mirror of
https://github.com/koloideal/Casha.git
synced 2026-06-10 10:25:28 +03:00
update
This commit is contained in:
@@ -139,6 +139,40 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
|||||||
.read(accountCardColorsProvider(editingAccount!.id).notifier)
|
.read(accountCardColorsProvider(editingAccount!.id).notifier)
|
||||||
.save(tempPrimary, tempSecondary, tempGradientType);
|
.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
|
// Update account name and currency
|
||||||
final updatedAccount = Account(
|
final updatedAccount = Account(
|
||||||
id: editingAccount!.id,
|
id: editingAccount!.id,
|
||||||
|
|||||||
@@ -45,15 +45,21 @@ class _AccountEditorOverlayState extends State<AccountEditorOverlay> {
|
|||||||
_originalCurrency = dash.tempAccountCurrency;
|
_originalCurrency = dash.tempAccountCurrency;
|
||||||
_nameController.addListener(() {
|
_nameController.addListener(() {
|
||||||
final text = _nameController.text;
|
final text = _nameController.text;
|
||||||
if (text.length > 17) {
|
|
||||||
_nameController.text = text.substring(0, 17);
|
// Check if empty or exceeds limit
|
||||||
_nameController.selection = TextSelection.fromPosition(
|
if (text.trim().isEmpty || text.length > 20) {
|
||||||
const TextPosition(offset: 17),
|
|
||||||
);
|
|
||||||
setState(() => _showLimitError = true);
|
setState(() => _showLimitError = true);
|
||||||
Future.delayed(const Duration(seconds: 2), () {
|
Future.delayed(const Duration(seconds: 2), () {
|
||||||
if (mounted) setState(() => _showLimitError = false);
|
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
|
return; // Skip updating dash to avoid out-of-bounds
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -858,10 +864,20 @@ class _AccountEditorOverlayState extends State<AccountEditorOverlay> {
|
|||||||
Expanded(
|
Expanded(
|
||||||
flex: 2,
|
flex: 2,
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
onPressed: () => dash.closeAccountOverlay(apply: true),
|
onPressed: _nameController.text.trim().isEmpty
|
||||||
|
? null
|
||||||
|
: () => dash.closeAccountOverlay(apply: true),
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
backgroundColor: const Color(0xFF7C6DED),
|
backgroundColor: const Color(0xFF7C6DED),
|
||||||
foregroundColor: Colors.white,
|
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),
|
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(12)),
|
borderRadius: BorderRadius.circular(12)),
|
||||||
|
|||||||
Reference in New Issue
Block a user