fix(mobile-app): 不依赖本地状态,直接显示序列号
问题:用户有序列号但 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 <noreply@anthropic.com>
This commit is contained in:
parent
8fa975a19e
commit
fefaeb29d6
|
|
@ -801,47 +801,48 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
|
|||
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<ProfilePage> {
|
|||
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<ProfilePage> {
|
|||
);
|
||||
}
|
||||
|
||||
// 如果钱包正在生成中,显示"账号创建审核中"
|
||||
if (authState.isAccountCreated && !authState.isWalletReady) {
|
||||
// 如果钱包正在生成中(walletStatus 从 API 获取的状态)
|
||||
if (walletStatus.isGenerating) {
|
||||
return Row(
|
||||
children: [
|
||||
const SizedBox(
|
||||
|
|
@ -4113,7 +4115,7 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
|
|||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'账号创建审核中',
|
||||
'钱包生成中...',
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontFamily: 'Inter',
|
||||
|
|
@ -4126,26 +4128,16 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
|
|||
);
|
||||
}
|
||||
|
||||
// 默认情况(unknown/generating状态)显示"创建账号审核中..."
|
||||
// 默认情况:无序列号,显示"--"
|
||||
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,
|
||||
color: Color(0xCC5D4037),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
|
|
|||
Loading…
Reference in New Issue