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 {
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<ProfilePage> {
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<ProfilePage> {
// 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<ProfilePage> {
}
///
/// 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>(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>(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,
),
),
],