2021-07-03 00:40:02 +00:00
|
|
|
import React from "react";
|
2021-10-31 05:38:41 +00:00
|
|
|
import { ensResolver, ResolvedAddresses } from "../api/address-resolver";
|
2021-10-31 06:16:03 +00:00
|
|
|
import PlainAddress from "./PlainAddress";
|
|
|
|
import ENSName from "./ENSName";
|
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;
|
|
|
|
if (resolver === ensResolver) {
|
|
|
|
return (
|
|
|
|
<ENSName
|
|
|
|
address={address}
|
|
|
|
text={text}
|
|
|
|
linkable={linkable}
|
|
|
|
name={resolvedName}
|
|
|
|
dontOverrideColors={dontOverrideColors}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return <></>;
|
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;
|