fix: 我的页面进入时直接检查钱包状态并更新UI
- 页面初始化时调用API检查钱包状态,不再只依赖60秒轮询 - 钱包就绪后刷新authProvider和触发UI重建 - 确保与监控页面状态同步 🤖 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
0047767c47
commit
c0657f88b9
|
|
@ -187,16 +187,15 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
|
|||
super.initState();
|
||||
// 首屏数据:用户基本信息(从本地存储优先)
|
||||
_checkLocalAvatarSync();
|
||||
_loadUserData();
|
||||
_loadUserData().then((_) {
|
||||
// 用户数据加载完成后,检查钱包状态
|
||||
_checkAndStartWalletPolling();
|
||||
});
|
||||
_loadAppInfo();
|
||||
// 通知数量(轻量级请求)
|
||||
_loadUnreadNotificationCount();
|
||||
// 启动定时刷新(可见区域的数据)
|
||||
_startAutoRefreshTimer();
|
||||
// 检查钱包状态并启动轮询(如果需要)
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_checkAndStartWalletPolling();
|
||||
});
|
||||
}
|
||||
|
||||
/// 加载应用信息
|
||||
|
|
@ -796,9 +795,43 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
|
|||
Future<void> _checkAndStartWalletPolling() async {
|
||||
final authState = ref.read(authProvider);
|
||||
|
||||
// 如果账号已创建但钱包未就绪,启动轮询
|
||||
if (authState.isAccountCreated && !authState.isWalletReady) {
|
||||
debugPrint('[ProfilePage] Account created but wallet not ready, starting polling');
|
||||
// 如果本地已标记钱包就绪,无需检查
|
||||
if (authState.isWalletReady) {
|
||||
debugPrint('[ProfilePage] Wallet already ready (local), skip polling');
|
||||
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);
|
||||
|
||||
if (walletInfo.isReady) {
|
||||
// 钱包已就绪,更新本地存储
|
||||
debugPrint('[ProfilePage] Wallet is ready, updating local storage');
|
||||
final secureStorage = ref.read(secureStorageProvider);
|
||||
await secureStorage.write(key: StorageKeys.isWalletReady, value: 'true');
|
||||
|
||||
// 刷新 authProvider 状态
|
||||
await ref.read(authProvider.notifier).checkAuthStatus();
|
||||
|
||||
// 通知 walletStatusProvider 更新状态
|
||||
ref.read(walletStatusProvider.notifier).stopPolling();
|
||||
|
||||
// 强制刷新UI
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('[ProfilePage] Failed to check wallet status: $e');
|
||||
}
|
||||
|
||||
// 钱包未就绪,启动轮询
|
||||
debugPrint('[ProfilePage] Wallet not ready, starting polling');
|
||||
await ref.read(walletStatusProvider.notifier).startPolling();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue