Dont display the contract tab if we know the address is an EOA

This commit is contained in:
Willian Mitsuda 2021-12-04 16:28:40 -03:00
parent f61b48742c
commit 3a6f050061
1 changed files with 51 additions and 30 deletions

View File

@ -1,4 +1,4 @@
import React, { useEffect, useContext, useCallback } from "react"; import React, { useEffect, useContext, useCallback, useMemo } from "react";
import { import {
useParams, useParams,
useNavigate, useNavigate,
@ -21,8 +21,9 @@ import Contracts from "./address/Contracts";
import { RuntimeContext } from "./useRuntime"; import { RuntimeContext } from "./useRuntime";
import { useAppConfigContext } from "./useAppConfig"; import { useAppConfigContext } from "./useAppConfig";
import { useAddressOrENSFromURL } from "./useResolvedAddresses"; import { useAddressOrENSFromURL } from "./useResolvedAddresses";
import { useSingleMetadata } from "./sourcify/useSourcify"; import { useMultipleMetadata } from "./sourcify/useSourcify";
import { ChecksummedAddress } from "./types"; import { ChecksummedAddress } from "./types";
import { useAddressesWithCode } from "./useErigonHooks";
const AddressTransactions: React.FC = () => { const AddressTransactions: React.FC = () => {
const { provider } = useContext(RuntimeContext); const { provider } = useContext(RuntimeContext);
@ -58,11 +59,24 @@ const AddressTransactions: React.FC = () => {
}, [addressOrName, checksummedAddress, isENS]); }, [addressOrName, checksummedAddress, isENS]);
const { sourcifySource } = useAppConfigContext(); const { sourcifySource } = useAppConfigContext();
const addressMetadata = useSingleMetadata( const checksummedAddressAsArray = useMemo(
checksummedAddress, () => (checksummedAddress !== undefined ? [checksummedAddress] : []),
[checksummedAddress]
);
const contractAddresses = useAddressesWithCode(
provider,
checksummedAddressAsArray
);
const metadatas = useMultipleMetadata(
undefined,
contractAddresses,
provider?.network.chainId, provider?.network.chainId,
sourcifySource sourcifySource
); );
const addressMetadata =
checksummedAddress !== undefined
? metadatas[checksummedAddress]
: undefined;
return ( return (
<StandardFrame> <StandardFrame>
@ -97,6 +111,7 @@ const AddressTransactions: React.FC = () => {
<NavTab href={`/address/${checksummedAddress}`}> <NavTab href={`/address/${checksummedAddress}`}>
Overview Overview
</NavTab> </NavTab>
{(contractAddresses?.length ?? 0) > 0 && (
<NavTab href={`/address/${checksummedAddress}/contract`}> <NavTab href={`/address/${checksummedAddress}/contract`}>
<span <span
className={`flex items-baseline space-x-2 ${ className={`flex items-baseline space-x-2 ${
@ -122,6 +137,7 @@ const AddressTransactions: React.FC = () => {
)} )}
</span> </span>
</NavTab> </NavTab>
)}
</Tab.List> </Tab.List>
<Tab.Panels> <Tab.Panels>
<Routes> <Routes>
@ -142,7 +158,12 @@ const AddressTransactions: React.FC = () => {
element={ element={
<Contracts <Contracts
checksummedAddress={checksummedAddress} checksummedAddress={checksummedAddress}
rawMetadata={addressMetadata} rawMetadata={
contractAddresses !== undefined &&
contractAddresses.length === 0
? null
: addressMetadata
}
/> />
} }
/> />