Refresh button for balance
This commit is contained in:
@@ -29,6 +29,8 @@ class WalletsProvider with ChangeNotifier {
|
||||
|
||||
bool _isRefreshingBalances = false;
|
||||
bool get isRefreshingBalances => _isRefreshingBalances;
|
||||
final Set<String> _refreshingWallets = <String>{};
|
||||
bool isWalletRefreshing(String walletId) => _refreshingWallets.contains(walletId);
|
||||
|
||||
void update(OrganizationsProvider organizations) {
|
||||
_organizations = organizations;
|
||||
@@ -81,6 +83,31 @@ class WalletsProvider with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> refreshBalance(String walletId) async {
|
||||
if (_refreshingWallets.contains(walletId)) return;
|
||||
final wallet = wallets.firstWhereOrNull((w) => w.id == walletId);
|
||||
if (wallet == null) return;
|
||||
|
||||
_refreshingWallets.add(walletId);
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
final balance = await _service.getBalance(_organizations.current.id, walletId);
|
||||
final updatedWallet = wallet.copyWith(balance: balance);
|
||||
final next = List<Wallet>.from(wallets);
|
||||
final idx = next.indexWhere((w) => w.id == walletId);
|
||||
if (idx >= 0) {
|
||||
next[idx] = updatedWallet;
|
||||
_setResource(_resource.copyWith(data: next));
|
||||
}
|
||||
} catch (e) {
|
||||
_setResource(_resource.copyWith(error: toException(e)));
|
||||
} finally {
|
||||
_refreshingWallets.remove(walletId);
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
void toggleVisibility(String walletId) {
|
||||
final index = wallets.indexWhere((w) => w.id == walletId);
|
||||
if (index < 0) return;
|
||||
|
||||
Reference in New Issue
Block a user