feat: 接入起卦后端流程并完善积分扣减链路
This commit is contained in:
+32
-1
@@ -9,6 +9,7 @@ import '../features/auth/data/repositories/auth_repository.dart';
|
||||
import '../features/auth/presentation/bloc/auth_bloc.dart';
|
||||
import '../features/auth/presentation/bloc/auth_state.dart';
|
||||
import '../features/auth/presentation/screens/login_screen.dart';
|
||||
import '../features/divination/data/apis/divination_api.dart';
|
||||
import '../features/home/presentation/screens/home_screen.dart';
|
||||
import '../features/settings/data/models/profile_settings.dart';
|
||||
import '../l10n/app_localizations.dart';
|
||||
@@ -26,10 +27,14 @@ class EryaoApp extends StatefulWidget {
|
||||
class _EryaoAppState extends State<EryaoApp> {
|
||||
final SessionStore _sessionStore = SessionStore(LocalKvStore());
|
||||
late final AuthBloc _authBloc;
|
||||
late final DivinationApi _divinationApi;
|
||||
Locale _locale = const Locale('zh');
|
||||
ProfileSettingsV1 _profileSettings = ProfileSettingsV1.defaultsForLocale(
|
||||
const Locale('zh'),
|
||||
);
|
||||
int _creditsBalance = 0;
|
||||
bool _loadingCredits = false;
|
||||
String? _loadedCreditsUserEmail;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -42,6 +47,7 @@ class _EryaoAppState extends State<EryaoApp> {
|
||||
},
|
||||
);
|
||||
final authApi = AuthApi(apiClient: apiClient);
|
||||
_divinationApi = DivinationApi(apiClient: apiClient);
|
||||
final authRepository = AuthRepositoryImpl(
|
||||
authApi: authApi,
|
||||
sessionStore: _sessionStore,
|
||||
@@ -50,6 +56,30 @@ class _EryaoAppState extends State<EryaoApp> {
|
||||
_bootstrap();
|
||||
}
|
||||
|
||||
void _ensureCreditsLoaded(String userEmail) {
|
||||
if (_loadingCredits) {
|
||||
return;
|
||||
}
|
||||
if (_loadedCreditsUserEmail == userEmail) {
|
||||
return;
|
||||
}
|
||||
_loadingCredits = true;
|
||||
_divinationApi
|
||||
.getPointsBalance()
|
||||
.then((balance) {
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
_creditsBalance = balance.availableBalance;
|
||||
_loadedCreditsUserEmail = userEmail;
|
||||
});
|
||||
})
|
||||
.whenComplete(() {
|
||||
_loadingCredits = false;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_authBloc.dispose();
|
||||
@@ -118,12 +148,13 @@ class _EryaoAppState extends State<EryaoApp> {
|
||||
}
|
||||
|
||||
if (state.status == AuthStatus.authenticated && state.user != null) {
|
||||
_ensureCreditsLoaded(state.user!.email);
|
||||
return HomeScreen(
|
||||
account: state.user!.email,
|
||||
sessionStore: _sessionStore,
|
||||
currentLocale: _locale,
|
||||
profileSettings: _profileSettings,
|
||||
coinBalance: 100,
|
||||
coinBalance: _creditsBalance,
|
||||
onLocaleChanged: _handleInterfaceLanguageChanged,
|
||||
onLogout: _authBloc.logout,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user