fix(mobile-app): 正确的钱包状态检查逻辑

逻辑:
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 <noreply@anthropic.com>
This commit is contained in:
hailin 2025-12-22 02:08:15 -08:00
parent fefaeb29d6
commit 7e1f9e952b
1 changed files with 57 additions and 62 deletions

View File

@ -793,23 +793,32 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
} }
/// ///
///
/// 1. isWalletReady ready
/// 2. ready API
/// 3. API ready UI
/// 4. API ready
Future<void> _checkAndStartWalletPolling() async { Future<void> _checkAndStartWalletPolling() async {
final authState = ref.read(authProvider); final authState = ref.read(authProvider);
debugPrint('[ProfilePage] _checkAndStartWalletPolling() called'); debugPrint('[ProfilePage] _checkAndStartWalletPolling() called');
debugPrint('[ProfilePage] authState.isWalletReady: ${authState.isWalletReady}'); debugPrint('[ProfilePage] authState.isWalletReady: ${authState.isWalletReady}');
debugPrint('[ProfilePage] authState.isAccountCreated: ${authState.isAccountCreated}');
debugPrint('[ProfilePage] _serialNumber: $_serialNumber'); debugPrint('[ProfilePage] _serialNumber: $_serialNumber');
// serialNumber API // 1. ready API
// isAccountCreated if (authState.isWalletReady) {
debugPrint('[ProfilePage] Wallet already ready (local flag), skip API check');
return;
}
// 2.
if (_serialNumber.isEmpty || _serialNumber == '--') { if (_serialNumber.isEmpty || _serialNumber == '--') {
debugPrint('[ProfilePage] Skip wallet check - no valid serialNumber'); debugPrint('[ProfilePage] Skip wallet check - no valid serialNumber');
return; return;
} }
// API // 3. API
debugPrint('[ProfilePage] Checking wallet status from API...'); debugPrint('[ProfilePage] isWalletReady=false, checking wallet status from API...');
try { try {
final accountService = ref.read(accountServiceProvider); final accountService = ref.read(accountServiceProvider);
final walletInfo = await accountService.getWalletInfo(_serialNumber); final walletInfo = await accountService.getWalletInfo(_serialNumber);
@ -817,7 +826,7 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
debugPrint('[ProfilePage] Wallet status from API: isReady=${walletInfo.isReady}, isGenerating=${walletInfo.isGenerating}'); debugPrint('[ProfilePage] Wallet status from API: isReady=${walletInfo.isReady}, isGenerating=${walletInfo.isGenerating}');
if (walletInfo.isReady) { if (walletInfo.isReady) {
// // 4.
debugPrint('[ProfilePage] Wallet is ready, updating local storage'); debugPrint('[ProfilePage] Wallet is ready, updating local storage');
final secureStorage = ref.read(secureStorageProvider); final secureStorage = ref.read(secureStorageProvider);
await secureStorage.write(key: StorageKeys.isWalletReady, value: 'true'); await secureStorage.write(key: StorageKeys.isWalletReady, value: 'true');
@ -826,17 +835,17 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
// authProvider // authProvider
await ref.read(authProvider.notifier).checkAuthStatus(); await ref.read(authProvider.notifier).checkAuthStatus();
// walletStatusProvider //
ref.read(walletStatusProvider.notifier).stopPolling(); ref.read(walletStatusProvider.notifier).stopPolling();
// UI // UI显示序列号
if (mounted) { if (mounted) {
setState(() {}); setState(() {});
} }
return; return;
} }
// // 5.
debugPrint('[ProfilePage] Wallet not ready, starting polling'); debugPrint('[ProfilePage] Wallet not ready, starting polling');
await ref.read(walletStatusProvider.notifier).startPolling(); await ref.read(walletStatusProvider.notifier).startPolling();
} catch (e) { } catch (e) {
@ -4070,74 +4079,60 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
} }
/// ///
/// isWalletReady ready
/// ready_checkAndStartWalletPolling API
Widget _buildSerialNumberOrStatus() { Widget _buildSerialNumberOrStatus() {
final walletStatus = ref.watch(walletStatusProvider); final walletStatus = ref.watch(walletStatusProvider);
final authState = ref.watch(authProvider); final authState = ref.watch(authProvider);
// // 1. API状态
// isWalletReady/isAccountCreated if (authState.isWalletReady || walletStatus.isReady) {
if (_serialNumber.isNotEmpty && _serialNumber != '--') { if (_serialNumber.isNotEmpty && _serialNumber != '--') {
return Row( return Row(
children: [ children: [
Text( Text(
'序列号: $_serialNumber', '序列号: $_serialNumber',
style: const TextStyle( style: const TextStyle(
fontSize: 14, fontSize: 14,
fontFamily: 'Inter', fontFamily: 'Inter',
height: 1.5, height: 1.5,
color: Color(0xCC5D4037), color: Color(0xCC5D4037),
),
), ),
), const SizedBox(width: 8),
const SizedBox(width: 8), GestureDetector(
GestureDetector( onTap: _copySerialNumber,
onTap: _copySerialNumber, child: const Icon(
child: const Icon( Icons.copy,
Icons.copy, size: 16,
size: 16, color: Color(0xCC5D4037),
color: Color(0xCC5D4037), ),
), ),
), ],
], );
); }
} }
// walletStatus API // 2.
if (walletStatus.isGenerating) {
return Row(
children: [
const SizedBox(
width: 12,
height: 12,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation<Color>(Color(0xFFD4AF37)),
),
),
const SizedBox(width: 8),
Text(
'钱包生成中...',
style: const TextStyle(
fontSize: 14,
fontFamily: 'Inter',
height: 1.5,
color: Color(0xFFD4AF37),
fontStyle: FontStyle.italic,
),
),
],
);
}
// "--"
return Row( return Row(
children: [ children: [
const SizedBox(
width: 12,
height: 12,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation<Color>(Color(0xFFD4AF37)),
),
),
const SizedBox(width: 8),
Text( Text(
'序列号: --', '钱包生成中...',
style: const TextStyle( style: const TextStyle(
fontSize: 14, fontSize: 14,
fontFamily: 'Inter', fontFamily: 'Inter',
height: 1.5, height: 1.5,
color: Color(0xCC5D4037), color: Color(0xFFD4AF37),
fontStyle: FontStyle.italic,
), ),
), ),
], ],