2021-08-01 09:59:59 +00:00
|
|
|
import React, { useMemo, useContext } from "react";
|
2021-11-25 09:28:45 +00:00
|
|
|
import { useParams, Routes, Route } from "react-router-dom";
|
2021-09-06 06:43:20 +00:00
|
|
|
import { Tab } from "@headlessui/react";
|
2021-07-01 18:21:40 +00:00
|
|
|
import StandardFrame from "./StandardFrame";
|
|
|
|
import StandardSubtitle from "./StandardSubtitle";
|
2021-09-04 06:19:42 +00:00
|
|
|
import ContentFrame from "./ContentFrame";
|
2021-09-06 06:34:13 +00:00
|
|
|
import NavTab from "./components/NavTab";
|
2021-07-09 05:07:20 +00:00
|
|
|
import { RuntimeContext } from "./useRuntime";
|
2021-07-14 07:43:58 +00:00
|
|
|
import { SelectionContext, useSelection } from "./useSelection";
|
2021-08-01 09:59:59 +00:00
|
|
|
import { useInternalOperations, useTxData } from "./useErigonHooks";
|
2021-08-31 05:56:05 +00:00
|
|
|
import { useETHUSDOracle } from "./usePriceOracle";
|
2021-09-23 21:25:52 +00:00
|
|
|
import { useAppConfigContext } from "./useAppConfig";
|
2021-11-25 18:50:59 +00:00
|
|
|
import { useSourcify, useTransactionDescription } from "./sourcify/useSourcify";
|
2021-10-31 01:44:33 +00:00
|
|
|
import {
|
|
|
|
transactionDataCollector,
|
|
|
|
useResolvedAddresses,
|
|
|
|
} from "./useResolvedAddresses";
|
2021-11-07 11:21:56 +00:00
|
|
|
import { SelectedTransactionContext } from "./useSelectedTransaction";
|
2021-07-01 18:21:40 +00:00
|
|
|
|
2021-10-24 04:04:18 +00:00
|
|
|
const Details = React.lazy(
|
|
|
|
() =>
|
|
|
|
import(
|
|
|
|
/* webpackChunkName: "txdetails", webpackPrefetch: true */
|
|
|
|
"./transaction/Details"
|
|
|
|
)
|
|
|
|
);
|
|
|
|
const Logs = React.lazy(
|
|
|
|
() =>
|
|
|
|
import(
|
|
|
|
/* webpackChunkName: "txlogs", webpackPrefetch: true */ "./transaction/Logs"
|
|
|
|
)
|
|
|
|
);
|
2021-10-27 01:10:37 +00:00
|
|
|
const Trace = React.lazy(
|
|
|
|
() =>
|
|
|
|
import(
|
|
|
|
/* webpackChunkName: "txtrace", webpackPrefetch: true */ "./transaction/Trace"
|
|
|
|
)
|
|
|
|
);
|
2021-10-24 04:04:18 +00:00
|
|
|
|
2021-07-01 18:21:40 +00:00
|
|
|
const Transaction: React.FC = () => {
|
2021-07-09 05:07:20 +00:00
|
|
|
const { provider } = useContext(RuntimeContext);
|
2021-11-25 09:28:45 +00:00
|
|
|
const { txhash } = useParams();
|
|
|
|
if (txhash === undefined) {
|
|
|
|
throw new Error("txhash couldn't be undefined here");
|
|
|
|
}
|
2021-07-01 18:21:40 +00:00
|
|
|
|
2021-08-01 09:59:59 +00:00
|
|
|
const txData = useTxData(provider, txhash);
|
2021-10-31 01:44:33 +00:00
|
|
|
const addrCollector = useMemo(
|
|
|
|
() => transactionDataCollector(txData),
|
|
|
|
[txData]
|
|
|
|
);
|
|
|
|
const resolvedAddresses = useResolvedAddresses(provider, addrCollector);
|
2021-07-01 18:21:40 +00:00
|
|
|
|
2021-07-21 19:06:51 +00:00
|
|
|
const internalOps = useInternalOperations(provider, txData);
|
2021-07-05 21:08:52 +00:00
|
|
|
const sendsEthToMiner = useMemo(() => {
|
2021-07-21 19:06:51 +00:00
|
|
|
if (!txData || !internalOps) {
|
2021-07-05 21:08:52 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-07-21 19:06:51 +00:00
|
|
|
for (const t of internalOps) {
|
2021-09-04 06:19:42 +00:00
|
|
|
if (t.to === txData.confirmedData?.miner) {
|
2021-07-05 21:08:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2021-07-21 19:06:51 +00:00
|
|
|
}, [txData, internalOps]);
|
2021-07-01 18:21:40 +00:00
|
|
|
|
2021-07-14 07:43:58 +00:00
|
|
|
const selectionCtx = useSelection();
|
|
|
|
|
2021-09-04 06:19:42 +00:00
|
|
|
const blockETHUSDPrice = useETHUSDOracle(
|
|
|
|
provider,
|
|
|
|
txData?.confirmedData?.blockNumber
|
|
|
|
);
|
2021-08-31 05:56:05 +00:00
|
|
|
|
2021-09-23 21:25:52 +00:00
|
|
|
const { sourcifySource } = useAppConfigContext();
|
2021-09-15 17:43:36 +00:00
|
|
|
const metadata = useSourcify(
|
|
|
|
txData?.to,
|
|
|
|
provider?.network.chainId,
|
2021-09-23 21:25:52 +00:00
|
|
|
sourcifySource
|
2021-09-15 17:43:36 +00:00
|
|
|
);
|
|
|
|
const txDesc = useTransactionDescription(metadata, txData);
|
|
|
|
|
2021-07-01 18:21:40 +00:00
|
|
|
return (
|
2021-11-07 11:21:56 +00:00
|
|
|
<SelectedTransactionContext.Provider value={txData}>
|
|
|
|
<StandardFrame>
|
|
|
|
<StandardSubtitle>Transaction Details</StandardSubtitle>
|
|
|
|
{txData === null && (
|
|
|
|
<ContentFrame>
|
|
|
|
<div className="py-4 text-sm">
|
|
|
|
Transaction <span className="font-hash">{txhash}</span> not found.
|
|
|
|
</div>
|
|
|
|
</ContentFrame>
|
|
|
|
)}
|
|
|
|
{txData && (
|
|
|
|
<SelectionContext.Provider value={selectionCtx}>
|
|
|
|
<Tab.Group>
|
|
|
|
<Tab.List className="flex space-x-2 border-l border-r border-t rounded-t-lg bg-white">
|
2021-11-25 09:28:45 +00:00
|
|
|
<NavTab href=".">Overview</NavTab>
|
2021-11-07 11:21:56 +00:00
|
|
|
{txData.confirmedData?.blockNumber !== undefined && (
|
2021-11-25 09:28:45 +00:00
|
|
|
<NavTab href="logs">
|
2021-11-07 11:21:56 +00:00
|
|
|
Logs
|
|
|
|
{txData && ` (${txData.confirmedData?.logs?.length ?? 0})`}
|
|
|
|
</NavTab>
|
|
|
|
)}
|
2021-11-25 09:28:45 +00:00
|
|
|
<NavTab href="trace">Trace</NavTab>
|
2021-11-07 11:21:56 +00:00
|
|
|
</Tab.List>
|
|
|
|
</Tab.Group>
|
|
|
|
<React.Suspense fallback={null}>
|
2021-11-25 09:28:45 +00:00
|
|
|
<Routes>
|
|
|
|
<Route
|
|
|
|
index
|
|
|
|
element={
|
|
|
|
<Details
|
|
|
|
txData={txData}
|
|
|
|
txDesc={txDesc}
|
|
|
|
userDoc={metadata?.output.userdoc}
|
|
|
|
devDoc={metadata?.output.devdoc}
|
|
|
|
internalOps={internalOps}
|
|
|
|
sendsEthToMiner={sendsEthToMiner}
|
|
|
|
ethUSDPrice={blockETHUSDPrice}
|
|
|
|
resolvedAddresses={resolvedAddresses}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
path="logs"
|
|
|
|
element={
|
|
|
|
<Logs
|
|
|
|
txData={txData}
|
|
|
|
metadata={metadata}
|
|
|
|
resolvedAddresses={resolvedAddresses}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
path="trace"
|
|
|
|
element={
|
|
|
|
<Trace
|
|
|
|
txData={txData}
|
|
|
|
resolvedAddresses={resolvedAddresses}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</Routes>
|
2021-11-07 11:21:56 +00:00
|
|
|
</React.Suspense>
|
|
|
|
</SelectionContext.Provider>
|
|
|
|
)}
|
|
|
|
</StandardFrame>
|
|
|
|
</SelectedTransactionContext.Provider>
|
2021-07-01 18:21:40 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2021-11-25 09:28:45 +00:00
|
|
|
export default Transaction;
|