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:
parent
fefaeb29d6
commit
7e1f9e952b
|
|
@ -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,
|
||||
),
|
||||
),
|
||||
],
|
||||
|
|
|
|||
Loading…
Reference in New Issue