From 5888e0d196e1578871ccf2eeba81ac9643674cf5 Mon Sep 17 00:00:00 2001 From: kolo Date: Tue, 24 Mar 2026 12:10:19 +0300 Subject: [PATCH] update --- lib/features/dashboard/screen.dart | 34 +++++++++++++++++++ .../widgets/account_editor_overlay.dart | 28 +++++++++++---- 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/lib/features/dashboard/screen.dart b/lib/features/dashboard/screen.dart index ac94c8f..542746c 100644 --- a/lib/features/dashboard/screen.dart +++ b/lib/features/dashboard/screen.dart @@ -139,6 +139,40 @@ class _DashboardScreenState extends ConsumerState { .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, diff --git a/lib/features/dashboard/widgets/account_editor_overlay.dart b/lib/features/dashboard/widgets/account_editor_overlay.dart index bd80822..f8c9312 100644 --- a/lib/features/dashboard/widgets/account_editor_overlay.dart +++ b/lib/features/dashboard/widgets/account_editor_overlay.dart @@ -45,15 +45,21 @@ class _AccountEditorOverlayState extends State { _originalCurrency = dash.tempAccountCurrency; _nameController.addListener(() { final text = _nameController.text; - if (text.length > 17) { - _nameController.text = text.substring(0, 17); - _nameController.selection = TextSelection.fromPosition( - const TextPosition(offset: 17), - ); + + // Check if empty or exceeds limit + if (text.trim().isEmpty || text.length > 20) { setState(() => _showLimitError = true); Future.delayed(const Duration(seconds: 2), () { if (mounted) setState(() => _showLimitError = false); }); + } + + // Truncate if exceeds 20 characters + if (text.length > 20) { + _nameController.text = text.substring(0, 20); + _nameController.selection = TextSelection.fromPosition( + const TextPosition(offset: 20), + ); return; // Skip updating dash to avoid out-of-bounds } @@ -858,10 +864,20 @@ class _AccountEditorOverlayState extends State { Expanded( flex: 2, child: ElevatedButton( - onPressed: () => dash.closeAccountOverlay(apply: true), + onPressed: _nameController.text.trim().isEmpty + ? null + : () => dash.closeAccountOverlay(apply: true), style: ElevatedButton.styleFrom( backgroundColor: const Color(0xFF7C6DED), foregroundColor: Colors.white, + disabledBackgroundColor: Theme.of(widget.context) + .colorScheme + .onSurface + .withOpacity(0.12), + disabledForegroundColor: Theme.of(widget.context) + .colorScheme + .onSurface + .withOpacity(0.38), padding: const EdgeInsets.symmetric(vertical: 10), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(12)),