From 7e1f9e952b03ffbede4a14f011ec9cc73509607e Mon Sep 17 00:00:00 2001 From: hailin Date: Mon, 22 Dec 2025 02:08:15 -0800 Subject: [PATCH] =?UTF-8?q?fix(mobile-app):=20=E6=AD=A3=E7=A1=AE=E7=9A=84?= =?UTF-8?q?=E9=92=B1=E5=8C=85=E7=8A=B6=E6=80=81=E6=A3=80=E6=9F=A5=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 逻辑: 1. 先检查本地标志 isWalletReady 2. 如果已 ready,直接显示序列号 3. 如果不 ready,调用 API 检查钱包状态 4. API 返回 ready 后,设置本地标志并刷新 UI 5. API 返回未 ready,启动轮询直到成功 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../presentation/pages/profile_page.dart | 119 +++++++++--------- 1 file changed, 57 insertions(+), 62 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 c84f610d..46b8c3b5 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 @@ -793,23 +793,32 @@ class _ProfilePageState extends ConsumerState { } /// 检查并启动钱包轮询 + /// 逻辑: + /// 1. 先检查本地标志 isWalletReady,如果已 ready 则跳过 + /// 2. 如果不 ready,调用 API 检查钱包状态 + /// 3. API 返回 ready 后,设置本地标志并刷新 UI + /// 4. API 返回未 ready,启动轮询直到成功 Future _checkAndStartWalletPolling() async { final authState = ref.read(authProvider); debugPrint('[ProfilePage] _checkAndStartWalletPolling() called'); debugPrint('[ProfilePage] authState.isWalletReady: ${authState.isWalletReady}'); - debugPrint('[ProfilePage] authState.isAccountCreated: ${authState.isAccountCreated}'); debugPrint('[ProfilePage] _serialNumber: $_serialNumber'); - // 关键修改:只要有 serialNumber,就去 API 检查钱包状态 - // 不再依赖本地的 isAccountCreated 状态 + // 1. 先检查本地标志,如果已 ready 则不需要检查 API + if (authState.isWalletReady) { + debugPrint('[ProfilePage] Wallet already ready (local flag), skip API check'); + return; + } + + // 2. 没有序列号则跳过 if (_serialNumber.isEmpty || _serialNumber == '--') { debugPrint('[ProfilePage] Skip wallet check - no valid serialNumber'); return; } - // 调用 API 检查钱包状态 - debugPrint('[ProfilePage] Checking wallet status from API...'); + // 3. 调用 API 检查钱包状态 + debugPrint('[ProfilePage] isWalletReady=false, checking wallet status from API...'); try { final accountService = ref.read(accountServiceProvider); final walletInfo = await accountService.getWalletInfo(_serialNumber); @@ -817,7 +826,7 @@ class _ProfilePageState extends ConsumerState { debugPrint('[ProfilePage] Wallet status from API: isReady=${walletInfo.isReady}, isGenerating=${walletInfo.isGenerating}'); if (walletInfo.isReady) { - // 钱包已就绪,更新本地存储 + // 4. 钱包已就绪,更新本地存储 debugPrint('[ProfilePage] Wallet is ready, updating local storage'); final secureStorage = ref.read(secureStorageProvider); await secureStorage.write(key: StorageKeys.isWalletReady, value: 'true'); @@ -826,17 +835,17 @@ class _ProfilePageState extends ConsumerState { // 刷新 authProvider 状态 await ref.read(authProvider.notifier).checkAuthStatus(); - // 通知 walletStatusProvider 更新状态 + // 停止轮询 ref.read(walletStatusProvider.notifier).stopPolling(); - // 强制刷新UI + // 强制刷新UI显示序列号 if (mounted) { setState(() {}); } return; } - // 钱包未就绪,启动轮询 + // 5. 钱包未就绪,启动轮询直到成功 debugPrint('[ProfilePage] Wallet not ready, starting polling'); await ref.read(walletStatusProvider.notifier).startPolling(); } catch (e) { @@ -4070,74 +4079,60 @@ class _ProfilePageState extends ConsumerState { } /// 构建序列号或钱包生成状态显示 + /// 逻辑:先检查 isWalletReady 标志,如果 ready 就显示序列号 + /// 如果不 ready,_checkAndStartWalletPolling 会去 API 检查并轮询 Widget _buildSerialNumberOrStatus() { final walletStatus = ref.watch(walletStatusProvider); final authState = ref.watch(authProvider); - // 关键修改:只要有有效的序列号,就直接显示 - // 不再依赖本地的 isWalletReady/isAccountCreated 状态 - if (_serialNumber.isNotEmpty && _serialNumber != '--') { - return Row( - children: [ - Text( - '序列号: $_serialNumber', - style: const TextStyle( - fontSize: 14, - fontFamily: 'Inter', - height: 1.5, - color: Color(0xCC5D4037), + // 1. 钱包已就绪(本地标志 或 API状态),显示序列号 + if (authState.isWalletReady || walletStatus.isReady) { + if (_serialNumber.isNotEmpty && _serialNumber != '--') { + return Row( + children: [ + Text( + '序列号: $_serialNumber', + style: const TextStyle( + fontSize: 14, + fontFamily: 'Inter', + height: 1.5, + color: Color(0xCC5D4037), + ), ), - ), - const SizedBox(width: 8), - GestureDetector( - onTap: _copySerialNumber, - child: const Icon( - Icons.copy, - size: 16, - color: Color(0xCC5D4037), + const SizedBox(width: 8), + GestureDetector( + onTap: _copySerialNumber, + child: const Icon( + Icons.copy, + size: 16, + color: Color(0xCC5D4037), + ), ), - ), - ], - ); + ], + ); + } } - // 如果钱包正在生成中(walletStatus 从 API 获取的状态) - if (walletStatus.isGenerating) { - return Row( - children: [ - const SizedBox( - width: 12, - height: 12, - child: CircularProgressIndicator( - strokeWidth: 2, - valueColor: AlwaysStoppedAnimation(Color(0xFFD4AF37)), - ), - ), - const SizedBox(width: 8), - Text( - '钱包生成中...', - style: const TextStyle( - fontSize: 14, - fontFamily: 'Inter', - height: 1.5, - color: Color(0xFFD4AF37), - fontStyle: FontStyle.italic, - ), - ), - ], - ); - } - - // 默认情况:无序列号,显示"--" + // 2. 钱包未就绪,显示生成中状态 return Row( children: [ + const SizedBox( + width: 12, + height: 12, + child: CircularProgressIndicator( + strokeWidth: 2, + valueColor: AlwaysStoppedAnimation(Color(0xFFD4AF37)), + ), + ), + const SizedBox(width: 8), Text( - '序列号: --', + '钱包生成中...', style: const TextStyle( fontSize: 14, fontFamily: 'Inter', height: 1.5, - color: Color(0xCC5D4037), + color: Color(0xFFD4AF37), + fontStyle: FontStyle.italic, ), ), ],