Commit 11a56827 authored by tom's avatar tom

remove array cheching in tx details token transfers

parent a45a5752
...@@ -18,8 +18,6 @@ export interface TokenCounters { ...@@ -18,8 +18,6 @@ export interface TokenCounters {
transfers_count: string; transfers_count: string;
} }
export type TokenInfoGeneric<Type extends TokenType> = Omit<TokenInfo, 'type'> & { type: Type };
export interface TokenHolders { export interface TokenHolders {
items: Array<TokenHolder>; items: Array<TokenHolder>;
next_page_params: TokenHoldersPagination; next_page_params: TokenHoldersPagination;
......
import type { AddressParam } from './addressParams'; import type { AddressParam } from './addressParams';
import type { TokenInfoGeneric, TokenType } from './token'; import type { TokenInfo, TokenType } from './token';
export type Erc20TotalPayload = { export type Erc20TotalPayload = {
decimals: string | null; decimals: string | null;
...@@ -18,20 +18,20 @@ export type Erc1155TotalPayload = { ...@@ -18,20 +18,20 @@ export type Erc1155TotalPayload = {
export type TokenTransfer = ( export type TokenTransfer = (
{ {
token: TokenInfoGeneric<'ERC-20'>; token: TokenInfo<'ERC-20'>;
total: Erc20TotalPayload; total: Erc20TotalPayload;
} | } |
{ {
token: TokenInfoGeneric<'ERC-721'>; token: TokenInfo<'ERC-721'>;
total: Erc721TotalPayload; total: Erc721TotalPayload;
} | } |
{ {
token: TokenInfoGeneric<'ERC-1155'>; token: TokenInfo<'ERC-1155'>;
total: Erc1155TotalPayload; total: Erc1155TotalPayload;
} }
) & TokenTransferBase ) & TokenTransferBase
export type TokenTotal = Erc20TotalPayload | Erc721TotalPayload | Erc1155TotalPayload | Array<Erc1155TotalPayload>; export type TokenTotal = Erc20TotalPayload | Erc721TotalPayload | Erc1155TotalPayload;
interface TokenTransferBase { interface TokenTransferBase {
type: 'token_transfer' | 'token_burning' | 'token_spawning' | 'token_minting'; type: 'token_transfer' | 'token_burning' | 'token_spawning' | 'token_minting';
......
...@@ -11,25 +11,25 @@ import CurrencyValue from 'ui/shared/CurrencyValue'; ...@@ -11,25 +11,25 @@ import CurrencyValue from 'ui/shared/CurrencyValue';
import TokenSnippet from 'ui/shared/TokenSnippet/TokenSnippet'; import TokenSnippet from 'ui/shared/TokenSnippet/TokenSnippet';
import NftTokenTransferSnippet from 'ui/tx/NftTokenTransferSnippet'; import NftTokenTransferSnippet from 'ui/tx/NftTokenTransferSnippet';
type Props = TTokenTransfer; interface Props {
data: TTokenTransfer;
}
const TxDetailsTokenTransfer = ({ token, total, to, from }: Props) => { const TxDetailsTokenTransfer = ({ data }: Props) => {
const isColumnLayout = token.type === 'ERC-1155' && Array.isArray(total);
const content = (() => { const content = (() => {
switch (token.type) { switch (data.token.type) {
case 'ERC-20': { case 'ERC-20': {
const payload = total as Erc20TotalPayload; const total = data.total as Erc20TotalPayload;
return ( return (
<Flex flexWrap="wrap" columnGap={ 3 } rowGap={ 2 }> <Flex flexWrap="wrap" columnGap={ 3 } rowGap={ 2 }>
<Text fontWeight={ 500 } as="span">For:{ space } <Text fontWeight={ 500 } as="span">For:{ space }
<CurrencyValue value={ payload.value } exchangeRate={ token.exchange_rate } fontWeight={ 600 } decimals={ payload.decimals }/> <CurrencyValue value={ total.value } exchangeRate={ data.token.exchange_rate } fontWeight={ 600 } decimals={ total.decimals }/>
</Text> </Text>
<TokenSnippet <TokenSnippet
symbol={ trimTokenSymbol(token.symbol) } symbol={ trimTokenSymbol(data.token.symbol) }
hash={ token.address } hash={ data.token.address }
name={ token.name } name={ data.token.name }
w="auto" w="auto"
flexGrow="1" flexGrow="1"
columnGap={ 1 } columnGap={ 1 }
...@@ -40,47 +40,46 @@ const TxDetailsTokenTransfer = ({ token, total, to, from }: Props) => { ...@@ -40,47 +40,46 @@ const TxDetailsTokenTransfer = ({ token, total, to, from }: Props) => {
} }
case 'ERC-721': { case 'ERC-721': {
const payload = total as Erc721TotalPayload; const total = data.total as Erc721TotalPayload;
return ( return (
<NftTokenTransferSnippet <NftTokenTransferSnippet
name={ token.name } name={ data.token.name }
tokenId={ payload.token_id } tokenId={ total.token_id }
value="1" value="1"
hash={ token.address } hash={ data.token.address }
symbol={ trimTokenSymbol(token.symbol) } symbol={ trimTokenSymbol(data.token.symbol) }
/> />
); );
} }
case 'ERC-1155': { case 'ERC-1155': {
const payload = total as Erc1155TotalPayload | Array<Erc1155TotalPayload>; const total = data.total as Erc1155TotalPayload;
const items = Array.isArray(payload) ? payload : [ payload ]; return (
return items.map((item) => (
<NftTokenTransferSnippet <NftTokenTransferSnippet
name={ token.name } name={ data.token.name }
key={ item.token_id } key={ total.token_id }
tokenId={ item.token_id } tokenId={ total.token_id }
value={ item.value } value={ total.value }
hash={ token.address } hash={ data.token.address }
symbol={ trimTokenSymbol(token.symbol) } symbol={ trimTokenSymbol(data.token.symbol) }
/> />
)); );
} }
} }
})(); })();
return ( return (
<Flex <Flex
alignItems={ isColumnLayout ? 'flex-start' : 'center' } alignItems="center"
flexWrap="wrap" flexWrap="wrap"
columnGap={ 3 } columnGap={ 3 }
rowGap={ 3 } rowGap={ 3 }
flexDir={ isColumnLayout ? 'column' : 'row' } flexDir="row"
> >
<Flex alignItems="center"> <Flex alignItems="center">
<AddressLink type="address" fontWeight="500" hash={ from.hash } truncation="constant"/> <AddressLink type="address" fontWeight="500" hash={ data.from.hash } truncation="constant"/>
<Icon as={ rightArrowIcon } boxSize={ 6 } mx={ 2 } color="gray.500"/> <Icon as={ rightArrowIcon } boxSize={ 6 } mx={ 2 } color="gray.500"/>
<AddressLink type="address" fontWeight="500" hash={ to.hash } truncation="constant"/> <AddressLink type="address" fontWeight="500" hash={ data.to.hash } truncation="constant"/>
</Flex> </Flex>
<Flex flexDir="column" rowGap={ 5 }> <Flex flexDir="column" rowGap={ 5 }>
{ content } { content }
......
...@@ -52,7 +52,7 @@ const TxDetailsTokenTransfers = ({ data, txHash }: Props) => { ...@@ -52,7 +52,7 @@ const TxDetailsTokenTransfers = ({ data, txHash }: Props) => {
rowGap={ 5 } rowGap={ 5 }
w="100%" w="100%"
> >
{ items.slice(0, VISIBLE_ITEMS_NUM).map((item, index) => <TxDetailsTokenTransfer key={ index } { ...item }/>) } { items.slice(0, VISIBLE_ITEMS_NUM).map((item, index) => <TxDetailsTokenTransfer key={ index } data={ item }/>) }
</Flex> </Flex>
</DetailsInfoItem> </DetailsInfoItem>
); );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment