Push down more hooks executions

This commit is contained in:
Willian Mitsuda 2022-08-10 05:21:08 -03:00
parent d5ba6ac781
commit edd3b87245
No known key found for this signature in database
2 changed files with 23 additions and 36 deletions

View File

@ -1,4 +1,4 @@
import React, { useContext, useMemo } from "react"; import React, { useContext } from "react";
import { Route, Routes } from "react-router-dom"; import { Route, Routes } from "react-router-dom";
import { Tab } from "@headlessui/react"; import { Tab } from "@headlessui/react";
import StandardFrame from "./StandardFrame"; import StandardFrame from "./StandardFrame";
@ -6,7 +6,7 @@ import StandardSubtitle from "./StandardSubtitle";
import ContentFrame from "./ContentFrame"; import ContentFrame from "./ContentFrame";
import NavTab from "./components/NavTab"; import NavTab from "./components/NavTab";
import { RuntimeContext } from "./useRuntime"; import { RuntimeContext } from "./useRuntime";
import { useInternalOperations, useTxData } from "./useErigonHooks"; import { useTxData } from "./useErigonHooks";
import { SelectionContext, useSelection } from "./useSelection"; import { SelectionContext, useSelection } from "./useSelection";
import { SelectedTransactionContext } from "./useSelectedTransaction"; import { SelectedTransactionContext } from "./useSelectedTransaction";
import { BlockNumberContext } from "./useBlockTagContext"; import { BlockNumberContext } from "./useBlockTagContext";
@ -25,19 +25,6 @@ const TransactionPageContent: React.FC<TransactionPageContentProps> = ({
const { provider } = useContext(RuntimeContext); const { provider } = useContext(RuntimeContext);
const txData = useTxData(provider, txHash); const txData = useTxData(provider, txHash);
const internalOps = useInternalOperations(provider, txData);
const sendsEthToMiner = useMemo(() => {
if (!txData || !internalOps) {
return false;
}
for (const t of internalOps) {
if (t.to === txData.confirmedData?.miner) {
return true;
}
}
return false;
}, [txData, internalOps]);
const selectionCtx = useSelection(); const selectionCtx = useSelection();
@ -71,16 +58,7 @@ const TransactionPageContent: React.FC<TransactionPageContentProps> = ({
</Tab.Group> </Tab.Group>
<React.Suspense fallback={null}> <React.Suspense fallback={null}>
<Routes> <Routes>
<Route <Route index element={<Details txData={txData} />} />
index
element={
<Details
txData={txData}
internalOps={internalOps}
sendsEthToMiner={sendsEthToMiner}
/>
}
/>
<Route path="logs" element={<Logs txData={txData} />} /> <Route path="logs" element={<Logs txData={txData} />} />
<Route path="trace" element={<Trace txData={txData} />} /> <Route path="trace" element={<Trace txData={txData} />} />
</Routes> </Routes>

View File

@ -1,4 +1,4 @@
import React, { useContext, useState } from "react"; import React, { useContext, useMemo, useState } from "react";
import { Tab } from "@headlessui/react"; import { Tab } from "@headlessui/react";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faCheckCircle } from "@fortawesome/free-solid-svg-icons/faCheckCircle"; import { faCheckCircle } from "@fortawesome/free-solid-svg-icons/faCheckCircle";
@ -24,7 +24,7 @@ import USDValue from "../components/USDValue";
import FormattedBalance from "../components/FormattedBalance"; import FormattedBalance from "../components/FormattedBalance";
import ETH2USDValue from "../components/ETH2USDValue"; import ETH2USDValue from "../components/ETH2USDValue";
import TokenTransferItem from "../TokenTransferItem"; import TokenTransferItem from "../TokenTransferItem";
import { TransactionData, InternalOperation } from "../types"; import { TransactionData } from "../types";
import PercentageBar from "../components/PercentageBar"; import PercentageBar from "../components/PercentageBar";
import ExternalLink from "../components/ExternalLink"; import ExternalLink from "../components/ExternalLink";
import RelativePosition from "../components/RelativePosition"; import RelativePosition from "../components/RelativePosition";
@ -43,21 +43,17 @@ import {
useTransactionDescription as useSourcifyTransactionDescription, useTransactionDescription as useSourcifyTransactionDescription,
} from "../sourcify/useSourcify"; } from "../sourcify/useSourcify";
import { RuntimeContext } from "../useRuntime"; import { RuntimeContext } from "../useRuntime";
import { useTransactionError } from "../useErigonHooks"; import { useInternalOperations, useTransactionError } from "../useErigonHooks";
import { useChainInfo } from "../useChainInfo"; import { useChainInfo } from "../useChainInfo";
import { useETHUSDOracle } from "../usePriceOracle"; import { useETHUSDOracle } from "../usePriceOracle";
type DetailsProps = { type DetailsProps = {
txData: TransactionData; txData: TransactionData;
internalOps?: InternalOperation[];
sendsEthToMiner: boolean;
}; };
const Details: React.FC<DetailsProps> = ({ const Details: React.FC<DetailsProps> = ({ txData }) => {
txData, const { provider } = useContext(RuntimeContext);
internalOps,
sendsEthToMiner,
}) => {
const hasEIP1559 = const hasEIP1559 =
txData.confirmedData?.blockBaseFeePerGas !== undefined && txData.confirmedData?.blockBaseFeePerGas !== undefined &&
txData.confirmedData?.blockBaseFeePerGas !== null; txData.confirmedData?.blockBaseFeePerGas !== null;
@ -71,7 +67,20 @@ const Details: React.FC<DetailsProps> = ({
txData.value txData.value
); );
const { provider } = useContext(RuntimeContext); const internalOps = useInternalOperations(provider, txData);
const sendsEthToMiner = useMemo(() => {
if (!txData || !internalOps) {
return false;
}
for (const t of internalOps) {
if (t.to === txData.confirmedData?.miner) {
return true;
}
}
return false;
}, [txData, internalOps]);
const { sourcifySource } = useAppConfigContext(); const { sourcifySource } = useAppConfigContext();
const metadata = useSourcifyMetadata( const metadata = useSourcifyMetadata(
txData?.to, txData?.to,