mirror of
https://github.com/koloideal/Casha.git
synced 2026-06-10 10:25:28 +03:00
update
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user