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 {
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 (
<StandardFrame>
@ -97,6 +111,7 @@ const AddressTransactions: React.FC = () => {
<NavTab href={`/address/${checksummedAddress}`}>
Overview
</NavTab>
{(contractAddresses?.length ?? 0) > 0 && (
<NavTab href={`/address/${checksummedAddress}/contract`}>
<span
className={`flex items-baseline space-x-2 ${
@ -122,6 +137,7 @@ const AddressTransactions: React.FC = () => {
)}
</span>
</NavTab>
)}
</Tab.List>
<Tab.Panels>
<Routes>
@ -142,7 +158,12 @@ const AddressTransactions: React.FC = () => {
element={
<Contracts
checksummedAddress={checksummedAddress}
rawMetadata={addressMetadata}
rawMetadata={
contractAddresses !== undefined &&
contractAddresses.length === 0
? null
: addressMetadata
}
/>
}
/>