otterscan/src/components/AddressOrENSName.tsx

54 lines
1.2 KiB
TypeScript
Raw Normal View History

import React from "react";
2021-10-31 08:10:42 +00:00
import {
ResolvedAddresses,
resolverRendererRegistry,
} from "../api/address-resolver";
import PlainAddress from "./PlainAddress";
type AddressOrENSNameProps = {
address: string;
selectedAddress?: string;
text?: string;
dontOverrideColors?: boolean;
resolvedAddresses?: ResolvedAddresses | undefined;
};
const AddressOrENSName: React.FC<AddressOrENSNameProps> = ({
address,
selectedAddress,
text,
dontOverrideColors,
resolvedAddresses,
}) => {
const resolvedAddress = resolvedAddresses?.[address];
const linkable = address !== selectedAddress;
if (resolvedAddress === undefined) {
return (
<PlainAddress
address={address}
text={text}
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}
text={text}
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;