From 5e11789393571b3a78331f4cfc3e9db3c9eb5ca4 Mon Sep 17 00:00:00 2001 From: Myroslav Sviderok Date: Fri, 1 Nov 2024 13:04:59 +0200 Subject: [PATCH 1/2] fix persisted feed storing unmerged transactions --- src/transactions/feed/TransactionFeedV2.tsx | 15 ++++++++++++++- src/transactions/slice.ts | 18 +++++++++++------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/transactions/feed/TransactionFeedV2.tsx b/src/transactions/feed/TransactionFeedV2.tsx index cff9720be50..f87662441dd 100644 --- a/src/transactions/feed/TransactionFeedV2.tsx +++ b/src/transactions/feed/TransactionFeedV2.tsx @@ -29,6 +29,7 @@ import TokenApprovalFeedItem from 'src/transactions/feed/TokenApprovalFeedItem' import TransferFeedItem from 'src/transactions/feed/TransferFeedItem' import NoActivity from 'src/transactions/NoActivity' import { allStandbyTransactionsSelector, feedFirstPageSelector } from 'src/transactions/selectors' +import { updateFeedFirstPage } from 'src/transactions/slice' import { FeeType, TokenTransactionTypeV2, @@ -203,7 +204,8 @@ function mergeStandByTransactionsInRange({ return inRange || newTransaction || veryOldTransaction }) const deduplicatedTransactions = deduplicateTransactions([...transactions, ...standByInRange]) - const transactionsFromAllowedNetworks = deduplicatedTransactions.filter((tx) => + const sortedTransactions = sortTransactions(deduplicatedTransactions) + const transactionsFromAllowedNetworks = sortedTransactions.filter((tx) => allowedNetworks.includes(tx.networkId) ) @@ -427,6 +429,17 @@ export default function TransactionFeedV2() { [newlyCompletedCrossChainSwaps] ) + useEffect( + function updatePersistedFeedFirstPage() { + const isFirstPage = !data?.pageInfo.hasPreviousPage + if (isFirstPage) { + const firstPageData = paginatedData[FIRST_PAGE_CURSOR] + dispatch(updateFeedFirstPage({ transactions: firstPageData })) + } + }, + [paginatedData, data?.pageInfo] + ) + const confirmedTransactions = useMemo(() => { const flattenedPages = Object.values(paginatedData).flat() const deduplicatedTransactions = deduplicateTransactions(flattenedPages) diff --git a/src/transactions/slice.ts b/src/transactions/slice.ts index 94f1e15f142..c61327462b4 100644 --- a/src/transactions/slice.ts +++ b/src/transactions/slice.ts @@ -204,6 +204,11 @@ const slice = createSlice({ standbyTransactions: updatedStandbyTransactions, } }, + + updateFeedFirstPage: (state, action: PayloadAction<{ transactions: TokenTransaction[] }>) => ({ + ...state, + feedFirstPage: action.payload.transactions, + }), }, extraReducers: (builder) => { @@ -221,10 +226,6 @@ const slice = createSlice({ * Whenever we get new data from the feed pagination - we need to perform updates on some portion * of our reducer data, as side-effects. These scenarios include: * - * - Updating "feedFirstPage" whenever we get new data for the first page. We use this to instantly - * show the user something that can be interacted with while we're actually refetching the latest - * state in the background. - * * - In order to avoid bloating stand by transactions with confirmed transactions that are already * present in the feed via pagination – we need to clean them up. This must run for every page * as standByTransaction might include very old transactions. We should use the chance whenever @@ -233,14 +234,12 @@ const slice = createSlice({ builder.addMatcher( transactionFeedV2Api.endpoints.transactionFeedV2.matchFulfilled, (state, { payload, meta }) => { - const isFirstPage = meta.arg.originalArgs.endCursor === undefined const confirmedTransactionsFromNewPage = payload.transactions .filter((tx) => tx.status !== TransactionStatus.Pending) .map((tx) => tx.transactionHash) return { ...state, - feedFirstPage: isFirstPage ? payload.transactions : state.feedFirstPage, standbyTransactions: state.standbyTransactions.filter((tx) => { /** * - ignore empty hashes as there's no way to compare them @@ -256,7 +255,12 @@ const slice = createSlice({ }, }) -export const { addStandbyTransaction, transactionConfirmed, updateTransactions } = slice.actions +export const { + addStandbyTransaction, + transactionConfirmed, + updateTransactions, + updateFeedFirstPage, +} = slice.actions export const { actions } = slice From 5e1a615b77819a7ccc7a63f6055d6371051d1835 Mon Sep 17 00:00:00 2001 From: Myroslav Sviderok Date: Mon, 4 Nov 2024 13:47:05 +0200 Subject: [PATCH 2/2] add space just to trigger PR checks re-run --- src/transactions/selectors.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/transactions/selectors.ts b/src/transactions/selectors.ts index ddaf4fbfea1..60d3ffd4aa8 100644 --- a/src/transactions/selectors.ts +++ b/src/transactions/selectors.ts @@ -118,4 +118,5 @@ export const pendingStandbyTxHashesByNetworkIdSelector = createSelector( ) const feedFirstPage = (state: RootState) => state.transactions.feedFirstPage + export const feedFirstPageSelector = createSelector(feedFirstPage, (feed) => feed)