Fix not known metadata scenario

This commit is contained in:
Willian Mitsuda 2021-09-27 00:49:23 -03:00
parent 9236bfcb2f
commit 9285d4dedf
3 changed files with 8 additions and 12 deletions

View File

@ -7,7 +7,7 @@ import DecoratedAddressLink from "./components/DecoratedAddressLink";
import FormattedBalance from "./components/FormattedBalance"; import FormattedBalance from "./components/FormattedBalance";
import { import {
AddressContext, AddressContext,
TokenMetas, TokenMeta,
TokenTransfer, TokenTransfer,
TransactionData, TransactionData,
} from "./types"; } from "./types";
@ -15,14 +15,14 @@ import {
type TokenTransferItemProps = { type TokenTransferItemProps = {
t: TokenTransfer; t: TokenTransfer;
txData: TransactionData; txData: TransactionData;
tokenMetas: TokenMetas; tokenMeta?: TokenMeta | undefined;
}; };
// TODO: handle partial // TODO: handle partial
const TokenTransferItem: React.FC<TokenTransferItemProps> = ({ const TokenTransferItem: React.FC<TokenTransferItemProps> = ({
t, t,
txData, txData,
tokenMetas, tokenMeta,
}) => ( }) => (
<div className="flex items-baseline space-x-2 px-2 py-1 truncate hover:bg-gray-100"> <div className="flex items-baseline space-x-2 px-2 py-1 truncate hover:bg-gray-100">
<span className="text-gray-500"> <span className="text-gray-500">
@ -57,7 +57,7 @@ const TokenTransferItem: React.FC<TokenTransferItemProps> = ({
<ValueHighlighter value={t.value}> <ValueHighlighter value={t.value}>
<FormattedBalance <FormattedBalance
value={t.value} value={t.value}
decimals={tokenMetas[t.token].decimals} decimals={tokenMeta?.decimals ?? 0}
/> />
</ValueHighlighter> </ValueHighlighter>
</span> </span>
@ -65,11 +65,9 @@ const TokenTransferItem: React.FC<TokenTransferItemProps> = ({
<DecoratedAddressLink <DecoratedAddressLink
address={t.token} address={t.token}
text={ text={
tokenMetas[t.token] tokenMeta ? `${tokenMeta.name} (${tokenMeta.symbol})` : undefined
? `${tokenMetas[t.token].name} (${tokenMetas[t.token].symbol})`
: ""
} }
tokenMeta={tokenMetas[t.token]} tokenMeta={tokenMeta}
/> />
</AddressHighlighter> </AddressHighlighter>
</div> </div>

View File

@ -206,7 +206,7 @@ const Details: React.FC<DetailsProps> = ({
key={i} key={i}
t={t} t={t}
txData={txData} txData={txData}
tokenMetas={txData.tokenMetas} tokenMeta={txData.tokenMetas[t.token]}
/> />
))} ))}
</div> </div>

View File

@ -108,6 +108,4 @@ export type TokenMeta = {
decimals: number; decimals: number;
}; };
export type TokenMetas = { export type TokenMetas = Record<string, TokenMeta>;
[tokenAddress: string]: TokenMeta;
};