|
| 1 | +import { useMemo } from 'react' |
| 2 | +import { Account } from '../models' |
| 3 | +import { Card, CardContent } from '@/features/common/components/card' |
| 4 | +import { DescriptionList } from '@/features/common/components/description-list' |
| 5 | +import { cn } from '@/features/common/utils' |
| 6 | +import { DisplayAlgo } from '@/features/common/components/display-algo' |
| 7 | +import { AccountLink } from './account-link' |
| 8 | + |
| 9 | +export const accountInformationLabel = 'Account Information' |
| 10 | +export const accountAddressLabel = 'Address' |
| 11 | +export const accountBalanceLabel = 'Balance' |
| 12 | +export const accountMinBalanceLabel = 'Min Balance' |
| 13 | +export const accountAssetsHeldLabel = 'Holding assets' |
| 14 | +export const accountAssetsCreatedLabel = 'Created assets' |
| 15 | +export const accountAssetsOptedInLabel = 'Opted assets' |
| 16 | +export const accountApplicationsCreatedLabel = 'Created applications' |
| 17 | +export const accountApplicationsOptedInLabel = 'Opted applications' |
| 18 | +export const accountRekeyedToLabel = 'Rekeyed to' |
| 19 | + |
| 20 | +export function AccountInfo({ account }: { account: Account }) { |
| 21 | + const accountInfoItems = useMemo(() => { |
| 22 | + const items = [ |
| 23 | + { |
| 24 | + dt: accountAddressLabel, |
| 25 | + dd: account.address, |
| 26 | + }, |
| 27 | + { |
| 28 | + dt: accountBalanceLabel, |
| 29 | + dd: <DisplayAlgo amount={account.balance} />, |
| 30 | + }, |
| 31 | + { |
| 32 | + dt: accountMinBalanceLabel, |
| 33 | + dd: <DisplayAlgo amount={account.minBalance} />, |
| 34 | + }, |
| 35 | + { |
| 36 | + dt: accountAssetsHeldLabel, |
| 37 | + dd: account.totalAssetsHeld, |
| 38 | + }, |
| 39 | + { |
| 40 | + dt: accountAssetsCreatedLabel, |
| 41 | + dd: account.totalAssetsCreated, |
| 42 | + }, |
| 43 | + { |
| 44 | + dt: accountAssetsOptedInLabel, |
| 45 | + dd: account.totalAssetsOptedIn, |
| 46 | + }, |
| 47 | + { |
| 48 | + dt: accountApplicationsCreatedLabel, |
| 49 | + dd: account.totalApplicationsCreated ? account.totalApplicationsCreated : 0, |
| 50 | + }, |
| 51 | + { |
| 52 | + dt: accountApplicationsOptedInLabel, |
| 53 | + dd: account.totalApplicationsOptedIn ? account.totalApplicationsOptedIn : 0, |
| 54 | + }, |
| 55 | + ...(account.rekeyedTo |
| 56 | + ? [ |
| 57 | + { |
| 58 | + dt: accountRekeyedToLabel, |
| 59 | + dd: <AccountLink address={account.rekeyedTo}></AccountLink>, |
| 60 | + }, |
| 61 | + ] |
| 62 | + : []), |
| 63 | + ] |
| 64 | + return items |
| 65 | + }, [ |
| 66 | + account.address, |
| 67 | + account.balance, |
| 68 | + account.minBalance, |
| 69 | + account.totalAssetsHeld, |
| 70 | + account.totalAssetsCreated, |
| 71 | + account.totalAssetsOptedIn, |
| 72 | + account.totalApplicationsCreated, |
| 73 | + account.totalApplicationsOptedIn, |
| 74 | + account.rekeyedTo, |
| 75 | + ]) |
| 76 | + return ( |
| 77 | + <Card aria-label={accountInformationLabel} className={cn('p-4')}> |
| 78 | + <CardContent className={cn('text-sm space-y-2')}> |
| 79 | + <DescriptionList items={accountInfoItems} /> |
| 80 | + </CardContent> |
| 81 | + </Card> |
| 82 | + ) |
| 83 | +} |
0 commit comments