fix(wallet): 丢弃切换账号后返回的旧余额响应
This commit is contained in:
1 parent
19196ceb8e
commit
501bc66282
2 files changed
+98
-5
No files matched your search
@@ -21,23 +21,29 @@ class WalletController extends ChangeNotifier {
|
||||
String? unlockError;
|
||||
String? unlockingEpisodeId;
|
||||
bool _disposed = false;
|
||||
int _requestSeq = 0;
|
||||
|
||||
int get balance => snapshot?.wallet.coinBalance ?? 0;
|
||||
List<CoinLedgerEntry> get ledger => snapshot?.ledger ?? const [];
|
||||
|
||||
Future<void> load() async {
|
||||
if (_disposed) return;
|
||||
final request = ++_requestSeq;
|
||||
loading = true;
|
||||
error = null;
|
||||
_notify();
|
||||
try {
|
||||
snapshot = await _repository.fetchWallet();
|
||||
final result = await _repository.fetchWallet();
|
||||
if (_isCurrent(request)) snapshot = result;
|
||||
} on ApiException catch (exception) {
|
||||
error = exception.message;
|
||||
if (_isCurrent(request)) error = exception.message;
|
||||
} catch (_) {
|
||||
error = 'walletLoadFailed';
|
||||
if (_isCurrent(request)) error = 'walletLoadFailed';
|
||||
} finally {
|
||||
loading = false;
|
||||
_notify();
|
||||
if (_isCurrent(request)) {
|
||||
loading = false;
|
||||
_notify();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,6 +81,7 @@ class WalletController extends ChangeNotifier {
|
||||
}
|
||||
|
||||
void reset() {
|
||||
_requestSeq += 1;
|
||||
snapshot = null;
|
||||
loading = false;
|
||||
unlocking = false;
|
||||
@@ -88,6 +95,8 @@ class WalletController extends ChangeNotifier {
|
||||
if (!_disposed) notifyListeners();
|
||||
}
|
||||
|
||||
bool _isCurrent(int request) => !_disposed && request == _requestSeq;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_disposed = true;
|
||||
|
||||
Reference in new issue
Block a user