2021-07-03 00:40:02 +00:00
|
|
|
import React from "react";
|
2021-10-31 08:10:42 +00:00
|
|
|
import {
|
|
|
|
ResolvedAddresses,
|
|
|
|
resolverRendererRegistry,
|
|
|
|
} from "../api/address-resolver";
|
2021-10-31 06:16:03 +00:00
|
|
|
import PlainAddress from "./PlainAddress";
|
2021-07-03 00:40:02 +00:00
|
|
|
|
|
|
|
type AddressOrENSNameProps = {
|
|
|
|
address: string;
|
|
|
|
selectedAddress?: string;
|
2021-07-19 03:38:38 +00:00
|
|
|
text?: string;
|
2021-07-19 03:50:32 +00:00
|
|
|
dontOverrideColors?: boolean;
|
2021-10-31 00:31:31 +00:00
|
|
|
resolvedAddresses?: ResolvedAddresses | undefined;
|
2021-07-03 00:40:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const AddressOrENSName: React.FC<AddressOrENSNameProps> = ({
|
|
|
|
address,
|
|
|
|
selectedAddress,
|
2021-07-19 03:38:38 +00:00
|
|
|
text,
|
2021-07-19 03:50:32 +00:00
|
|
|
dontOverrideColors,
|
2021-10-31 00:31:31 +00:00
|
|
|
resolvedAddresses,
|
|
|
|
}) => {
|
2021-10-31 06:16:03 +00:00
|
|
|
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) {
|
2021-10-31 06:16:03 +00:00
|
|
|
return (
|
2021-10-31 08:10:42 +00:00
|
|
|
<PlainAddress
|
2021-10-31 06:16:03 +00:00
|
|
|
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 00:31:31 +00:00
|
|
|
};
|
2021-07-03 00:40:02 +00:00
|
|
|
|
2021-10-31 01:05:26 +00:00
|
|
|
export default AddressOrENSName;
|