diff --git a/apps/mobile/components/common/amount-format.tsx b/apps/mobile/components/common/amount-format.tsx new file mode 100644 index 00000000..3e46e6b2 --- /dev/null +++ b/apps/mobile/components/common/amount-format.tsx @@ -0,0 +1,66 @@ +import { cn } from '@/lib/utils' +import { type VariantProps, cva } from 'class-variance-authority' +import { Text } from '../ui/text' + +const amountVariants = cva('font-semibold shrink-0', { + variants: { + size: { + xl: 'text-4xl', + lg: 'text-3xl', + md: 'text-2xl', + sm: 'text-base', + }, + }, + defaultVariants: { + size: 'md', + }, +}) + +const currencyVariants = cva('text-muted-foreground font-normal', { + variants: { + size: { + xl: 'text-base', + lg: 'text-sm', + md: 'text-sm', + sm: 'text-[10px]', + }, + }, + defaultVariants: { + size: 'md', + }, +}) + +type AmountFormatProps = { + amount?: number + currency?: string + className?: string + displayNegativeSign?: boolean + displayPositiveColor?: boolean +} & VariantProps + +export function AmountFormat({ + amount = 0, + currency = 'VND', + className, + size, + displayNegativeSign, + displayPositiveColor, +}: AmountFormatProps) { + return ( + = 0 + ? displayPositiveColor + ? 'text-amount-positive' + : 'text-foreground' + : 'text-amount-negative', + className, + )} + > + {(displayNegativeSign ? amount : Math.abs(amount)).toLocaleString() || + '0.00'}{' '} + {currency} + + ) +} diff --git a/apps/mobile/components/home/wallet-statistics.tsx b/apps/mobile/components/home/wallet-statistics.tsx index cc9a7693..ce66a0bb 100644 --- a/apps/mobile/components/home/wallet-statistics.tsx +++ b/apps/mobile/components/home/wallet-statistics.tsx @@ -2,6 +2,7 @@ import { useWallets } from '@/queries/wallet' 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' @@ -28,10 +29,7 @@ export function WalletStatistics() { {isLoading ? ( ) : ( - - {currentBalance?.toLocaleString() || '0.00'}{' '} - VND - + )} ) diff --git a/apps/mobile/components/transaction/transaction-item.tsx b/apps/mobile/components/transaction/transaction-item.tsx index 03fd5ff8..0b34365a 100644 --- a/apps/mobile/components/transaction/transaction-item.tsx +++ b/apps/mobile/components/transaction/transaction-item.tsx @@ -1,11 +1,11 @@ import { TRANSACTION_ICONS } from '@/lib/icons/category-icons' -import { cn } from '@/lib/utils' import type { TransactionPopulated } from '@6pm/validation' import { t } from '@lingui/macro' import { useLingui } from '@lingui/react' import { Link } from 'expo-router' import { type FC, useMemo } from 'react' import { Pressable, View } from 'react-native' +import { AmountFormat } from '../common/amount-format' import GenericIcon from '../common/generic-icon' import { Text } from '../ui/text' @@ -52,18 +52,12 @@ export const TransactionItem: FC = ({ transaction }) => { {transactionName} - 0 && 'text-amount-positive', - transaction.amount < 0 && 'text-amount-negative', - )} - > - {Math.abs(transaction.amount).toLocaleString()}{' '} - - {transaction.currency} - - + ) diff --git a/apps/mobile/components/wallet/wallet-account-item.tsx b/apps/mobile/components/wallet/wallet-account-item.tsx index 37f622b3..dbe4db57 100644 --- a/apps/mobile/components/wallet/wallet-account-item.tsx +++ b/apps/mobile/components/wallet/wallet-account-item.tsx @@ -3,9 +3,9 @@ import { Link } from 'expo-router' import { ChevronRightIcon } from 'lucide-react-native' import type { FC } from 'react' import { View } from 'react-native' +import { AmountFormat } from '../common/amount-format' import GenericIcon from '../common/generic-icon' import { MenuItem } from '../common/menu-item' -import { Text } from '../ui/text' type WalletAccountItemProps = { data: WalletAccountWithBalance @@ -32,10 +32,7 @@ export const WalletAccountItem: FC = ({ data }) => { )} rightSection={ - - {Number(data.balance ?? '0')?.toLocaleString?.()}{' '} - {data.preferredCurrency} - + }