Avoid getting erc20 metadata multiple times in the same session

This commit is contained in:
Willian Mitsuda 2021-10-28 23:39:33 -03:00
parent 7b611f96e2
commit a3626136a6
4 changed files with 5 additions and 4 deletions

View File

@ -15,7 +15,7 @@ import {
type TokenTransferItemProps = { type TokenTransferItemProps = {
t: TokenTransfer; t: TokenTransfer;
txData: TransactionData; txData: TransactionData;
tokenMeta?: TokenMeta | undefined; tokenMeta: TokenMeta | null | undefined;
}; };
// TODO: handle partial // TODO: handle partial

View File

@ -20,7 +20,7 @@ type DecoratedAddressLinkProps = {
selfDestruct?: boolean; selfDestruct?: boolean;
txFrom?: boolean; txFrom?: boolean;
txTo?: boolean; txTo?: boolean;
tokenMeta?: TokenMeta; tokenMeta?: TokenMeta | null | undefined;
}; };
const DecoratedAddresssLink: React.FC<DecoratedAddressLinkProps> = ({ const DecoratedAddresssLink: React.FC<DecoratedAddressLinkProps> = ({

View File

@ -108,4 +108,4 @@ export type TokenMeta = {
decimals: number; decimals: number;
}; };
export type TokenMetas = Record<string, TokenMeta>; export type TokenMetas = Record<string, TokenMeta | null | undefined>;

View File

@ -222,7 +222,7 @@ export const useTxData = (
// Extract token meta // Extract token meta
const tokenMetas: TokenMetas = {}; const tokenMetas: TokenMetas = {};
for (const t of tokenTransfers) { for (const t of tokenTransfers) {
if (tokenMetas[t.token]) { if (tokenMetas[t.token] !== undefined) {
continue; continue;
} }
const erc20Contract = new Contract(t.token, erc20, provider); const erc20Contract = new Contract(t.token, erc20, provider);
@ -238,6 +238,7 @@ export const useTxData = (
decimals, decimals,
}; };
} catch (err) { } catch (err) {
tokenMetas[t.token] = null;
console.warn(`Couldn't get token ${t.token} metadata; ignoring`, err); console.warn(`Couldn't get token ${t.token} metadata; ignoring`, err);
} }
} }