From c0657f88b9ba5de0b7a366818040a3fceb4ae773 Mon Sep 17 00:00:00 2001 From: hailin Date: Sun, 21 Dec 2025 21:31:02 -0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=88=91=E7=9A=84=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E8=BF=9B=E5=85=A5=E6=97=B6=E7=9B=B4=E6=8E=A5=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E9=92=B1=E5=8C=85=E7=8A=B6=E6=80=81=E5=B9=B6=E6=9B=B4=E6=96=B0?= =?UTF-8?q?UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 页面初始化时调用API检查钱包状态,不再只依赖60秒轮询 - 钱包就绪后刷新authProvider和触发UI重建 - 确保与监控页面状态同步 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../presentation/pages/profile_page.dart | 49 ++++++++++++++++--- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/frontend/mobile-app/lib/features/profile/presentation/pages/profile_page.dart b/frontend/mobile-app/lib/features/profile/presentation/pages/profile_page.dart index 566f56ae..31e73a8f 100644 --- a/frontend/mobile-app/lib/features/profile/presentation/pages/profile_page.dart +++ b/frontend/mobile-app/lib/features/profile/presentation/pages/profile_page.dart @@ -187,16 +187,15 @@ class _ProfilePageState extends ConsumerState { super.initState(); // 首屏数据:用户基本信息(从本地存储优先) _checkLocalAvatarSync(); - _loadUserData(); + _loadUserData().then((_) { + // 用户数据加载完成后,检查钱包状态 + _checkAndStartWalletPolling(); + }); _loadAppInfo(); // 通知数量(轻量级请求) _loadUnreadNotificationCount(); // 启动定时刷新(可见区域的数据) _startAutoRefreshTimer(); - // 检查钱包状态并启动轮询(如果需要) - WidgetsBinding.instance.addPostFrameCallback((_) { - _checkAndStartWalletPolling(); - }); } /// 加载应用信息 @@ -796,9 +795,43 @@ class _ProfilePageState extends ConsumerState { Future _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(); } }