otterscan/src/components/AddressOrENSName.tsx

48 lines
1.2 KiB
TypeScript
Raw Normal View History

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<AddressOrENSNameProps> = ({
address,
selectedAddress,
dontOverrideColors,
}) => {
const { provider } = useContext(RuntimeContext);
const resolvedAddress = useResolvedAddress(provider, address);
const linkable = address !== selectedAddress;
if (!resolvedAddress) {
return (
<PlainAddress
address={address}
linkable={linkable}
dontOverrideColors={dontOverrideColors}
/>
);
}
const [resolver, resolvedName] = resolvedAddress;
2021-10-31 08:10:42 +00:00
const renderer = resolverRendererRegistry.get(resolver);
if (renderer === undefined) {
return (
2021-10-31 08:10:42 +00:00
<PlainAddress
address={address}
linkable={linkable}
dontOverrideColors={dontOverrideColors}
/>
);
}
2021-10-31 08:10:42 +00:00
return renderer(address, resolvedName, linkable, !!dontOverrideColors);
};
2021-10-31 01:05:26 +00:00
export default AddressOrENSName;