From 3a6f050061492f7fa09c1672786de1c0e978006c Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Sat, 4 Dec 2021 16:28:40 -0300 Subject: [PATCH] Dont display the contract tab if we know the address is an EOA --- src/AddressTransactions.tsx | 81 +++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 30 deletions(-) diff --git a/src/AddressTransactions.tsx b/src/AddressTransactions.tsx index 17c8888..9adcd86 100644 --- a/src/AddressTransactions.tsx +++ b/src/AddressTransactions.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useContext, useCallback } from "react"; +import React, { useEffect, useContext, useCallback, useMemo } from "react"; import { useParams, useNavigate, @@ -21,8 +21,9 @@ import Contracts from "./address/Contracts"; import { RuntimeContext } from "./useRuntime"; import { useAppConfigContext } from "./useAppConfig"; import { useAddressOrENSFromURL } from "./useResolvedAddresses"; -import { useSingleMetadata } from "./sourcify/useSourcify"; +import { useMultipleMetadata } from "./sourcify/useSourcify"; import { ChecksummedAddress } from "./types"; +import { useAddressesWithCode } from "./useErigonHooks"; const AddressTransactions: React.FC = () => { const { provider } = useContext(RuntimeContext); @@ -58,11 +59,24 @@ const AddressTransactions: React.FC = () => { }, [addressOrName, checksummedAddress, isENS]); const { sourcifySource } = useAppConfigContext(); - const addressMetadata = useSingleMetadata( - checksummedAddress, + const checksummedAddressAsArray = useMemo( + () => (checksummedAddress !== undefined ? [checksummedAddress] : []), + [checksummedAddress] + ); + const contractAddresses = useAddressesWithCode( + provider, + checksummedAddressAsArray + ); + const metadatas = useMultipleMetadata( + undefined, + contractAddresses, provider?.network.chainId, sourcifySource ); + const addressMetadata = + checksummedAddress !== undefined + ? metadatas[checksummedAddress] + : undefined; return ( @@ -97,31 +111,33 @@ const AddressTransactions: React.FC = () => { Overview - - - Contract - {addressMetadata === undefined ? ( - - - - ) : addressMetadata === null ? ( - - - - ) : ( - - - - )} - - + {(contractAddresses?.length ?? 0) > 0 && ( + + + Contract + {addressMetadata === undefined ? ( + + + + ) : addressMetadata === null ? ( + + + + ) : ( + + + + )} + + + )} @@ -142,7 +158,12 @@ const AddressTransactions: React.FC = () => { element={ } />