From 812539674e9d4bc0116092e365e97a0676ce96f2 Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Mon, 22 Aug 2022 17:56:10 -0300 Subject: [PATCH] Remove hacky prefetcher --- src/transaction/NavButton.tsx | 41 +++++++++++++++++++++++++++++------ src/transaction/NavNonce.tsx | 27 ++--------------------- src/useErigonHooks.ts | 21 +----------------- 3 files changed, 37 insertions(+), 52 deletions(-) diff --git a/src/transaction/NavButton.tsx b/src/transaction/NavButton.tsx index 3f7186b..9ea59bf 100644 --- a/src/transaction/NavButton.tsx +++ b/src/transaction/NavButton.tsx @@ -1,5 +1,7 @@ -import { PropsWithChildren } from "react"; +import React, { PropsWithChildren, useContext, useState } from "react"; import { NavLink } from "react-router-dom"; +import { RuntimeContext } from "../useRuntime"; +import { useTransactionBySenderAndNonce } from "../useErigonHooks"; import { ChecksummedAddress } from "../types"; import { addressByNonceURL } from "../url"; @@ -16,6 +18,8 @@ const NavButton: React.FC> = ({ disabled, children, }) => { + const [prefetch, setPrefetch] = useState(false); + if (disabled) { return ( @@ -25,13 +29,36 @@ const NavButton: React.FC> = ({ } return ( - - {children} - + <> + setPrefetch(true)} + > + {children} + + {prefetch && } + ); }; +type PrefetcherProps = { + checksummedAddress: ChecksummedAddress; + nonce: number; +}; + +const Prefetcher: React.FC = ({ + checksummedAddress, + nonce, +}) => { + const { provider } = useContext(RuntimeContext); + const _txHash = useTransactionBySenderAndNonce( + provider, + checksummedAddress, + nonce + ); + + return <>; +}; + export default NavButton; diff --git a/src/transaction/NavNonce.tsx b/src/transaction/NavNonce.tsx index 9efd47f..e5f55b9 100644 --- a/src/transaction/NavNonce.tsx +++ b/src/transaction/NavNonce.tsx @@ -1,15 +1,11 @@ -import React, { useContext, useEffect } from "react"; +import React, { useContext } from "react"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faChevronLeft } from "@fortawesome/free-solid-svg-icons/faChevronLeft"; import { faChevronRight } from "@fortawesome/free-solid-svg-icons/faChevronRight"; import NavButton from "./NavButton"; import { ChecksummedAddress } from "../types"; import { RuntimeContext } from "../useRuntime"; -import { - prefetchTransactionBySenderAndNonce, - useTransactionCount, -} from "../useErigonHooks"; -import { useSWRConfig } from "swr"; +import { useTransactionCount } from "../useErigonHooks"; type NavNonceProps = { sender: ChecksummedAddress; @@ -20,25 +16,6 @@ const NavNonce: React.FC = ({ sender, nonce }) => { const { provider } = useContext(RuntimeContext); const count = useTransactionCount(provider, sender); - // Prefetch - const swrConfig = useSWRConfig(); - useEffect(() => { - if (!provider || !sender || nonce === undefined || count === undefined) { - return; - } - - prefetchTransactionBySenderAndNonce(swrConfig, provider, sender, nonce - 1); - prefetchTransactionBySenderAndNonce(swrConfig, provider, sender, nonce + 1); - if (count > 0) { - prefetchTransactionBySenderAndNonce( - swrConfig, - provider, - sender, - count - 1 - ); - } - }, [swrConfig, provider, sender, nonce, count]); - return (
diff --git a/src/useErigonHooks.ts b/src/useErigonHooks.ts index 6382877..f2b798c 100644 --- a/src/useErigonHooks.ts +++ b/src/useErigonHooks.ts @@ -10,7 +10,7 @@ import { Contract } from "@ethersproject/contracts"; import { defaultAbiCoder } from "@ethersproject/abi"; import { BigNumber } from "@ethersproject/bignumber"; import { arrayify, hexDataSlice, isHexString } from "@ethersproject/bytes"; -import useSWR, { useSWRConfig } from "swr"; +import useSWR from "swr"; import useSWRImmutable from "swr/immutable"; import { getInternalOperations } from "./nodeFunctions"; import { @@ -527,25 +527,6 @@ const getTransactionBySenderAndNonceFetcher = return result; }; -export const prefetchTransactionBySenderAndNonce = ( - { mutate }: ReturnType, - provider: JsonRpcProvider, - sender: ChecksummedAddress, - nonce: number -) => { - const key: TransactionBySenderAndNonceKey = { - network: provider.network.chainId, - sender, - nonce, - }; - mutate(key, (curr: any) => { - if (curr) { - return curr; - } - return getTransactionBySenderAndNonceFetcher(provider)(key); - }); -}; - export const useTransactionBySenderAndNonce = ( provider: JsonRpcProvider | undefined, sender: ChecksummedAddress | undefined,