From 65cc6a69c8639705d1623ff390498865fe89d802 Mon Sep 17 00:00:00 2001 From: Justin Starry Date: Tue, 29 Sep 2020 21:24:01 +0800 Subject: [PATCH] Fix history fetching and inner spl token instructions (#12515) --- .../components/account/TokenHistoryCard.tsx | 246 ++++++++++-------- .../src/providers/transactions/details.tsx | 15 ++ 2 files changed, 158 insertions(+), 103 deletions(-) diff --git a/explorer/src/components/account/TokenHistoryCard.tsx b/explorer/src/components/account/TokenHistoryCard.tsx index 1290be8ac5..7e2d1e8f39 100644 --- a/explorer/src/components/account/TokenHistoryCard.tsx +++ b/explorer/src/components/account/TokenHistoryCard.tsx @@ -4,7 +4,7 @@ import { ConfirmedSignatureInfo, ParsedInstruction, } from "@solana/web3.js"; -import { FetchStatus } from "providers/cache"; +import { CacheEntry, FetchStatus } from "providers/cache"; import { useAccountHistories, useFetchAccountHistory, @@ -12,14 +12,18 @@ import { import { useAccountOwnedTokens, TokenInfoWithPubkey, + TOKEN_PROGRAM_ID, } from "providers/accounts/tokens"; import { ErrorCard } from "components/common/ErrorCard"; import { LoadingCard } from "components/common/LoadingCard"; import { Signature } from "components/common/Signature"; import { Address } from "components/common/Address"; import { Slot } from "components/common/Slot"; -import { useTransactionDetails } from "providers/transactions"; -import { useFetchTransactionDetails } from "providers/transactions/details"; +import { + Details, + useFetchTransactionDetails, + useTransactionDetailsCache, +} from "providers/transactions/details"; import { coerce } from "superstruct"; import { ParsedInfo } from "validators"; import { @@ -51,6 +55,7 @@ export function TokenHistoryCard({ pubkey }: { pubkey: PublicKey }) { function TokenHistoryTable({ tokens }: { tokens: TokenInfoWithPubkey[] }) { const accountHistories = useAccountHistories(); const fetchAccountHistory = useFetchAccountHistory(); + const transactionDetailsCache = useTransactionDetailsCache(); const fetchHistories = (refresh?: boolean) => { tokens.forEach((token) => { @@ -68,11 +73,30 @@ function TokenHistoryTable({ tokens }: { tokens: TokenInfoWithPubkey[] }) { }); }, []); // eslint-disable-line react-hooks/exhaustive-deps - const fetchedFullHistory = tokens.every((token) => { + const allFoundOldest = tokens.every((token) => { const history = accountHistories[token.pubkey.toBase58()]; return history?.data?.foundOldest === true; }); + const allFetchedSome = tokens.every((token) => { + const history = accountHistories[token.pubkey.toBase58()]; + return history?.data !== undefined; + }); + + // Find the oldest slot which we know we have the full history for + let oldestSlot: number | undefined = allFoundOldest ? 0 : undefined; + if (!allFoundOldest && allFetchedSome) { + tokens.forEach((token) => { + const history = accountHistories[token.pubkey.toBase58()]; + if (history?.data?.foundOldest === false) { + const earliest = + history.data.fetched[history.data.fetched.length - 1].slot; + if (!oldestSlot) oldestSlot = earliest; + oldestSlot = Math.max(oldestSlot, earliest); + } + }); + } + const fetching = tokens.some((token) => { const history = accountHistories[token.pubkey.toBase58()]; return history?.status === FetchStatus.Fetching; @@ -102,6 +126,9 @@ function TokenHistoryTable({ tokens }: { tokens: TokenInfoWithPubkey[] }) { if (sigSet.has(tx.signature)) return false; sigSet.add(tx.signature); return true; + }) + .filter(({ tx }) => { + return oldestSlot !== undefined && tx.slot >= oldestSlot; }); if (mintAndTxs.length === 0) { @@ -166,14 +193,19 @@ function TokenHistoryTable({ tokens }: { tokens: TokenInfoWithPubkey[] }) { {mintAndTxs.map(({ mint, tx }) => ( - + ))}
- {fetchedFullHistory ? ( + {allFoundOldest ? (
Fetched full history
) : (