Use ResolvedAddresses table instead of pre-resolved name parameter

This commit is contained in:
Willian Mitsuda 2021-10-30 21:31:31 -03:00
parent 9da41d0a2e
commit a0675c6377
5 changed files with 48 additions and 49 deletions

View File

@ -165,7 +165,7 @@ const AddressTransactions: React.FC = () => {
}, [provider, checksummedAddress, params.direction, hash, controller]); }, [provider, checksummedAddress, params.direction, hash, controller]);
const page = useMemo(() => controller?.getPage(), [controller]); const page = useMemo(() => controller?.getPage(), [controller]);
const reverseCache = useENSCache(provider, page); const resolvedAddresses = useENSCache(provider, page);
const blockTags: BlockTag[] = useMemo(() => { const blockTags: BlockTag[] = useMemo(() => {
if (!page) { if (!page) {
@ -283,7 +283,7 @@ const AddressTransactions: React.FC = () => {
<TransactionItem <TransactionItem
key={tx.hash} key={tx.hash}
tx={tx} tx={tx}
ensCache={reverseCache} resolvedAddresses={resolvedAddresses}
selectedAddress={checksummedAddress} selectedAddress={checksummedAddress}
feeDisplay={feeDisplay} feeDisplay={feeDisplay}
priceMap={priceMap} priceMap={priceMap}

View File

@ -29,7 +29,7 @@ const BlockTransactionResults: React.FC<BlockTransactionResultsProps> = ({
const selectionCtx = useSelection(); const selectionCtx = useSelection();
const [feeDisplay, feeDisplayToggler] = useFeeToggler(); const [feeDisplay, feeDisplayToggler] = useFeeToggler();
const { provider } = useContext(RuntimeContext); const { provider } = useContext(RuntimeContext);
const reverseCache = useENSCache(provider, page); const resolvedAddresses = useENSCache(provider, page);
const blockTags = useMemo(() => [blockTag], [blockTag]); const blockTags = useMemo(() => [blockTag], [blockTag]);
const priceMap = useMultipleETHUSDOracle(provider, blockTags); const priceMap = useMultipleETHUSDOracle(provider, blockTags);
@ -59,7 +59,7 @@ const BlockTransactionResults: React.FC<BlockTransactionResultsProps> = ({
<TransactionItem <TransactionItem
key={tx.hash} key={tx.hash}
tx={tx} tx={tx}
ensCache={reverseCache} resolvedAddresses={resolvedAddresses}
feeDisplay={feeDisplay} feeDisplay={feeDisplay}
priceMap={priceMap} priceMap={priceMap}
/> />

View File

@ -3,49 +3,53 @@ import Address from "./Address";
import AddressLink from "./AddressLink"; import AddressLink from "./AddressLink";
import ENSName from "./ENSName"; import ENSName from "./ENSName";
import ENSNameLink from "./ENSNameLink"; import ENSNameLink from "./ENSNameLink";
import { ResolvedAddresses } from "../api/address-resolver";
type AddressOrENSNameProps = { type AddressOrENSNameProps = {
address: string; address: string;
ensName?: string;
selectedAddress?: string; selectedAddress?: string;
text?: string; text?: string;
dontOverrideColors?: boolean; dontOverrideColors?: boolean;
resolvedAddresses?: ResolvedAddresses | undefined;
}; };
const AddressOrENSName: React.FC<AddressOrENSNameProps> = ({ const AddressOrENSName: React.FC<AddressOrENSNameProps> = ({
address, address,
ensName,
selectedAddress, selectedAddress,
text, text,
dontOverrideColors, dontOverrideColors,
}) => ( resolvedAddresses,
<> }) => {
{address === selectedAddress ? ( const name = resolvedAddresses?.[address];
<> return (
{ensName ? ( <>
<ENSName name={ensName} address={address} /> {address === selectedAddress ? (
) : ( <>
<Address address={address} /> {name ? (
)} <ENSName name={name} address={address} />
</> ) : (
) : ( <Address address={address} />
<> )}
{ensName ? ( </>
<ENSNameLink ) : (
name={ensName} <>
address={address} {name ? (
dontOverrideColors={dontOverrideColors} <ENSNameLink
/> name={name}
) : ( address={address}
<AddressLink dontOverrideColors={dontOverrideColors}
address={address} />
text={text} ) : (
dontOverrideColors={dontOverrideColors} <AddressLink
/> address={address}
)} text={text}
</> dontOverrideColors={dontOverrideColors}
)} />
</> )}
); </>
)}
</>
);
};
export default React.memo(AddressOrENSName); export default React.memo(AddressOrENSName);

View File

@ -8,10 +8,10 @@ import { faCoins } from "@fortawesome/free-solid-svg-icons/faCoins";
import TokenLogo from "./TokenLogo"; import TokenLogo from "./TokenLogo";
import AddressOrENSName from "./AddressOrENSName"; import AddressOrENSName from "./AddressOrENSName";
import { AddressContext, TokenMeta, ZERO_ADDRESS } from "../types"; import { AddressContext, TokenMeta, ZERO_ADDRESS } from "../types";
import { ResolvedAddresses } from "../api/address-resolver";
type DecoratedAddressLinkProps = { type DecoratedAddressLinkProps = {
address: string; address: string;
ensName?: string;
selectedAddress?: string; selectedAddress?: string;
text?: string; text?: string;
addressCtx?: AddressContext; addressCtx?: AddressContext;
@ -21,11 +21,11 @@ type DecoratedAddressLinkProps = {
txFrom?: boolean; txFrom?: boolean;
txTo?: boolean; txTo?: boolean;
tokenMeta?: TokenMeta; tokenMeta?: TokenMeta;
resolvedAddresses?: ResolvedAddresses | undefined;
}; };
const DecoratedAddressLink: React.FC<DecoratedAddressLinkProps> = ({ const DecoratedAddressLink: React.FC<DecoratedAddressLinkProps> = ({
address, address,
ensName,
selectedAddress, selectedAddress,
text, text,
addressCtx, addressCtx,
@ -35,6 +35,7 @@ const DecoratedAddressLink: React.FC<DecoratedAddressLinkProps> = ({
txFrom, txFrom,
txTo, txTo,
tokenMeta, tokenMeta,
resolvedAddresses,
}) => { }) => {
const mint = addressCtx === AddressContext.FROM && address === ZERO_ADDRESS; const mint = addressCtx === AddressContext.FROM && address === ZERO_ADDRESS;
const burn = addressCtx === AddressContext.TO && address === ZERO_ADDRESS; const burn = addressCtx === AddressContext.TO && address === ZERO_ADDRESS;
@ -81,10 +82,10 @@ const DecoratedAddressLink: React.FC<DecoratedAddressLinkProps> = ({
)} )}
<AddressOrENSName <AddressOrENSName
address={address} address={address}
ensName={ensName}
selectedAddress={selectedAddress} selectedAddress={selectedAddress}
text={text} text={text}
dontOverrideColors={mint || burn} dontOverrideColors={mint || burn}
resolvedAddresses={resolvedAddresses}
/> />
</div> </div>
); );

View File

@ -22,7 +22,7 @@ import { ResolvedAddresses } from "../api/address-resolver";
type TransactionItemProps = { type TransactionItemProps = {
tx: ProcessedTransaction; tx: ProcessedTransaction;
ensCache?: ResolvedAddresses; resolvedAddresses?: ResolvedAddresses;
selectedAddress?: string; selectedAddress?: string;
feeDisplay: FeeDisplay; feeDisplay: FeeDisplay;
priceMap: Record<BlockTag, BigNumber>; priceMap: Record<BlockTag, BigNumber>;
@ -30,7 +30,7 @@ type TransactionItemProps = {
const TransactionItem: React.FC<TransactionItemProps> = ({ const TransactionItem: React.FC<TransactionItemProps> = ({
tx, tx,
ensCache, resolvedAddresses,
selectedAddress, selectedAddress,
feeDisplay, feeDisplay,
priceMap, priceMap,
@ -51,12 +51,6 @@ const TransactionItem: React.FC<TransactionItemProps> = ({
} }
} }
const ensFrom = ensCache && tx.from && ensCache[tx.from];
const ensTo = ensCache && tx.to && ensCache[tx.to];
const ensCreated =
ensCache &&
tx.createdContractAddress &&
ensCache[tx.createdContractAddress];
const flash = tx.gasPrice.isZero() && tx.internalMinerInteraction; const flash = tx.gasPrice.isZero() && tx.internalMinerInteraction;
return ( return (
@ -88,9 +82,9 @@ const TransactionItem: React.FC<TransactionItemProps> = ({
<AddressHighlighter address={tx.from}> <AddressHighlighter address={tx.from}>
<DecoratedAddressLink <DecoratedAddressLink
address={tx.from} address={tx.from}
ensName={ensFrom}
selectedAddress={selectedAddress} selectedAddress={selectedAddress}
miner={tx.miner === tx.from} miner={tx.miner === tx.from}
resolvedAddresses={resolvedAddresses}
/> />
</AddressHighlighter> </AddressHighlighter>
)} )}
@ -108,18 +102,18 @@ const TransactionItem: React.FC<TransactionItemProps> = ({
<AddressHighlighter address={tx.to}> <AddressHighlighter address={tx.to}>
<DecoratedAddressLink <DecoratedAddressLink
address={tx.to} address={tx.to}
ensName={ensTo}
selectedAddress={selectedAddress} selectedAddress={selectedAddress}
miner={tx.miner === tx.to} miner={tx.miner === tx.to}
resolvedAddresses={resolvedAddresses}
/> />
</AddressHighlighter> </AddressHighlighter>
) : ( ) : (
<AddressHighlighter address={tx.createdContractAddress!}> <AddressHighlighter address={tx.createdContractAddress!}>
<DecoratedAddressLink <DecoratedAddressLink
address={tx.createdContractAddress!} address={tx.createdContractAddress!}
ensName={ensCreated}
selectedAddress={selectedAddress} selectedAddress={selectedAddress}
creation creation
resolvedAddresses={resolvedAddresses}
/> />
</AddressHighlighter> </AddressHighlighter>
)} )}