From 2dc9468948ad5e02c0a01e49a3fa4d34078418f8 Mon Sep 17 00:00:00 2001 From: Dustin Do Date: Mon, 5 Aug 2024 23:50:54 +0700 Subject: [PATCH] feat(mobile): use transactions in store to calculate wallet stats --- .../components/home/wallet-statistics.tsx | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/apps/mobile/components/home/wallet-statistics.tsx b/apps/mobile/components/home/wallet-statistics.tsx index 6ff88c37..5e79fd86 100644 --- a/apps/mobile/components/home/wallet-statistics.tsx +++ b/apps/mobile/components/home/wallet-statistics.tsx @@ -1,36 +1,28 @@ -import { useWallets } from '@/queries/wallet' +import { useTransactionStore } from '@/stores/transaction/store' import { t } from '@lingui/macro' import { useLingui } from '@lingui/react' import { Pressable, View } from 'react-native' import { AmountFormat } from '../common/amount-format' -import { Skeleton } from '../ui/skeleton' import { Text } from '../ui/text' export function WalletStatistics() { const { i18n } = useLingui() - const { data: walletAccounts, isLoading } = useWallets() + const { transactions } = useTransactionStore() /** * TODO: Calculate correct amount with currency exchange rate * base on the user's preferred currency */ - const currentBalance = walletAccounts?.reduce( - (acc, walletAccount) => acc + (walletAccount?.balance ?? 0), - 0, - ) + const currentBalance = transactions.reduce((acc, t) => acc + t.amount, 0) return ( - + {t(i18n)`Current balance`} - {isLoading ? ( - - ) : ( - - )} + ) }