fix: 我的页面进入时直接检查钱包状态并更新UI

- 页面初始化时调用API检查钱包状态,不再只依赖60秒轮询
- 钱包就绪后刷新authProvider和触发UI重建
- 确保与监控页面状态同步

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2025-12-21 21:31:02 -08:00
parent 0047767c47
commit c0657f88b9
1 changed files with 41 additions and 8 deletions

View File

@ -187,16 +187,15 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
super.initState();
//
_checkLocalAvatarSync();
_loadUserData();
_loadUserData().then((_) {
//
_checkAndStartWalletPolling();
});
_loadAppInfo();
//
_loadUnreadNotificationCount();
//
_startAutoRefreshTimer();
//
WidgetsBinding.instance.addPostFrameCallback((_) {
_checkAndStartWalletPolling();
});
}
///
@ -796,9 +795,43 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
Future<void> _checkAndStartWalletPolling() async {
final authState = ref.read(authProvider);
//
if (authState.isAccountCreated && !authState.isWalletReady) {
debugPrint('[ProfilePage] Account created but wallet not ready, starting polling');
//
if (authState.isWalletReady) {
debugPrint('[ProfilePage] Wallet already ready (local), skip polling');
return;
}
// API
if (authState.isAccountCreated && _serialNumber.isNotEmpty && _serialNumber != '--') {
debugPrint('[ProfilePage] Checking wallet status from API...');
try {
final accountService = ref.read(accountServiceProvider);
final walletInfo = await accountService.getWalletInfo(_serialNumber);
if (walletInfo.isReady) {
//
debugPrint('[ProfilePage] Wallet is ready, updating local storage');
final secureStorage = ref.read(secureStorageProvider);
await secureStorage.write(key: StorageKeys.isWalletReady, value: 'true');
// authProvider
await ref.read(authProvider.notifier).checkAuthStatus();
// walletStatusProvider
ref.read(walletStatusProvider.notifier).stopPolling();
// UI
if (mounted) {
setState(() {});
}
return;
}
} catch (e) {
debugPrint('[ProfilePage] Failed to check wallet status: $e');
}
//
debugPrint('[ProfilePage] Wallet not ready, starting polling');
await ref.read(walletStatusProvider.notifier).startPolling();
}
}