Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(TransactionFeedV2): Fix removals and "jumps" of pending transactions #6206

Merged
merged 5 commits into from
Nov 5, 2024

Conversation

sviderock
Copy link
Contributor

@sviderock sviderock commented Nov 1, 2024

Description

This PR fixes an issue when some pending transactions can be removed from the feed for a short time and re-added back again. This was happening because pending and confirmed stand by transactions were split into 2 states which were independently affecting different parts of the final sections state.

Example:

  • pending transaction appears with a spinning indicator after a Send action
  • when it is marked as confirmed it changes both standByTransactions.pending and standByTransactions.confirmed

This causes the following update chains:

  • standByTransactions.pending -> sections
  • standByTransactions.confirmed -> updatePaginatedData -> paginatedData -> confirmedTransactions -> sections

So in result sections is updated twice with visual feedback in a form of removing and re-adding back transactions.

Test plan

All existing tests pass.

Simulator.Screen.Recording.-.iPhone.15.Pro.Max.-.2024-11-01.at.17.00.26.mp4

Related issues

Backwards compatibility

Network scalability

If a new NetworkId and/or Network are added in the future, the changes in this PR will:

  • Continue to work without code changes, OR trigger a compilation error (guaranteeing we find it when a new network is added)

Comment on lines 206 to 210
const transactionsFromAllowedNetworks = deduplicatedTransactions.filter((tx) =>
allowedNetworks.includes(tx.networkId)
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this to be applied at the end of the processing flow, within sections const. In this case, we can ensure that if somehow some async changes from mutlichain arrive and change showTransfers - it will instantly be reflected with recalculation of sections

@sviderock sviderock changed the base branch from main to slava/feed-v2-fix-persisted-feed November 1, 2024 15:12
@@ -22,6 +23,24 @@ const standbyTransactionsSelector = createSelector(
}
)

export const formattedStandByTransactionsSelector = createSelector(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't really know how to call this, considering there are already selectors like:

  • standByTransactionsSelector
  • allStandByTransactionsSelector
  • pendingStandByTransactionsSelector
  • confirmedStandByTransactionsSelector

The last three are un-memoized and trigger a lot of re-renders so cannot use them.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about adding this logic to standByTransactionsSelector? it seems harmless to ensure the correct types are returned?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kathaypacific standByTransactionsSelector includes getSupportedNetworkIdsForApprovalTxsInHomefeed which triggers a lot of unnecessary re-renders due to it being unmemoized. This is the reason I didn't use it in the first place and initially used allStandbyTransactionsSelector directly.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless it causes noticeable performance degradations, my personal preference would be to use existing functions rather than introduce extra complexity (and potential readability issues). we can go back and improve the memoization for the getSupportedNetworkIds* selectors later and fix the issue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kathaypacific my expectation was that once we remove the old feed - we'll adjust all the naming accordingly so there won't be an issue with multiple selectors having similar names and doing similar things.

Copy link

emerge-tools bot commented Nov 1, 2024

📸 Snapshot Test

No snapshots generated

Name Added Removed Modified Unchanged Errored Approval
Celo (test)
org.celo.mobile.test
0 0 0 0 0 N/A

🛸 Powered by Emerge Tools

Copy link

codecov bot commented Nov 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.93%. Comparing base (52fb491) to head (605eb1e).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #6206      +/-   ##
==========================================
- Coverage   88.93%   88.93%   -0.01%     
==========================================
  Files         737      737              
  Lines       31378    31379       +1     
  Branches     5801     5804       +3     
==========================================
- Hits        27907    27906       -1     
- Misses       3273     3275       +2     
  Partials      198      198              
Files with missing lines Coverage Δ
src/transactions/feed/TransactionFeedV2.tsx 89.53% <100.00%> (-0.96%) ⬇️
src/transactions/selectors.ts 100.00% <100.00%> (ø)
src/transactions/utils.ts 96.82% <ø> (-0.10%) ⬇️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 52fb491...605eb1e. Read the comment docs.

Copy link
Collaborator

@kathaypacific kathaypacific left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! ✨

@@ -268,7 +239,8 @@ function useNewlyCompletedTransactions(
useEffect(
function updatePrevStandBy() {
setPreviousStandBy((prev) => {
const confirmedHashes = standByTransactions.confirmed.map((tx) => tx.transactionHash)
const { pending, confirmed } = categorizeTransactions(standByTransactions)
const confirmedHashes = confirmed.map((tx) => tx.transactionHash)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: do we need to loop through to get transaction hashes, and then loop through again to use the .includes below? could we instead do confirmed.some(({transactionHash}) => transactionHash === tx.transactionHash) to get newlyCompleted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kathaypacific you're right about replacing .filter with .some! For some reason I interchangeably use both when I do these checks and I don't really know why I always pick one or the other 😄

I'll still need to .map for hashes whether for confirmed or prev.prending cause otherwise I'll need to do:

confirmed.some(({transactionHash}) => {
  const pendingTx = prev.prending.find((tx) => tx.transactionHash);
  return pendingTx && transactionHash === pendingTx?.transactionHash
}) 

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kathaypacific Oh, I've remember why I made it with .filter.
newlyCompleted is also used to calculate newlyCompletedCrossChainSwaps

@@ -22,6 +23,24 @@ const standbyTransactionsSelector = createSelector(
}
)

export const formattedStandByTransactionsSelector = createSelector(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about adding this logic to standByTransactionsSelector? it seems harmless to ensure the correct types are returned?

Base automatically changed from slava/feed-v2-fix-persisted-feed to main November 5, 2024 10:21
@sviderock sviderock added this pull request to the merge queue Nov 5, 2024
Merged via the queue into main with commit 34a9d38 Nov 5, 2024
16 checks passed
@sviderock sviderock deleted the slava/feed-v2-refactor-standby branch November 5, 2024 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants