import React, { useContext } from "react"; import { resolverRendererRegistry } from "../api/address-resolver"; import { useResolvedAddress } from "../useResolvedAddresses"; import { RuntimeContext } from "../useRuntime"; import PlainAddress from "./PlainAddress"; type AddressOrENSNameProps = { address: string; selectedAddress?: string; dontOverrideColors?: boolean; }; const AddressOrENSName: React.FC = ({ address, selectedAddress, dontOverrideColors, }) => { const { provider } = useContext(RuntimeContext); const resolvedAddress = useResolvedAddress(provider, address); const linkable = address !== selectedAddress; if (!resolvedAddress) { return ( ); } const [resolver, resolvedName] = resolvedAddress; const renderer = resolverRendererRegistry.get(resolver); if (renderer === undefined) { return ( ); } return renderer(address, resolvedName, linkable, !!dontOverrideColors); }; export default AddressOrENSName;