Skip to content

Commit

Permalink
erc 404 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
isstuev committed Apr 2, 2024
1 parent af7a835 commit 3e0f6e6
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 33 deletions.
37 changes: 37 additions & 0 deletions ui/tx/FtTokenTransferSnippet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { chakra } from '@chakra-ui/react';
import React from 'react';

import type { TokenInfo } from 'types/api/token';

import getCurrencyValue from 'lib/getCurrencyValue';
import TokenEntity from 'ui/shared/entities/token/TokenEntity';

interface Props {
token: TokenInfo;
value: string;
decimals: string | null;
}
const FtTokenTransferSnippet = ({ token, value, decimals }: Props) => {
const { valueStr, usd } = getCurrencyValue({
value: value,
exchangeRate: token.exchange_rate,
accuracyUsd: 2,
decimals: decimals,
});

return (
<>
<chakra.span color="text_secondary">for</chakra.span>
<span>{ valueStr }</span>
<TokenEntity
token={{ ...token, name: token.symbol || token.name }}
noCopy
noSymbol
w="auto"
/>
{ usd && <chakra.span color="text_secondary">(${ usd })</chakra.span> }
</>
);
};

export default React.memo(FtTokenTransferSnippet);
53 changes: 20 additions & 33 deletions ui/tx/details/TxDetailsTokenTransfer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Flex, chakra } from '@chakra-ui/react';
import { Flex } from '@chakra-ui/react';
import React from 'react';

import type {
Expand All @@ -9,11 +9,11 @@ import type {
Erc404TotalPayload,
} from 'types/api/tokenTransfer';

import getCurrencyValue from 'lib/getCurrencyValue';
import AddressFromTo from 'ui/shared/address/AddressFromTo';
import TokenEntity from 'ui/shared/entities/token/TokenEntity';
import NftTokenTransferSnippet from 'ui/tx/NftTokenTransferSnippet';

import FtTokenTransferSnippet from '../FtTokenTransferSnippet';

interface Props {
data: TTokenTransfer;
}
Expand All @@ -24,26 +24,7 @@ const TxDetailsTokenTransfer = ({ data }: Props) => {
switch (data.token.type) {
case 'ERC-20': {
const total = data.total as Erc20TotalPayload;
const { valueStr, usd } = getCurrencyValue({
value: total.value,
exchangeRate: data.token.exchange_rate,
accuracyUsd: 2,
decimals: total.decimals,
});

return (
<>
<chakra.span color="text_secondary">for</chakra.span>
<span>{ valueStr }</span>
<TokenEntity
token={{ ...data.token, name: data.token.symbol || data.token.name }}
noCopy
noSymbol
w="auto"
/>
{ usd && <chakra.span color="text_secondary">(${ usd })</chakra.span> }
</>
);
return <FtTokenTransferSnippet token={ data.token } value={ total.value } decimals={ total.decimals }/>;
}

case 'ERC-721': {
Expand Down Expand Up @@ -71,16 +52,22 @@ const TxDetailsTokenTransfer = ({ data }: Props) => {

case 'ERC-404': {
const total = data.total as Erc404TotalPayload;
return (
<NftTokenTransferSnippet
token={ data.token }
tokenId={ 'token_id' in total ? total.token_id : null }
value={ 'value' in total && total.value ?
getCurrencyValue({ value: total.value, decimals: total.decimals || '0', accuracy: 2 }).valueStr :
'1'
}
/>
);

if ('token_id' in total) {
return (
<NftTokenTransferSnippet
token={ data.token }
tokenId={ total.token_id }
value="1"
/>
);
} else {
if (total.value === null) {
return null;
}

return <FtTokenTransferSnippet token={ data.token } value={ total.value } decimals={ total.decimals }/>;
}
}
}
})();
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3e0f6e6

Please sign in to comment.