This commit is contained in:
2026-03-24 15:24:59 +03:00
parent 5888e0d196
commit bb4580ec49
4 changed files with 51 additions and 56 deletions
+8 -35
View File
@@ -139,40 +139,6 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
.read(accountCardColorsProvider(editingAccount!.id).notifier)
.save(tempPrimary, tempSecondary, tempGradientType);
// Check if currency was changed and convert transactions
if (tempAccountCurrency != editingAccount!.currency) {
final exchangeService = ref.read(exchangeRateServiceProvider);
final txRepo = ref.read(transactionRepositoryProvider);
// Fetch all transactions
final allTxsResult = await txRepo.getAll();
if (allTxsResult.isSuccess) {
final accountTxs = allTxsResult.dataOrNull!
.where((t) => t.accountId == editingAccount!.id)
.toList();
// Convert and update each transaction
for (final tx in accountTxs) {
final convertedAmount = exchangeService.convert(
tx.amount,
editingAccount!.currency, // old currency
tempAccountCurrency, // new currency
);
final updatedTx = tx.copyWith(
amount: convertedAmount,
currency: currencyMap[tempAccountCurrency]?.symbol ?? '\$',
currencyCode: tempAccountCurrency,
);
await txRepo.update(updatedTx);
}
// Refresh transactions provider so the UI updates
ref.read(transactionsProvider.notifier).refresh();
}
}
// Update account name and currency
final updatedAccount = Account(
id: editingAccount!.id,
@@ -242,7 +208,14 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
final monthExpense = ref.watch(currentMonthExpenseProvider);
final budget = ref.watch(budgetProvider);
final recent = ref.watch(recentTransactionsProvider);
final currencyInfo = ref.watch(currencyProvider);
final activeAccount = ref.watch(activeAccountProvider);
final globalCurrencyInfo = ref.watch(currencyProvider);
final currencyInfo = activeAccount != null
? CurrencyInfo(
currencyMap[activeAccount.currency]?.symbol ?? '\$',
activeAccount.currency,
)
: globalCurrencyInfo;
return Scaffold(
backgroundColor: Theme.of(context).scaffoldBackgroundColor,