usability fixes
This commit is contained in:
@@ -17,6 +17,9 @@ class AccountProvider extends ChangeNotifier {
|
||||
String? _accountError;
|
||||
String? _statementError;
|
||||
|
||||
/// Cached balances keyed by currency code (e.g. 'USD', 'ZWG').
|
||||
final Map<String, AccountModel?> _balances = {};
|
||||
|
||||
AccountModel? get account => _account;
|
||||
StatementModel? get statement => _statement;
|
||||
bool get isLoadingAccount => _isLoadingAccount;
|
||||
@@ -25,6 +28,20 @@ class AccountProvider extends ChangeNotifier {
|
||||
String? get statementError => _statementError;
|
||||
bool _isDisposed = false;
|
||||
|
||||
/// Returns a cached account balance for [currency], or null if not yet
|
||||
/// fetched.
|
||||
AccountModel? balanceForCurrency(String currency) {
|
||||
return _balances[currency.toUpperCase()];
|
||||
}
|
||||
|
||||
/// Returns the account with name 'City Wallet' for [currency], or null.
|
||||
AccountModel? cityWalletBalance() {
|
||||
return _balances.values.firstWhere(
|
||||
(a) => a?.name == 'City Wallet',
|
||||
orElse: () => null,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void notifyListeners() {
|
||||
if (!_isDisposed) {
|
||||
@@ -52,6 +69,7 @@ class AccountProvider extends ChangeNotifier {
|
||||
);
|
||||
|
||||
_account = AccountModel.fromJson(response);
|
||||
_balances[currency.toUpperCase()] = _account;
|
||||
_isLoadingAccount = false;
|
||||
notifyListeners();
|
||||
return ApiResponse.success(_account!);
|
||||
@@ -71,6 +89,17 @@ class AccountProvider extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
/// Pre-load multiple currency balances at once. Results are stored in the
|
||||
/// [_balances] map so any widget can access them later.
|
||||
Future<void> preloadBalances(
|
||||
String? workspaceId,
|
||||
List<String> currencies,
|
||||
) async {
|
||||
for (final currency in currencies) {
|
||||
await fetchAccount(workspaceId, currency);
|
||||
}
|
||||
}
|
||||
|
||||
Future<ApiResponse<StatementModel>> fetchStatement({
|
||||
required String workspaceId,
|
||||
required String currency,
|
||||
@@ -117,4 +146,4 @@ class AccountProvider extends ChangeNotifier {
|
||||
_statementError = null;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user