import React, { PropsWithChildren, useContext } from "react"; import { NavLink } from "react-router-dom"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faStar } from "@fortawesome/free-solid-svg-icons/faStar"; import { faBomb } from "@fortawesome/free-solid-svg-icons/faBomb"; import { faMoneyBillAlt } from "@fortawesome/free-solid-svg-icons/faMoneyBillAlt"; import { faBurn } from "@fortawesome/free-solid-svg-icons/faBurn"; import { faCoins } from "@fortawesome/free-solid-svg-icons/faCoins"; import SourcifyLogo from "../sourcify/SourcifyLogo"; import PlainAddress from "./PlainAddress"; import { Metadata } from "../sourcify/useSourcify"; import { RuntimeContext } from "../useRuntime"; import { useResolvedAddress } from "../useResolvedAddresses"; import { AddressContext, ChecksummedAddress, ZERO_ADDRESS } from "../types"; import { resolverRendererRegistry } from "../api/address-resolver"; type DecoratedAddressLinkProps = { address: ChecksummedAddress; selectedAddress?: ChecksummedAddress | undefined; addressCtx?: AddressContext | undefined; creation?: boolean | undefined; miner?: boolean | undefined; selfDestruct?: boolean | undefined; txFrom?: boolean | undefined; txTo?: boolean | undefined; metadata?: Metadata | null | undefined; eoa?: boolean | undefined; }; const DecoratedAddressLink: React.FC = ({ address, selectedAddress, addressCtx, creation, miner, selfDestruct, txFrom, txTo, metadata, eoa, }) => { const mint = addressCtx === AddressContext.FROM && address === ZERO_ADDRESS; const burn = addressCtx === AddressContext.TO && address === ZERO_ADDRESS; return (
{creation && ( )} {selfDestruct && ( )} {mint && ( )} {burn && ( )} {miner && ( )} {metadata && ( )} {!mint && !burn && ( <> {eoa === true && ( [EOA] )} {eoa === false && ( [C] )} )}
); }; type ResolvedAddressProps = { address: ChecksummedAddress; selectedAddress?: ChecksummedAddress | undefined; dontOverrideColors?: boolean; }; const ResolvedAddress: React.FC = ({ address, selectedAddress, dontOverrideColors, }) => { const { provider } = useContext(RuntimeContext); const resolvedAddress = useResolvedAddress(provider, address); const linkable = address !== selectedAddress; if (!provider || !resolvedAddress) { return ( ); } const [resolver, resolvedName] = resolvedAddress; const renderer = resolverRendererRegistry.get(resolver); if (renderer === undefined) { return ( ); } return renderer( provider.network.chainId, address, resolvedName, linkable, !!dontOverrideColors ); }; type AddressLegendProps = { title: string; }; const AddressLegend: React.FC> = ({ title, children, }) => ( {children} ); export default React.memo(DecoratedAddressLink);