diff --git a/src/components/TransactionDirection.tsx b/src/components/TransactionDirection.tsx index aca1f95..54b1685 100644 --- a/src/components/TransactionDirection.tsx +++ b/src/components/TransactionDirection.tsx @@ -11,6 +11,7 @@ export enum Direction { } export enum Flags { + // Means the transaction internal sends ETH to the miner, e.g. flashbots MINER, } diff --git a/src/search/TransactionItem.tsx b/src/search/TransactionItem.tsx index 94e4820..c0f6d39 100644 --- a/src/search/TransactionItem.tsx +++ b/src/search/TransactionItem.tsx @@ -16,7 +16,7 @@ import TransactionItemFiatFee from "./TransactionItemFiatFee"; import { ProcessedTransaction } from "../types"; import { FeeDisplay } from "./useFeeToggler"; import { RuntimeContext } from "../useRuntime"; -import { useHasCode } from "../useErigonHooks"; +import { useHasCode, useSendsToMiner } from "../useErigonHooks"; import { formatValue } from "../components/formatter"; type TransactionItemProps = { @@ -36,6 +36,7 @@ const TransactionItem: React.FC = ({ tx.to ?? undefined, tx.blockNumber - 1 ); + const [sendsToMiner] = useSendsToMiner(provider, tx.hash, tx.miner); let direction: Direction | undefined; if (selectedAddress) { @@ -53,7 +54,7 @@ const TransactionItem: React.FC = ({ } } - const flash = tx.gasPrice.isZero() && tx.internalMinerInteraction; + const flash = tx.gasPrice.isZero() && sendsToMiner; return (
= ({ diff --git a/src/transaction/Details.tsx b/src/transaction/Details.tsx index 62844ff..6932f5c 100644 --- a/src/transaction/Details.tsx +++ b/src/transaction/Details.tsx @@ -1,4 +1,4 @@ -import React, { useContext, useMemo, useState } from "react"; +import React, { useContext, useState } from "react"; import { Tab } from "@headlessui/react"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faCheckCircle } from "@fortawesome/free-solid-svg-icons/faCheckCircle"; @@ -43,7 +43,7 @@ import { useTransactionDescription as useSourcifyTransactionDescription, } from "../sourcify/useSourcify"; import { RuntimeContext } from "../useRuntime"; -import { useInternalOperations, useTransactionError } from "../useErigonHooks"; +import { useSendsToMiner, useTransactionError } from "../useErigonHooks"; import { useChainInfo } from "../useChainInfo"; import { useETHUSDOracle } from "../usePriceOracle"; @@ -67,19 +67,11 @@ const Details: React.FC = ({ txData }) => { txData.value ); - 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 [sendsEthToMiner, internalOps] = useSendsToMiner( + provider, + txData.confirmedData ? txData.transactionHash : undefined, + txData.confirmedData?.miner + ); const metadata = useSourcifyMetadata(txData?.to, provider?.network.chainId); diff --git a/src/types.ts b/src/types.ts index adedc86..44a134b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -18,7 +18,6 @@ export type ProcessedTransaction = { from?: string; to: string | null; createdContractAddress?: string; - internalMinerInteraction?: boolean; value: BigNumber; fee: BigNumber; gasPrice: BigNumber; diff --git a/src/useErigonHooks.ts b/src/useErigonHooks.ts index 75e8a32..a3620b7 100644 --- a/src/useErigonHooks.ts +++ b/src/useErigonHooks.ts @@ -140,27 +140,6 @@ export const useBlockTransactions = ( .reverse(); setTxs(rawTxs); setTotalTxs(result.fullblock.transactionCount); - - const checkTouchMinerAddr = await Promise.all( - rawTxs.map(async (res) => { - const ops = await getInternalOperations(provider, res.hash); - return ( - ops.findIndex( - (op) => - op.type === OperationType.TRANSFER && - res.miner !== undefined && - res.miner === getAddress(op.to) - ) !== -1 - ); - }) - ); - const processedTxs = rawTxs.map( - (r, i): ProcessedTransaction => ({ - ...r, - internalMinerInteraction: checkTouchMinerAddr[i], - }) - ); - setTxs(processedTxs); }; readBlock(); }, [provider, blockNumber, pageNumber, pageSize]); @@ -308,34 +287,13 @@ export const useTxData = ( return txData; }; -// TODO: convert caller to hooks and remove this function -const getInternalOperations = async ( - provider: JsonRpcProvider, - txHash: string -) => { - const rawTransfers = await provider.send("ots_getInternalOperations", [ - txHash, - ]); - - const _transfers: InternalOperation[] = []; - for (const t of rawTransfers) { - _transfers.push({ - type: t.type, - from: getAddress(t.from), - to: getAddress(t.to), - value: t.value, - }); - } - return _transfers; -}; - export const useInternalOperations = ( provider: JsonRpcProvider | undefined, - txData: TransactionData | undefined | null + txHash: string | undefined ): InternalOperation[] | undefined => { const { data, error } = useSWRImmutable( - provider !== undefined && txData?.confirmedData - ? ["ots_getInternalOperations", txData.transactionHash] + provider !== undefined && txHash !== undefined + ? ["ots_getInternalOperations", txHash] : null, providerFetcher(provider) ); @@ -359,6 +317,26 @@ export const useInternalOperations = ( return _transfers; }; +export const useSendsToMiner = ( + provider: JsonRpcProvider | undefined, + txHash: string | undefined, + miner: string | undefined +): [boolean, InternalOperation[]] | [undefined, undefined] => { + const ops = useInternalOperations(provider, txHash); + if (ops === undefined) { + return [undefined, undefined]; + } + + const send = + ops.findIndex( + (op) => + op.type === OperationType.TRANSFER && + miner !== undefined && + miner === getAddress(op.to) + ) !== -1; + return [send, ops]; +}; + export type TraceEntry = { type: string; depth: number;