From b985eb6d756a30bc777a076bcc5091dbb17ccf6b Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Sun, 27 Feb 2022 13:39:25 -0300 Subject: [PATCH] Flatten DecoratedAddressLink component --- src/components/AddressOrENSName.tsx | 54 ---------------------- src/components/DecoratedAddressLink.tsx | 61 ++++++++++++++++++++++--- 2 files changed, 55 insertions(+), 60 deletions(-) delete mode 100644 src/components/AddressOrENSName.tsx diff --git a/src/components/AddressOrENSName.tsx b/src/components/AddressOrENSName.tsx deleted file mode 100644 index bacdea8..0000000 --- a/src/components/AddressOrENSName.tsx +++ /dev/null @@ -1,54 +0,0 @@ -import React, { useContext } from "react"; -import PlainAddress from "./PlainAddress"; -import { resolverRendererRegistry } from "../api/address-resolver"; -import { useResolvedAddress } from "../useResolvedAddresses"; -import { RuntimeContext } from "../useRuntime"; -import { ChecksummedAddress } from "../types"; - -type AddressOrENSNameProps = { - address: ChecksummedAddress; - selectedAddress?: string; - dontOverrideColors?: boolean; -}; - -const AddressOrENSName: React.FC = ({ - address, - selectedAddress, - dontOverrideColors, -}) => { - const { provider } = useContext(RuntimeContext); - const resolvedAddress = useResolvedAddress(provider, address); - const linkable = address !== selectedAddress; - - if (!provider || !resolvedAddress) { - return ( - - ); - } - - const [resolver, resolvedName] = resolvedAddress; - const renderer = resolverRendererRegistry.get(resolver); - if (renderer === undefined) { - return ( - - ); - } - - return renderer( - provider.network.chainId, - address, - resolvedName, - linkable, - !!dontOverrideColors - ); -}; - -export default AddressOrENSName; diff --git a/src/components/DecoratedAddressLink.tsx b/src/components/DecoratedAddressLink.tsx index fd3709d..331beb5 100644 --- a/src/components/DecoratedAddressLink.tsx +++ b/src/components/DecoratedAddressLink.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useContext } from "react"; import { NavLink } from "react-router-dom"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faStar } from "@fortawesome/free-solid-svg-icons/faStar"; @@ -6,14 +6,17 @@ import { faBomb } from "@fortawesome/free-solid-svg-icons/faBomb"; import { faMoneyBillAlt } from "@fortawesome/free-solid-svg-icons/faMoneyBillAlt"; import { faBurn } from "@fortawesome/free-solid-svg-icons/faBurn"; import { faCoins } from "@fortawesome/free-solid-svg-icons/faCoins"; -import AddressOrENSName from "./AddressOrENSName"; import SourcifyLogo from "../sourcify/SourcifyLogo"; -import { AddressContext, ZERO_ADDRESS } from "../types"; +import PlainAddress from "./PlainAddress"; import { Metadata } from "../sourcify/useSourcify"; +import { RuntimeContext } from "../useRuntime"; +import { useResolvedAddress } from "../useResolvedAddresses"; +import { AddressContext, ChecksummedAddress, ZERO_ADDRESS } from "../types"; +import { resolverRendererRegistry } from "../api/address-resolver"; type DecoratedAddressLinkProps = { - address: string; - selectedAddress?: string | undefined; + address: ChecksummedAddress; + selectedAddress?: ChecksummedAddress | undefined; addressCtx?: AddressContext | undefined; creation?: boolean | undefined; miner?: boolean | undefined; @@ -80,7 +83,7 @@ const DecoratedAddressLink: React.FC = ({ )} - = ({ ); }; +type ResolvedAddressProps = { + address: ChecksummedAddress; + selectedAddress?: ChecksummedAddress | undefined; + dontOverrideColors?: boolean; +}; + +const ResolvedAddress: React.FC = ({ + address, + selectedAddress, + dontOverrideColors, +}) => { + const { provider } = useContext(RuntimeContext); + const resolvedAddress = useResolvedAddress(provider, address); + const linkable = address !== selectedAddress; + + if (!provider || !resolvedAddress) { + return ( + + ); + } + + const [resolver, resolvedName] = resolvedAddress; + const renderer = resolverRendererRegistry.get(resolver); + if (renderer === undefined) { + return ( + + ); + } + + return renderer( + provider.network.chainId, + address, + resolvedName, + linkable, + !!dontOverrideColors + ); +}; + export default React.memo(DecoratedAddressLink);