mirror of
https://github.com/koloideal/Casha.git
synced 2026-06-10 02:15:29 +03:00
update
This commit is contained in:
@@ -139,6 +139,40 @@ 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,
|
||||
|
||||
@@ -45,15 +45,21 @@ class _AccountEditorOverlayState extends State<AccountEditorOverlay> {
|
||||
_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<AccountEditorOverlay> {
|
||||
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)),
|
||||
|
||||
Reference in New Issue
Block a user