otterscan/src/components/AddressOrENSName.tsx

52 lines
1.1 KiB
TypeScript
Raw Normal View History

import React from "react";
import { ensResolver, ResolvedAddresses } from "../api/address-resolver";
import PlainAddress from "./PlainAddress";
import ENSName from "./ENSName";
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;
if (resolver === ensResolver) {
return (
<ENSName
address={address}
text={text}
linkable={linkable}
name={resolvedName}
dontOverrideColors={dontOverrideColors}
/>
);
}
return <></>;
};
2021-10-31 01:05:26 +00:00
export default AddressOrENSName;