Files
explore/ui/token/TokenTransfer/TokenTransferTableItem.tsx

111 lines
3.4 KiB
TypeScript

import React from 'react';
import type { TokenInstance } from 'types/api/token';
import type { TokenTransfer } from 'types/api/tokenTransfer';
import type { ClusterChainConfig } from 'types/multichain';
import { hasTokenTransferValue, isConfidentialTokenType, NFT_TOKEN_TYPE_IDS } from 'lib/token/tokenTypes';
import { Badge } from '@luxfi/ui/badge';
import { Skeleton } from '@luxfi/ui/skeleton';
import { TableCell, TableRow } from '@luxfi/ui/table';
import AddressFromTo from 'ui/shared/address/AddressFromTo';
import NftEntity from 'ui/shared/entities/nft/NftEntity';
import TxEntity from 'ui/shared/entities/tx/TxEntity';
import ChainIcon from 'ui/shared/externalChains/ChainIcon';
import TimeWithTooltip from 'ui/shared/time/TimeWithTooltip';
import AssetValue from 'ui/shared/value/AssetValue';
import ConfidentialValue from 'ui/shared/value/ConfidentialValue';
type Props = TokenTransfer & { tokenId?: string; isLoading?: boolean; instance?: TokenInstance; chainData?: ClusterChainConfig };
const TokenTransferTableItem = ({
token,
total,
transaction_hash: txHash,
from,
to,
method,
timestamp,
tokenId,
isLoading,
instance,
chainData,
}: Props) => {
return (
<TableRow>
{ chainData && (
<TableCell>
<ChainIcon data={ chainData } isLoading={ isLoading }/>
</TableCell>
) }
<TableCell>
<div>
{ txHash ? (
<TxEntity
hash={ txHash }
isLoading={ isLoading }
noIcon
truncation="constant_long"
/>
) : <Skeleton loading={ isLoading }>-</Skeleton> }
<TimeWithTooltip
timestamp={ timestamp }
enableIncrement
isLoading={ isLoading }
color="text.secondary"
/>
</div>
</TableCell>
<TableCell>
{ method ? (
<div>
<Badge loading={ isLoading } truncated>{ method }</Badge>
</div>
) : null }
</TableCell>
<TableCell>
<AddressFromTo
from={ from }
to={ to }
isLoading={ isLoading }
mode={{ lg: 'compact', xl: 'long' }}
tokenHash={ token?.address_hash }
tokenSymbol={ token?.symbol ?? undefined }
/>
</TableCell>
{ (token && NFT_TOKEN_TYPE_IDS.includes(token.type)) && (
<TableCell>
{ total && 'token_id' in total && token && total.token_id !== null ? (
<NftEntity
hash={ token.address_hash }
id={ total.token_id }
instance={ instance || total.token_instance }
noLink={ Boolean(tokenId && tokenId === total.token_id) }
isLoading={ isLoading }
/>
) : ''
}
</TableCell>
) }
{ token && (hasTokenTransferValue(token.type)) && (
<TableCell isNumeric>
{ isConfidentialTokenType(token.type) ? (
<ConfidentialValue loading={ isLoading } className="break-all"/>
) : (
<AssetValue
amount={ total && 'value' in total ? total.value : null }
decimals={ total && 'decimals' in total ? total.decimals || '0' : '0' }
exchangeRate={ token?.exchange_rate }
loading={ isLoading }
layout="vertical"
/>
) }
</TableCell>
) }
</TableRow>
);
};
export default React.memo(TokenTransferTableItem);