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 = {
t: TokenTransfer;
txData: TransactionData;
tokenMeta?: TokenMeta | undefined;
tokenMeta: TokenMeta | null | undefined;
};
// TODO: handle partial

View File

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

View File

@ -108,4 +108,4 @@ export type TokenMeta = {
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
const tokenMetas: TokenMetas = {};
for (const t of tokenTransfers) {
if (tokenMetas[t.token]) {
if (tokenMetas[t.token] !== undefined) {
continue;
}
const erc20Contract = new Contract(t.token, erc20, provider);
@ -238,6 +238,7 @@ export const useTxData = (
decimals,
};
} catch (err) {
tokenMetas[t.token] = null;
console.warn(`Couldn't get token ${t.token} metadata; ignoring`, err);
}
}