|
| 1 | +import { Card, CardContent } from '@/features/common/components/card' |
| 2 | +import { DescriptionList } from '@/features/common/components/description-list' |
| 3 | +import { useMemo } from 'react' |
| 4 | +import { cn } from '@/features/common/utils' |
| 5 | +import { Asset } from '../models' |
| 6 | +import { isDefined } from '@/utils/is-defined' |
| 7 | +import Decimal from 'decimal.js' |
| 8 | +import { AccountLink } from '@/features/accounts/components/account-link' |
| 9 | +import { ZERO_ADDRESS } from '@/features/common/constants' |
| 10 | + |
| 11 | +type Props = { |
| 12 | + asset: Asset |
| 13 | +} |
| 14 | + |
| 15 | +export const assetIdLabel = 'Asset ID' |
| 16 | +export const assetNameLabel = 'Name' |
| 17 | +export const assetUnitNameLabel = 'Unit' |
| 18 | +export const assetDecimalsLabel = 'Decimals' |
| 19 | +export const assetTotalSupplyLabel = 'Total Supply' |
| 20 | +export const assetMetadataHashLabel = 'Metadata Hash' |
| 21 | +export const assetDefaultFrozenLabel = 'Default Frozen' |
| 22 | +export const assetUrlLabel = 'URL' |
| 23 | + |
| 24 | +export const assetAddressesLabel = 'Asset Addresses' |
| 25 | +export const assetCreatorLabel = 'Creator' |
| 26 | +export const assetManagerLabel = 'Manager' |
| 27 | +export const assetReserveLabel = 'Reserve' |
| 28 | +export const assetFreezeLabel = 'Freeze' |
| 29 | +export const assetClawbackLabel = 'Clawback' |
| 30 | + |
| 31 | +export const assetJsonLabel = 'Asset JSON' |
| 32 | + |
| 33 | +export function AssetDetails({ asset }: Props) { |
| 34 | + const assetItems = useMemo( |
| 35 | + () => [ |
| 36 | + { |
| 37 | + dt: assetIdLabel, |
| 38 | + dd: asset.id, |
| 39 | + }, |
| 40 | + asset.name |
| 41 | + ? { |
| 42 | + dt: assetNameLabel, |
| 43 | + dd: asset.name, |
| 44 | + } |
| 45 | + : undefined, |
| 46 | + asset.unitName |
| 47 | + ? { |
| 48 | + dt: assetUnitNameLabel, |
| 49 | + dd: asset.unitName, |
| 50 | + } |
| 51 | + : undefined, |
| 52 | + { |
| 53 | + dt: assetTotalSupplyLabel, |
| 54 | + dd: `${new Decimal(asset.total.toString()).div(new Decimal(10).pow(asset.decimals.toString()))} ${asset.unitName}`, |
| 55 | + }, |
| 56 | + { |
| 57 | + dt: assetDecimalsLabel, |
| 58 | + dd: asset.decimals.toString(), |
| 59 | + }, |
| 60 | + { |
| 61 | + dt: assetDefaultFrozenLabel, |
| 62 | + dd: asset.defaultFrozen ? 'Yes' : 'No', |
| 63 | + }, |
| 64 | + asset.url |
| 65 | + ? { |
| 66 | + dt: assetUrlLabel, |
| 67 | + dd: ( |
| 68 | + <a href={asset.url} className={cn('text-primary underline')}> |
| 69 | + {asset.url} |
| 70 | + </a> |
| 71 | + ), |
| 72 | + } |
| 73 | + : undefined, |
| 74 | + ], |
| 75 | + [asset.decimals, asset.defaultFrozen, asset.id, asset.name, asset.total, asset.unitName, asset.url] |
| 76 | + ).filter(isDefined) |
| 77 | + |
| 78 | + const assetAddresses = useMemo( |
| 79 | + () => [ |
| 80 | + { |
| 81 | + dt: assetCreatorLabel, |
| 82 | + dd: <AccountLink address={asset.creator} />, |
| 83 | + }, |
| 84 | + asset.manager && asset.manager !== ZERO_ADDRESS |
| 85 | + ? { |
| 86 | + dt: assetManagerLabel, |
| 87 | + dd: <AccountLink address={asset.manager} />, |
| 88 | + } |
| 89 | + : undefined, |
| 90 | + asset.reserve && asset.reserve !== ZERO_ADDRESS |
| 91 | + ? { |
| 92 | + dt: assetReserveLabel, |
| 93 | + dd: <AccountLink address={asset.reserve} />, |
| 94 | + } |
| 95 | + : undefined, |
| 96 | + asset.freeze && asset.freeze !== ZERO_ADDRESS |
| 97 | + ? { |
| 98 | + dt: assetFreezeLabel, |
| 99 | + dd: <AccountLink address={asset.freeze} />, |
| 100 | + } |
| 101 | + : undefined, |
| 102 | + asset.clawback && asset.clawback !== ZERO_ADDRESS |
| 103 | + ? { |
| 104 | + dt: assetClawbackLabel, |
| 105 | + dd: <AccountLink address={asset.clawback} />, |
| 106 | + } |
| 107 | + : undefined, |
| 108 | + ], |
| 109 | + [asset.clawback, asset.creator, asset.freeze, asset.manager, asset.reserve] |
| 110 | + ).filter(isDefined) |
| 111 | + |
| 112 | + return ( |
| 113 | + <div className={cn('space-y-6 pt-7')}> |
| 114 | + <Card className={cn('p-4')}> |
| 115 | + <CardContent className={cn('text-sm space-y-2')}> |
| 116 | + <DescriptionList items={assetItems} /> |
| 117 | + </CardContent> |
| 118 | + </Card> |
| 119 | + <Card className={cn('p-4')}> |
| 120 | + <CardContent className={cn('text-sm space-y-2')}> |
| 121 | + <h1 className={cn('text-2xl text-primary font-bold')}>{assetAddressesLabel}</h1> |
| 122 | + <DescriptionList items={assetAddresses} /> |
| 123 | + </CardContent> |
| 124 | + </Card> |
| 125 | + <Card className={cn('p-4')}> |
| 126 | + <CardContent className={cn('text-sm space-y-2')}> |
| 127 | + <h1 className={cn('text-2xl text-primary font-bold')}>{assetJsonLabel}</h1> |
| 128 | + <div className={cn('border-solid border-2 border-border h-96 grid')}> |
| 129 | + <pre className={cn('overflow-scroll p-4')}>{asset.json}</pre> |
| 130 | + </div> |
| 131 | + </CardContent> |
| 132 | + </Card> |
| 133 | + </div> |
| 134 | + ) |
| 135 | +} |
0 commit comments