Skip to content

Commit

Permalink
feat(mobile): use transactions in store to calculate wallet stats (#208)
Browse files Browse the repository at this point in the history
Instant update ⚡
  • Loading branch information
duongdev authored Aug 5, 2024
1 parent fe11ac6 commit 9446396
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions apps/mobile/components/home/wallet-statistics.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
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 (
<View className="gap-3">
Expand All @@ -26,11 +22,7 @@ export function WalletStatistics() {
{t(i18n)`Current balance`}
</Text>
</Pressable>
{isLoading ? (
<Skeleton className="h-10 w-44" />
) : (
<AmountFormat amount={currentBalance} size="xl" displayNegativeSign />
)}
<AmountFormat amount={currentBalance} size="xl" displayNegativeSign />
</View>
)
}

0 comments on commit 9446396

Please sign in to comment.