mirror of
https://github.com/koloideal/Casha.git
synced 2026-06-10 10:25:28 +03:00
update
This commit is contained in:
@@ -132,6 +132,21 @@ final accountFilteredTransactionsProvider = Provider<List<Transaction>>((ref) {
|
||||
return txs.where((t) => t.accountId == activeAccount.id).toList();
|
||||
});
|
||||
|
||||
final globalTotalBalanceProvider = Provider<double>((ref) {
|
||||
final txs = ref.watch(transactionsProvider).valueOrNull ?? [];
|
||||
final exchangeService = ref.watch(exchangeRateServiceProvider);
|
||||
final targetCurrency = ref.watch(currencyProvider).code;
|
||||
|
||||
return txs.fold(0.0, (sum, t) {
|
||||
final converted = exchangeService.convert(
|
||||
t.amount,
|
||||
t.currencyCode,
|
||||
targetCurrency,
|
||||
);
|
||||
return t.type == TransactionType.income ? sum + converted : sum - converted;
|
||||
});
|
||||
});
|
||||
|
||||
final totalBalanceProvider = Provider<double>((ref) {
|
||||
final txs = ref.watch(accountFilteredTransactionsProvider);
|
||||
|
||||
@@ -181,7 +196,8 @@ final totalIncomeProvider = Provider<double>((ref) {
|
||||
final exchangeService = ref.watch(exchangeRateServiceProvider);
|
||||
|
||||
return filtered.fold(0.0, (sum, t) {
|
||||
return sum + exchangeService.convert(t.amount, t.currencyCode, targetCurrency);
|
||||
return sum +
|
||||
exchangeService.convert(t.amount, t.currencyCode, targetCurrency);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -204,7 +220,8 @@ final totalExpenseProvider = Provider<double>((ref) {
|
||||
final exchangeService = ref.watch(exchangeRateServiceProvider);
|
||||
|
||||
return filtered.fold(0.0, (sum, t) {
|
||||
return sum + exchangeService.convert(t.amount, t.currencyCode, targetCurrency);
|
||||
return sum +
|
||||
exchangeService.convert(t.amount, t.currencyCode, targetCurrency);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -233,7 +250,8 @@ final currentMonthExpenseProvider = Provider<double>((ref) {
|
||||
final exchangeService = ref.watch(exchangeRateServiceProvider);
|
||||
|
||||
return filtered.fold(0.0, (sum, t) {
|
||||
return sum + exchangeService.convert(t.amount, t.currencyCode, targetCurrency);
|
||||
return sum +
|
||||
exchangeService.convert(t.amount, t.currencyCode, targetCurrency);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -330,7 +348,10 @@ final cardColorsProvider =
|
||||
|
||||
// Account-specific color provider
|
||||
final accountCardColorsProvider =
|
||||
StateNotifierProvider.family<CardColorsNotifier, CardColors, int>((ref, accountId) {
|
||||
StateNotifierProvider.family<CardColorsNotifier, CardColors, int>((
|
||||
ref,
|
||||
accountId,
|
||||
) {
|
||||
final notifier = CardColorsNotifier(accountId: accountId);
|
||||
notifier.setupThemeListener(ref);
|
||||
return notifier;
|
||||
@@ -369,7 +390,12 @@ class CardColorsNotifier extends StateNotifier<CardColors> {
|
||||
GradientType gradient,
|
||||
) async {
|
||||
state = CardColors(primary, secondary, gradient);
|
||||
await CardColorService.save(primary, secondary, gradient, accountId: accountId);
|
||||
await CardColorService.save(
|
||||
primary,
|
||||
secondary,
|
||||
gradient,
|
||||
accountId: accountId,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> reset(bool isDark) async {
|
||||
|
||||
@@ -87,9 +87,13 @@ class _BalanceCardCarouselState extends ConsumerState<BalanceCardCarousel> {
|
||||
Widget cardWidget;
|
||||
|
||||
if (index == 0) {
|
||||
final totalBalance = ref.watch(
|
||||
globalTotalBalanceProvider,
|
||||
);
|
||||
final globalCurrency = ref.watch(currencyProvider);
|
||||
cardWidget = BalanceCard(
|
||||
balance: widget.balance,
|
||||
currencyInfo: widget.currencyInfo,
|
||||
balance: totalBalance,
|
||||
currencyInfo: globalCurrency,
|
||||
onLongPress: widget.onLongPress,
|
||||
previewPrimary: widget.previewPrimary,
|
||||
previewSecondary: widget.previewSecondary,
|
||||
|
||||
Reference in New Issue
Block a user