Encapsulate hook call
This commit is contained in:
parent
812539674e
commit
bf2aa4e644
|
@ -21,7 +21,6 @@ import SourcifyLogo from "./sourcify/SourcifyLogo";
|
||||||
import AddressTransactionResults from "./address/AddressTransactionResults";
|
import AddressTransactionResults from "./address/AddressTransactionResults";
|
||||||
import Contracts from "./address/Contracts";
|
import Contracts from "./address/Contracts";
|
||||||
import { RuntimeContext } from "./useRuntime";
|
import { RuntimeContext } from "./useRuntime";
|
||||||
import { useAppConfigContext } from "./useAppConfig";
|
|
||||||
import { useAddressOrENS } from "./useResolvedAddresses";
|
import { useAddressOrENS } from "./useResolvedAddresses";
|
||||||
import { useSourcifyMetadata } from "./sourcify/useSourcify";
|
import { useSourcifyMetadata } from "./sourcify/useSourcify";
|
||||||
import { ChecksummedAddress } from "./types";
|
import { ChecksummedAddress } from "./types";
|
||||||
|
@ -66,11 +65,9 @@ const Address: React.FC = () => {
|
||||||
}, [addressOrName, checksummedAddress, isENS]);
|
}, [addressOrName, checksummedAddress, isENS]);
|
||||||
|
|
||||||
const hasCode = useHasCode(provider, checksummedAddress, "latest");
|
const hasCode = useHasCode(provider, checksummedAddress, "latest");
|
||||||
const { sourcifySource } = useAppConfigContext();
|
|
||||||
const addressMetadata = useSourcifyMetadata(
|
const addressMetadata = useSourcifyMetadata(
|
||||||
hasCode ? checksummedAddress : undefined,
|
hasCode ? checksummedAddress : undefined,
|
||||||
provider?.network.chainId,
|
provider?.network.chainId
|
||||||
sourcifySource
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const { network, faucets } = useChainInfo();
|
const { network, faucets } = useChainInfo();
|
||||||
|
|
|
@ -9,7 +9,6 @@ import { faCoins } from "@fortawesome/free-solid-svg-icons/faCoins";
|
||||||
import SourcifyLogo from "../sourcify/SourcifyLogo";
|
import SourcifyLogo from "../sourcify/SourcifyLogo";
|
||||||
import PlainAddress from "./PlainAddress";
|
import PlainAddress from "./PlainAddress";
|
||||||
import { RuntimeContext } from "../useRuntime";
|
import { RuntimeContext } from "../useRuntime";
|
||||||
import { useAppConfigContext } from "../useAppConfig";
|
|
||||||
import { useSourcifyMetadata } from "../sourcify/useSourcify";
|
import { useSourcifyMetadata } from "../sourcify/useSourcify";
|
||||||
import { useResolvedAddress } from "../useResolvedAddresses";
|
import { useResolvedAddress } from "../useResolvedAddresses";
|
||||||
import { AddressContext, ChecksummedAddress, ZERO_ADDRESS } from "../types";
|
import { AddressContext, ChecksummedAddress, ZERO_ADDRESS } from "../types";
|
||||||
|
@ -39,12 +38,7 @@ const DecoratedAddressLink: React.FC<DecoratedAddressLinkProps> = ({
|
||||||
eoa,
|
eoa,
|
||||||
}) => {
|
}) => {
|
||||||
const { provider } = useContext(RuntimeContext);
|
const { provider } = useContext(RuntimeContext);
|
||||||
const { sourcifySource } = useAppConfigContext();
|
const metadata = useSourcifyMetadata(address, provider?.network.chainId);
|
||||||
const metadata = useSourcifyMetadata(
|
|
||||||
address,
|
|
||||||
provider?.network.chainId,
|
|
||||||
sourcifySource
|
|
||||||
);
|
|
||||||
|
|
||||||
const mint = addressCtx === AddressContext.FROM && address === ZERO_ADDRESS;
|
const mint = addressCtx === AddressContext.FROM && address === ZERO_ADDRESS;
|
||||||
const burn = addressCtx === AddressContext.TO && address === ZERO_ADDRESS;
|
const burn = addressCtx === AddressContext.TO && address === ZERO_ADDRESS;
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { ErrorDescription } from "@ethersproject/abi/lib/interface";
|
||||||
import useSWRImmutable from "swr/immutable";
|
import useSWRImmutable from "swr/immutable";
|
||||||
import { ChecksummedAddress, TransactionData } from "../types";
|
import { ChecksummedAddress, TransactionData } from "../types";
|
||||||
import { sourcifyMetadata, SourcifySource, sourcifySourceFile } from "../url";
|
import { sourcifyMetadata, SourcifySource, sourcifySourceFile } from "../url";
|
||||||
|
import { useAppConfigContext } from "../useAppConfig";
|
||||||
|
|
||||||
export type UserMethod = {
|
export type UserMethod = {
|
||||||
notice?: string | undefined;
|
notice?: string | undefined;
|
||||||
|
@ -98,13 +99,13 @@ const sourcifyFetcher = async (url: string) => {
|
||||||
|
|
||||||
export const useSourcifyMetadata = (
|
export const useSourcifyMetadata = (
|
||||||
address: ChecksummedAddress | undefined,
|
address: ChecksummedAddress | undefined,
|
||||||
chainId: number | undefined,
|
chainId: number | undefined
|
||||||
source: SourcifySource
|
|
||||||
): Metadata | null | undefined => {
|
): Metadata | null | undefined => {
|
||||||
|
const { sourcifySource } = useAppConfigContext();
|
||||||
const metadataURL = () =>
|
const metadataURL = () =>
|
||||||
address === undefined || chainId === undefined
|
address === undefined || chainId === undefined
|
||||||
? null
|
? null
|
||||||
: sourcifyMetadata(address, chainId, source);
|
: sourcifyMetadata(address, chainId, sourcifySource);
|
||||||
const { data, error } = useSWRImmutable<Metadata>(
|
const { data, error } = useSWRImmutable<Metadata>(
|
||||||
metadataURL,
|
metadataURL,
|
||||||
sourcifyFetcher
|
sourcifyFetcher
|
||||||
|
|
|
@ -37,7 +37,6 @@ import {
|
||||||
use4Bytes,
|
use4Bytes,
|
||||||
useTransactionDescription,
|
useTransactionDescription,
|
||||||
} from "../use4Bytes";
|
} from "../use4Bytes";
|
||||||
import { useAppConfigContext } from "../useAppConfig";
|
|
||||||
import {
|
import {
|
||||||
useError,
|
useError,
|
||||||
useSourcifyMetadata,
|
useSourcifyMetadata,
|
||||||
|
@ -82,12 +81,7 @@ const Details: React.FC<DetailsProps> = ({ txData }) => {
|
||||||
return false;
|
return false;
|
||||||
}, [txData, internalOps]);
|
}, [txData, internalOps]);
|
||||||
|
|
||||||
const { sourcifySource } = useAppConfigContext();
|
const metadata = useSourcifyMetadata(txData?.to, provider?.network.chainId);
|
||||||
const metadata = useSourcifyMetadata(
|
|
||||||
txData?.to,
|
|
||||||
provider?.network.chainId,
|
|
||||||
sourcifySource
|
|
||||||
);
|
|
||||||
|
|
||||||
const txDesc = useSourcifyTransactionDescription(metadata, txData);
|
const txDesc = useSourcifyTransactionDescription(metadata, txData);
|
||||||
const userDoc = metadata?.output.userdoc;
|
const userDoc = metadata?.output.userdoc;
|
||||||
|
|
|
@ -9,7 +9,6 @@ import DecodedParamsTable from "./decoder/DecodedParamsTable";
|
||||||
import DecodedLogSignature from "./decoder/DecodedLogSignature";
|
import DecodedLogSignature from "./decoder/DecodedLogSignature";
|
||||||
import { useTopic0 } from "../useTopic0";
|
import { useTopic0 } from "../useTopic0";
|
||||||
import { RuntimeContext } from "../useRuntime";
|
import { RuntimeContext } from "../useRuntime";
|
||||||
import { useAppConfigContext } from "../useAppConfig";
|
|
||||||
import { useSourcifyMetadata } from "../sourcify/useSourcify";
|
import { useSourcifyMetadata } from "../sourcify/useSourcify";
|
||||||
|
|
||||||
type LogEntryProps = {
|
type LogEntryProps = {
|
||||||
|
@ -18,12 +17,7 @@ type LogEntryProps = {
|
||||||
|
|
||||||
const LogEntry: React.FC<LogEntryProps> = ({ log }) => {
|
const LogEntry: React.FC<LogEntryProps> = ({ log }) => {
|
||||||
const { provider } = useContext(RuntimeContext);
|
const { provider } = useContext(RuntimeContext);
|
||||||
const { sourcifySource } = useAppConfigContext();
|
const metadata = useSourcifyMetadata(log.address, provider?.network.chainId);
|
||||||
const metadata = useSourcifyMetadata(
|
|
||||||
log.address,
|
|
||||||
provider?.network.chainId,
|
|
||||||
sourcifySource
|
|
||||||
);
|
|
||||||
|
|
||||||
const logDesc = useMemo(() => {
|
const logDesc = useMemo(() => {
|
||||||
if (!metadata) {
|
if (!metadata) {
|
||||||
|
|
Loading…
Reference in New Issue