From dca72a13b47c39ce58bbb76aaa3f59eb408e0304 Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Wed, 10 Nov 2021 05:45:46 -0300 Subject: [PATCH] Add Sourcify decoration support to AddressTransactions page --- src/AddressTransactions.tsx | 17 ++++++++++++++++- src/components/DecoratedAddressLink.tsx | 15 +++++++++++++++ src/search/TransactionItem.tsx | 9 ++++++++- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/AddressTransactions.tsx b/src/AddressTransactions.tsx index 69ebad2..a1013c8 100644 --- a/src/AddressTransactions.tsx +++ b/src/AddressTransactions.tsx @@ -32,6 +32,7 @@ import { SelectionContext, useSelection } from "./useSelection"; import { useMultipleETHUSDOracle } from "./usePriceOracle"; import { useAppConfigContext } from "./useAppConfig"; import { useMultipleMetadata } from "./useSourcify"; +import { ChecksummedAddress } from "./types"; import SourcifyLogo from "./sourcify.svg"; type BlockParams = { @@ -181,7 +182,20 @@ const AddressTransactions: React.FC = () => { const [feeDisplay, feeDisplayToggler] = useFeeToggler(); const selectionCtx = useSelection(); - const addresses = useMemo(() => [checksummedAddress], [checksummedAddress]); + const addresses = useMemo(() => { + const _addresses: ChecksummedAddress[] = []; + if (checksummedAddress) { + _addresses.push(checksummedAddress); + } + if (page) { + for (const t of page) { + if (t.to) { + _addresses.push(t.to); + } + } + } + return _addresses; + }, [checksummedAddress, page]); const { sourcifySource } = useAppConfigContext(); const metadatas = useMultipleMetadata( undefined, @@ -294,6 +308,7 @@ const AddressTransactions: React.FC = () => { selectedAddress={checksummedAddress} feeDisplay={feeDisplay} priceMap={priceMap} + metadatas={metadatas} /> ))}
diff --git a/src/components/DecoratedAddressLink.tsx b/src/components/DecoratedAddressLink.tsx index cadc77f..087da7f 100644 --- a/src/components/DecoratedAddressLink.tsx +++ b/src/components/DecoratedAddressLink.tsx @@ -8,6 +8,8 @@ import { faCoins } from "@fortawesome/free-solid-svg-icons/faCoins"; import AddressOrENSName from "./AddressOrENSName"; import { AddressContext, ZERO_ADDRESS } from "../types"; import { ResolvedAddresses } from "../api/address-resolver"; +import { Metadata } from "../useSourcify"; +import SourcifyLogo from "../sourcify.svg"; type DecoratedAddressLinkProps = { address: string; @@ -19,6 +21,7 @@ type DecoratedAddressLinkProps = { txFrom?: boolean; txTo?: boolean; resolvedAddresses?: ResolvedAddresses | undefined; + metadata?: Metadata | null | undefined; }; const DecoratedAddressLink: React.FC = ({ @@ -31,6 +34,7 @@ const DecoratedAddressLink: React.FC = ({ txFrom, txTo, resolvedAddresses, + metadata, }) => { const mint = addressCtx === AddressContext.FROM && address === ZERO_ADDRESS; const burn = addressCtx === AddressContext.TO && address === ZERO_ADDRESS; @@ -70,6 +74,17 @@ const DecoratedAddressLink: React.FC = ({ )} + {metadata && ( + + Sourcify logo + + )} ; + metadatas?: + | Record + | undefined; }; const TransactionItem: React.FC = ({ @@ -34,6 +38,7 @@ const TransactionItem: React.FC = ({ selectedAddress, feeDisplay, priceMap, + metadatas, }) => { let direction: Direction | undefined; if (selectedAddress) { @@ -105,6 +110,7 @@ const TransactionItem: React.FC = ({ selectedAddress={selectedAddress} miner={tx.miner === tx.to} resolvedAddresses={resolvedAddresses} + metadata={metadatas?.[tx.to]} /> ) : ( @@ -114,6 +120,7 @@ const TransactionItem: React.FC = ({ selectedAddress={selectedAddress} creation resolvedAddresses={resolvedAddresses} + metadata={metadatas?.[tx.createdContractAddress!]} /> )}