From fefaeb29d6c41443743d055b16f1ed7c883669e8 Mon Sep 17 00:00:00 2001 From: hailin Date: Mon, 22 Dec 2025 02:05:27 -0800 Subject: [PATCH] =?UTF-8?q?fix(mobile-app):=20=E4=B8=8D=E4=BE=9D=E8=B5=96?= =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E7=8A=B6=E6=80=81=EF=BC=8C=E7=9B=B4=E6=8E=A5?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=BA=8F=E5=88=97=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题:用户有序列号但 isAccountCreated 为 false 时显示"审核中" 修复: 1. _buildSerialNumberOrStatus(): 只要有有效序列号就直接显示 2. _checkAndStartWalletPolling(): 只要有序列号就调用 API 检查钱包状态 3. 不再依赖本地的 isAccountCreated/isWalletReady 状态 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../presentation/pages/profile_page.dart | 84 +++++++++---------- 1 file changed, 38 insertions(+), 46 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 a7bcd72a..c84f610d 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 @@ -801,47 +801,48 @@ class _ProfilePageState extends ConsumerState { debugPrint('[ProfilePage] authState.isAccountCreated: ${authState.isAccountCreated}'); debugPrint('[ProfilePage] _serialNumber: $_serialNumber'); - // 如果本地已标记钱包就绪,无需检查 - if (authState.isWalletReady) { - debugPrint('[ProfilePage] Wallet already ready (local), skip polling'); + // 关键修改:只要有 serialNumber,就去 API 检查钱包状态 + // 不再依赖本地的 isAccountCreated 状态 + if (_serialNumber.isEmpty || _serialNumber == '--') { + debugPrint('[ProfilePage] Skip wallet check - no valid serialNumber'); 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); + // 调用 API 检查钱包状态 + 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'); + debugPrint('[ProfilePage] Wallet status from API: isReady=${walletInfo.isReady}, isGenerating=${walletInfo.isGenerating}'); - // 刷新 authProvider 状态 - await ref.read(authProvider.notifier).checkAuthStatus(); + if (walletInfo.isReady) { + // 钱包已就绪,更新本地存储 + debugPrint('[ProfilePage] Wallet is ready, updating local storage'); + final secureStorage = ref.read(secureStorageProvider); + await secureStorage.write(key: StorageKeys.isWalletReady, value: 'true'); + await secureStorage.write(key: StorageKeys.isAccountCreated, value: 'true'); - // 通知 walletStatusProvider 更新状态 - ref.read(walletStatusProvider.notifier).stopPolling(); + // 刷新 authProvider 状态 + await ref.read(authProvider.notifier).checkAuthStatus(); - // 强制刷新UI - if (mounted) { - setState(() {}); - } - return; + // 通知 walletStatusProvider 更新状态 + ref.read(walletStatusProvider.notifier).stopPolling(); + + // 强制刷新UI + if (mounted) { + setState(() {}); } - } catch (e) { - debugPrint('[ProfilePage] Failed to check wallet status: $e'); + return; } // 钱包未就绪,启动轮询 debugPrint('[ProfilePage] Wallet not ready, starting polling'); await ref.read(walletStatusProvider.notifier).startPolling(); - } else { - debugPrint('[ProfilePage] Skip wallet check - conditions not met'); - debugPrint('[ProfilePage] isAccountCreated=${authState.isAccountCreated}, serialNumber=$_serialNumber'); + } catch (e) { + debugPrint('[ProfilePage] Failed to check wallet status: $e'); + // API 调用失败时,也尝试启动轮询 + await ref.read(walletStatusProvider.notifier).startPolling(); } } @@ -4073,8 +4074,9 @@ class _ProfilePageState extends ConsumerState { final walletStatus = ref.watch(walletStatusProvider); final authState = ref.watch(authProvider); - // 如果钱包已就绪或账号已创建且钱包也就绪,显示序列号 - if (authState.isWalletReady || walletStatus.isReady) { + // 关键修改:只要有有效的序列号,就直接显示 + // 不再依赖本地的 isWalletReady/isAccountCreated 状态 + if (_serialNumber.isNotEmpty && _serialNumber != '--') { return Row( children: [ Text( @@ -4099,8 +4101,8 @@ class _ProfilePageState extends ConsumerState { ); } - // 如果钱包正在生成中,显示"账号创建审核中" - if (authState.isAccountCreated && !authState.isWalletReady) { + // 如果钱包正在生成中(walletStatus 从 API 获取的状态) + if (walletStatus.isGenerating) { return Row( children: [ const SizedBox( @@ -4113,7 +4115,7 @@ class _ProfilePageState extends ConsumerState { ), const SizedBox(width: 8), Text( - '账号创建审核中', + '钱包生成中...', style: const TextStyle( fontSize: 14, fontFamily: 'Inter', @@ -4126,26 +4128,16 @@ class _ProfilePageState extends ConsumerState { ); } - // 默认情况(unknown/generating状态)显示"创建账号审核中..." + // 默认情况:无序列号,显示"--" 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, + color: Color(0xCC5D4037), ), ), ],