mirror of
https://github.com/koloideal/Casha.git
synced 2026-06-10 10:25:28 +03:00
update
This commit is contained in:
@@ -122,23 +122,38 @@ final accountFilteredTransactionsProvider = Provider<List<Transaction>>((ref) {
|
|||||||
final txsAsync = ref.watch(transactionsProvider);
|
final txsAsync = ref.watch(transactionsProvider);
|
||||||
final txs = txsAsync.valueOrNull ?? [];
|
final txs = txsAsync.valueOrNull ?? [];
|
||||||
final activeAccount = ref.watch(activeAccountProvider);
|
final activeAccount = ref.watch(activeAccountProvider);
|
||||||
|
|
||||||
// If activeAccount is null (Total Balance page), return all transactions
|
// If activeAccount is null (Total Balance page), return all transactions
|
||||||
if (activeAccount == null) {
|
if (activeAccount == null) {
|
||||||
return txs;
|
return txs;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter by account ID
|
// Filter by account ID
|
||||||
return txs.where((t) => t.accountId == activeAccount.id).toList();
|
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 totalBalanceProvider = Provider<double>((ref) {
|
||||||
final txs = ref.watch(accountFilteredTransactionsProvider);
|
final txs = ref.watch(accountFilteredTransactionsProvider);
|
||||||
|
|
||||||
final index = ref.watch(activeAccountIndexProvider);
|
final index = ref.watch(activeAccountIndexProvider);
|
||||||
final accountsAsync = ref.watch(accountsProvider);
|
final accountsAsync = ref.watch(accountsProvider);
|
||||||
final globalCurrency = ref.watch(currencyProvider).code;
|
final globalCurrency = ref.watch(currencyProvider).code;
|
||||||
|
|
||||||
String targetCurrency = globalCurrency;
|
String targetCurrency = globalCurrency;
|
||||||
if (index > 0) {
|
if (index > 0) {
|
||||||
final accounts = accountsAsync.valueOrNull ?? [];
|
final accounts = accountsAsync.valueOrNull ?? [];
|
||||||
@@ -146,7 +161,7 @@ final totalBalanceProvider = Provider<double>((ref) {
|
|||||||
targetCurrency = accounts[index - 1].currency;
|
targetCurrency = accounts[index - 1].currency;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final exchangeService = ref.watch(exchangeRateServiceProvider);
|
final exchangeService = ref.watch(exchangeRateServiceProvider);
|
||||||
|
|
||||||
return txs.fold(0.0, (sum, t) {
|
return txs.fold(0.0, (sum, t) {
|
||||||
@@ -163,12 +178,12 @@ final totalIncomeProvider = Provider<double>((ref) {
|
|||||||
// Watch the filtered transactions directly
|
// Watch the filtered transactions directly
|
||||||
final txs = ref.watch(accountFilteredTransactionsProvider);
|
final txs = ref.watch(accountFilteredTransactionsProvider);
|
||||||
final filtered = txs.where((t) => t.type == TransactionType.income);
|
final filtered = txs.where((t) => t.type == TransactionType.income);
|
||||||
|
|
||||||
// Watch the dependencies that change on swipe!
|
// Watch the dependencies that change on swipe!
|
||||||
final index = ref.watch(activeAccountIndexProvider);
|
final index = ref.watch(activeAccountIndexProvider);
|
||||||
final accountsAsync = ref.watch(accountsProvider);
|
final accountsAsync = ref.watch(accountsProvider);
|
||||||
final globalCurrency = ref.watch(currencyProvider).code;
|
final globalCurrency = ref.watch(currencyProvider).code;
|
||||||
|
|
||||||
// Resolve target currency synchronously based on the current swipe index
|
// Resolve target currency synchronously based on the current swipe index
|
||||||
String targetCurrency = globalCurrency;
|
String targetCurrency = globalCurrency;
|
||||||
if (index > 0) {
|
if (index > 0) {
|
||||||
@@ -177,22 +192,23 @@ final totalIncomeProvider = Provider<double>((ref) {
|
|||||||
targetCurrency = accounts[index - 1].currency;
|
targetCurrency = accounts[index - 1].currency;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final exchangeService = ref.watch(exchangeRateServiceProvider);
|
final exchangeService = ref.watch(exchangeRateServiceProvider);
|
||||||
|
|
||||||
return filtered.fold(0.0, (sum, t) {
|
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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
final totalExpenseProvider = Provider<double>((ref) {
|
final totalExpenseProvider = Provider<double>((ref) {
|
||||||
final txs = ref.watch(accountFilteredTransactionsProvider);
|
final txs = ref.watch(accountFilteredTransactionsProvider);
|
||||||
final filtered = txs.where((t) => t.type == TransactionType.expense);
|
final filtered = txs.where((t) => t.type == TransactionType.expense);
|
||||||
|
|
||||||
final index = ref.watch(activeAccountIndexProvider);
|
final index = ref.watch(activeAccountIndexProvider);
|
||||||
final accountsAsync = ref.watch(accountsProvider);
|
final accountsAsync = ref.watch(accountsProvider);
|
||||||
final globalCurrency = ref.watch(currencyProvider).code;
|
final globalCurrency = ref.watch(currencyProvider).code;
|
||||||
|
|
||||||
String targetCurrency = globalCurrency;
|
String targetCurrency = globalCurrency;
|
||||||
if (index > 0) {
|
if (index > 0) {
|
||||||
final accounts = accountsAsync.valueOrNull ?? [];
|
final accounts = accountsAsync.valueOrNull ?? [];
|
||||||
@@ -200,11 +216,12 @@ final totalExpenseProvider = Provider<double>((ref) {
|
|||||||
targetCurrency = accounts[index - 1].currency;
|
targetCurrency = accounts[index - 1].currency;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final exchangeService = ref.watch(exchangeRateServiceProvider);
|
final exchangeService = ref.watch(exchangeRateServiceProvider);
|
||||||
|
|
||||||
return filtered.fold(0.0, (sum, t) {
|
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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -217,11 +234,11 @@ final currentMonthExpenseProvider = Provider<double>((ref) {
|
|||||||
t.date.year == now.year &&
|
t.date.year == now.year &&
|
||||||
t.date.month == now.month,
|
t.date.month == now.month,
|
||||||
);
|
);
|
||||||
|
|
||||||
final index = ref.watch(activeAccountIndexProvider);
|
final index = ref.watch(activeAccountIndexProvider);
|
||||||
final accountsAsync = ref.watch(accountsProvider);
|
final accountsAsync = ref.watch(accountsProvider);
|
||||||
final globalCurrency = ref.watch(currencyProvider).code;
|
final globalCurrency = ref.watch(currencyProvider).code;
|
||||||
|
|
||||||
String targetCurrency = globalCurrency;
|
String targetCurrency = globalCurrency;
|
||||||
if (index > 0) {
|
if (index > 0) {
|
||||||
final accounts = accountsAsync.valueOrNull ?? [];
|
final accounts = accountsAsync.valueOrNull ?? [];
|
||||||
@@ -229,11 +246,12 @@ final currentMonthExpenseProvider = Provider<double>((ref) {
|
|||||||
targetCurrency = accounts[index - 1].currency;
|
targetCurrency = accounts[index - 1].currency;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final exchangeService = ref.watch(exchangeRateServiceProvider);
|
final exchangeService = ref.watch(exchangeRateServiceProvider);
|
||||||
|
|
||||||
return filtered.fold(0.0, (sum, t) {
|
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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -298,9 +316,9 @@ final activeAccountIndexProvider = StateProvider<int>((ref) => 0);
|
|||||||
final activeAccountProvider = Provider<Account?>((ref) {
|
final activeAccountProvider = Provider<Account?>((ref) {
|
||||||
final index = ref.watch(activeAccountIndexProvider);
|
final index = ref.watch(activeAccountIndexProvider);
|
||||||
final accountsAsync = ref.watch(accountsProvider);
|
final accountsAsync = ref.watch(accountsProvider);
|
||||||
|
|
||||||
if (index == 0) return null; // 0 means "Total Balance"
|
if (index == 0) return null; // 0 means "Total Balance"
|
||||||
|
|
||||||
return accountsAsync.when(
|
return accountsAsync.when(
|
||||||
data: (accounts) {
|
data: (accounts) {
|
||||||
if (index > 0 && index <= accounts.length) {
|
if (index > 0 && index <= accounts.length) {
|
||||||
@@ -330,7 +348,10 @@ final cardColorsProvider =
|
|||||||
|
|
||||||
// Account-specific color provider
|
// Account-specific color provider
|
||||||
final accountCardColorsProvider =
|
final accountCardColorsProvider =
|
||||||
StateNotifierProvider.family<CardColorsNotifier, CardColors, int>((ref, accountId) {
|
StateNotifierProvider.family<CardColorsNotifier, CardColors, int>((
|
||||||
|
ref,
|
||||||
|
accountId,
|
||||||
|
) {
|
||||||
final notifier = CardColorsNotifier(accountId: accountId);
|
final notifier = CardColorsNotifier(accountId: accountId);
|
||||||
notifier.setupThemeListener(ref);
|
notifier.setupThemeListener(ref);
|
||||||
return notifier;
|
return notifier;
|
||||||
@@ -369,7 +390,12 @@ class CardColorsNotifier extends StateNotifier<CardColors> {
|
|||||||
GradientType gradient,
|
GradientType gradient,
|
||||||
) async {
|
) async {
|
||||||
state = CardColors(primary, secondary, gradient);
|
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 {
|
Future<void> reset(bool isDark) async {
|
||||||
|
|||||||
@@ -87,9 +87,13 @@ class _BalanceCardCarouselState extends ConsumerState<BalanceCardCarousel> {
|
|||||||
Widget cardWidget;
|
Widget cardWidget;
|
||||||
|
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
|
final totalBalance = ref.watch(
|
||||||
|
globalTotalBalanceProvider,
|
||||||
|
);
|
||||||
|
final globalCurrency = ref.watch(currencyProvider);
|
||||||
cardWidget = BalanceCard(
|
cardWidget = BalanceCard(
|
||||||
balance: widget.balance,
|
balance: totalBalance,
|
||||||
currencyInfo: widget.currencyInfo,
|
currencyInfo: globalCurrency,
|
||||||
onLongPress: widget.onLongPress,
|
onLongPress: widget.onLongPress,
|
||||||
previewPrimary: widget.previewPrimary,
|
previewPrimary: widget.previewPrimary,
|
||||||
previewSecondary: widget.previewSecondary,
|
previewSecondary: widget.previewSecondary,
|
||||||
|
|||||||
Reference in New Issue
Block a user