Add merged trace address resolution

This commit is contained in:
Willian Mitsuda 2021-11-01 17:40:38 -03:00
parent c4615e47bf
commit bc1d6f35b8
1 changed files with 17 additions and 3 deletions

View File

@ -1,4 +1,4 @@
import React, { useContext } from "react"; import React, { useContext, useMemo } from "react";
import AddressHighlighter from "../components/AddressHighlighter"; import AddressHighlighter from "../components/AddressHighlighter";
import DecoratedAddressLink from "../components/DecoratedAddressLink"; import DecoratedAddressLink from "../components/DecoratedAddressLink";
import ContentFrame from "../ContentFrame"; import ContentFrame from "../ContentFrame";
@ -8,6 +8,7 @@ import { useBatch4Bytes } from "../use4Bytes";
import { useTraceTransaction, useUniqueSignatures } from "../useErigonHooks"; import { useTraceTransaction, useUniqueSignatures } from "../useErigonHooks";
import { RuntimeContext } from "../useRuntime"; import { RuntimeContext } from "../useRuntime";
import { ResolvedAddresses } from "../api/address-resolver"; import { ResolvedAddresses } from "../api/address-resolver";
import { tracesCollector, useResolvedAddresses } from "../useResolvedAddresses";
type TraceProps = { type TraceProps = {
txData: TransactionData; txData: TransactionData;
@ -20,6 +21,19 @@ const Trace: React.FC<TraceProps> = ({ txData, resolvedAddresses }) => {
const uniqueSignatures = useUniqueSignatures(traces); const uniqueSignatures = useUniqueSignatures(traces);
const sigMap = useBatch4Bytes(uniqueSignatures); const sigMap = useBatch4Bytes(uniqueSignatures);
const addrCollector = useMemo(() => tracesCollector(traces), [traces]);
const traceResolvedAddresses = useResolvedAddresses(provider, addrCollector);
const mergedResolvedAddresses = useMemo(() => {
const merge = {};
if (resolvedAddresses) {
Object.assign(merge, resolvedAddresses);
}
if (traceResolvedAddresses) {
Object.assign(merge, traceResolvedAddresses);
}
return merge;
}, [resolvedAddresses, traceResolvedAddresses]);
return ( return (
<ContentFrame tabs> <ContentFrame tabs>
<div className="mt-4 mb-5 space-y-3 font-code text-sm flex flex-col items-start overflow-x-auto"> <div className="mt-4 mb-5 space-y-3 font-code text-sm flex flex-col items-start overflow-x-auto">
@ -30,7 +44,7 @@ const Trace: React.FC<TraceProps> = ({ txData, resolvedAddresses }) => {
miner={txData.from === txData.confirmedData?.miner} miner={txData.from === txData.confirmedData?.miner}
txFrom txFrom
txTo={txData.from === txData.to} txTo={txData.from === txData.to}
resolvedAddresses={resolvedAddresses} resolvedAddresses={mergedResolvedAddresses}
/> />
</AddressHighlighter> </AddressHighlighter>
</div> </div>
@ -44,7 +58,7 @@ const Trace: React.FC<TraceProps> = ({ txData, resolvedAddresses }) => {
txData={txData} txData={txData}
last={i === a.length - 1} last={i === a.length - 1}
fourBytesMap={sigMap} fourBytesMap={sigMap}
resolvedAddresses={resolvedAddresses} resolvedAddresses={mergedResolvedAddresses}
/> />
))} ))}
</div> </div>