-
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): [Transaction] add list transactions and basic wallet st…
…atistic
- Loading branch information
Quốc Khánh
committed
Jul 11, 2024
1 parent
8b0b970
commit f840e1e
Showing
13 changed files
with
348 additions
and
12 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
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
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
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { View } from 'react-native' | ||
import { Skeleton } from '../ui/skeleton' | ||
|
||
export function ListSkeleton() { | ||
return ( | ||
<> | ||
<View className="flex-row items-center gap-5 px-6 mb-5 mt-3"> | ||
<Skeleton className="h-6 w-6 rounded-full" /> | ||
<Skeleton className="h-4 w-[40%] rounded-full" /> | ||
</View> | ||
<View className="flex-row items-center gap-5 px-6 mb-5 mt-3"> | ||
<Skeleton className="h-6 w-6 rounded-full" /> | ||
<Skeleton className="h-4 w-[50%] rounded-full" /> | ||
</View> | ||
<View className="flex-row items-center gap-5 px-6 mb-5 mt-3"> | ||
<Skeleton className="h-6 w-6 rounded-full" /> | ||
<Skeleton className="h-4 w-[30%] rounded-full" /> | ||
</View> | ||
</> | ||
) | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { useWallets } from '@/queries/wallet' | ||
import { t } from '@lingui/macro' | ||
import { useLingui } from '@lingui/react' | ||
import { Pressable, View } from 'react-native' | ||
import { Skeleton } from '../ui/skeleton' | ||
import { Text } from '../ui/text' | ||
|
||
export function WalletStatistics() { | ||
const { i18n } = useLingui() | ||
const { data: walletAccounts, isLoading } = useWallets() | ||
|
||
/** | ||
* 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, | ||
) | ||
|
||
return ( | ||
<View className="gap-3"> | ||
<Pressable className="border-b border-primary self-start"> | ||
<Text className="w-fit self-start leading-tight"> | ||
{t(i18n)`Current balance`} | ||
</Text> | ||
</Pressable> | ||
{isLoading ? ( | ||
<Skeleton className="w-44 h-10" /> | ||
) : ( | ||
<Text className="font-semibold text-4xl"> | ||
{currentBalance?.toLocaleString() || '0.00'}{' '} | ||
<Text className="text-muted-foreground font-normal">VND</Text> | ||
</Text> | ||
)} | ||
</View> | ||
) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import Svg, { type SvgProps, Path } from 'react-native-svg' | ||
|
||
export const HandyArrow = (props: SvgProps) => ( | ||
<Svg width={51} height={87} fill="none" {...props}> | ||
<Path | ||
stroke="currentColor" | ||
strokeLinecap="round" | ||
strokeWidth={2} | ||
d="M1.715 1.547c.168.671 2.887.133 3.217.102 5.252-.487 10.983-1.296 16.054.658 5.617 2.165 10.635 7.488 13.7 12.516 3.101 5.087 5.733 10.7 6.916 16.58 1.198 5.958-3.224 11.726-7.544 15.44-1.479 1.272-3.105 2.249-5.147 1.99-7.02-.892-3.242-8.432-.819-12.078 2.417-3.636 6.537-4.663 10.586-2.924 4.976 2.138 7.97 7.096 9.62 12.048 1.535 4.603 1.253 9.363.38 14.066-1.455 7.845-4.375 15.472-6.433 23.189" | ||
/> | ||
<Path | ||
stroke="currentColor" | ||
strokeLinecap="round" | ||
strokeWidth={2} | ||
d="M37.034 74.607c0 2.113 1.609 4.407 2.515 6.2.444.876 1.866 4.829 3.217 4.649.756-.101 2.227-2.21 2.778-2.72 1.51-1.4 2.45-3.035 3.86-4.445" | ||
/> | ||
</Svg> | ||
) |
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
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 GenericIcon from '../common/generic-icon' | ||
import { Text } from '../ui/text' | ||
|
||
type TransactionItemProps = { | ||
transaction: TransactionPopulated | ||
} | ||
|
||
export const TransactionItem: FC<TransactionItemProps> = ({ transaction }) => { | ||
const { i18n } = useLingui() | ||
|
||
const iconName = useMemo(() => { | ||
return ( | ||
TRANSACTION_ICONS[transaction.note!] || | ||
transaction?.category?.icon || | ||
'Shapes' | ||
) | ||
}, [transaction]) | ||
|
||
const transactionName = useMemo(() => { | ||
return ( | ||
t(i18n)`${transaction.note}` || | ||
transaction?.category?.name || | ||
t(i18n)`Uncategorized` | ||
) | ||
}, [transaction, i18n]) | ||
|
||
return ( | ||
<Link | ||
asChild | ||
push | ||
href={{ | ||
pathname: '/transaction/[transactionId]', | ||
params: { transactionId: transaction.id }, | ||
}} | ||
> | ||
<Pressable className="flex flex-row items-center gap-4 px-6 justify-between h-14 active:bg-muted"> | ||
<View className="flex flex-row items-center gap-6 flex-1 line-clamp-1"> | ||
<GenericIcon | ||
// biome-ignore lint/suspicious/noExplicitAny: <explanation> | ||
name={iconName as any} | ||
className="size-5 text-foreground" | ||
/> | ||
<Text>{transactionName}</Text> | ||
</View> | ||
<Text | ||
className={cn( | ||
'font-semibold shrink-0', | ||
transaction.amount > 0 && 'text-green-500', | ||
)} | ||
> | ||
{Math.abs(transaction.amount).toLocaleString()}{' '} | ||
<Text className="text-muted-foreground text-[10px] font-normal"> | ||
{transaction.currency} | ||
</Text> | ||
</Text> | ||
</Pressable> | ||
</Link> | ||
) | ||
} |
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
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
Oops, something went wrong.