From 379ffda83ed0352d28e4e570752e1ce7dcd3aa13 Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Thu, 25 Nov 2021 15:41:40 -0300 Subject: [PATCH] Extract single Sourcify metadata helper function --- src/AddressTransactions.tsx | 23 ++++++----------------- src/useSourcify.ts | 10 ++++++++++ 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/AddressTransactions.tsx b/src/AddressTransactions.tsx index 0328c8a..ea2baa3 100644 --- a/src/AddressTransactions.tsx +++ b/src/AddressTransactions.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect, useMemo, useContext } from "react"; +import React, { useState, useEffect, useContext } from "react"; import { useParams, useNavigate, @@ -20,7 +20,7 @@ import AddressTransactionResults from "./address/AddressTransactionResults"; import Contracts from "./address/Contracts"; import { RuntimeContext } from "./useRuntime"; import { useAppConfigContext } from "./useAppConfig"; -import { useMultipleMetadata } from "./useSourcify"; +import { useSingleMetadata } from "./useSourcify"; import SourcifyLogo from "./sourcify.svg"; const AddressTransactions: React.FC = () => { @@ -83,21 +83,12 @@ const AddressTransactions: React.FC = () => { resolveName(); }, [provider, addressOrName, navigate, direction, searchParams]); - const addresses = useMemo( - () => (checksummedAddress ? [checksummedAddress] : []), - [checksummedAddress] - ); const { sourcifySource } = useAppConfigContext(); - const metadatas = useMultipleMetadata( - undefined, - addresses, + const addressMetadata = useSingleMetadata( + checksummedAddress, provider?.network.chainId, sourcifySource ); - const addressMetadata = - checksummedAddress !== undefined - ? metadatas[checksummedAddress] - : undefined; return ( @@ -151,7 +142,7 @@ const AddressTransactions: React.FC = () => { ) : ( - + Sourcify logo { + } /> { + const addresses = useMemo(() => (address ? [address] : []), [address]); + const metadatas = useMultipleMetadata(undefined, addresses, chainId, source); + return address !== undefined ? metadatas[address] : undefined; +}; + export const useMultipleMetadata = ( baseMetadatas: Record | undefined, addresses: (ChecksummedAddress | undefined)[],