Skip to content

Commit

Permalink
feat(mobile): use transactions in store to calculate wallet stats
Browse files Browse the repository at this point in the history
  • Loading branch information
duongdev committed Aug 5, 2024
1 parent e4c514e commit 2dc9468
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions apps/mobile/components/home/wallet-statistics.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<View className="gap-3">
<Pressable className='self-start border-primary border-b'>
<Pressable className="self-start border-primary border-b">
<Text className="w-fit self-start leading-tight">
{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 2dc9468

Please sign in to comment.