-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mobile): use transactions in store to calculate wallet stats
- Loading branch information
Showing
1 changed file
with
5 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} |