2021-07-03 00:40:02 +00:00
|
|
|
import React from "react";
|
|
|
|
import Address from "./Address";
|
|
|
|
import AddressLink from "./AddressLink";
|
|
|
|
import ENSName from "./ENSName";
|
|
|
|
import ENSNameLink from "./ENSNameLink";
|
2021-10-31 05:38:41 +00:00
|
|
|
import { ensResolver, ResolvedAddresses } from "../api/address-resolver";
|
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,
|
|
|
|
}) => {
|
|
|
|
const name = resolvedAddresses?.[address];
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{address === selectedAddress ? (
|
|
|
|
<>
|
2021-10-31 05:38:41 +00:00
|
|
|
{name?.[0] === ensResolver ? (
|
|
|
|
<ENSName name={name[1]} address={address} />
|
2021-10-31 00:31:31 +00:00
|
|
|
) : (
|
|
|
|
<Address address={address} />
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<>
|
2021-10-31 05:38:41 +00:00
|
|
|
{name?.[0] ? (
|
2021-10-31 00:31:31 +00:00
|
|
|
<ENSNameLink
|
2021-10-31 05:38:41 +00:00
|
|
|
name={name[1]}
|
2021-10-31 00:31:31 +00:00
|
|
|
address={address}
|
|
|
|
dontOverrideColors={dontOverrideColors}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<AddressLink
|
|
|
|
address={address}
|
|
|
|
text={text}
|
|
|
|
dontOverrideColors={dontOverrideColors}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
2021-07-03 00:40:02 +00:00
|
|
|
|
2021-10-31 01:05:26 +00:00
|
|
|
export default AddressOrENSName;
|