Skip to content

Commit

Permalink
chore(TransactionFeedV2): Show stand by transactions when paginated d…
Browse files Browse the repository at this point in the history
…ata is empty (#6152)

### Description
6th PR for RET-1207. Adds handling of the empty transaction feed. There
is a possibility that a new user can have a few pending/failed
transactions that are stored in `standByTransactions` but paginated data
returning empty array for the first page. In this case we need to show
stand by transactions.

### Test plan
Adds test to show stand by transactions if the paginated data is empty.

### Related issues

- Relates to RET-1207

### Backwards compatibility
Yes

### Network scalability

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

- [x] Continue to work without code changes, OR trigger a compilation
error (guaranteeing we find it when a new network is added)
  • Loading branch information
sviderock authored Oct 17, 2024
1 parent 8db264a commit 8533127
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/transactions/feed/TransactionFeedV2.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,20 @@ describe('TransactionFeedV2', () => {
*/
await waitFor(() => expect(store.getState().transactions.standbyTransactions.length).toBe(0))
})

it('should show stand by transactions if paginated data is empty', async () => {
mockFetch.mockResponse(typedResponse({ transactions: [] }))
const { store, ...tree } = renderScreen({
transactions: {
standbyTransactions: [
mockTransaction({ transactionHash: '0x01', status: TransactionStatus.Complete }),
mockTransaction({ transactionHash: '0x02', status: TransactionStatus.Pending }),
],
},
})

await waitFor(() => expect(tree.getByTestId('TransactionList').props.data.length).toBe(2))
expect(tree.getByTestId('TransactionList').props.data[0].data.length).toBe(1)
expect(tree.getByTestId('TransactionList').props.data[1].data.length).toBe(1)
})
})
18 changes: 16 additions & 2 deletions src/transactions/feed/TransactionFeedV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,29 @@ function mergeStandByTransactionsInRange({
standByTransactions: TokenTransaction[]
currentCursor?: number
}): TokenTransaction[] {
if (transactions.length === 0) return []
/**
* If the data from the first page is empty - there's no successful transactions in the wallet.
* Maybe the user executed a single transaction, it failed and now it's in the standByTransactions.
* In this case we need to show whatever we've got in standByTransactions, until we have some
* paginated data to merge it with.
*/
const isFirstPage = currentCursor === FIRST_PAGE_TIMESTAMP
if (isFirstPage && transactions.length === 0) {
return standByTransactions
}

// return empty array for any page other than the first
if (transactions.length === 0) {
return []
}

const allowedNetworks = getAllowedNetworksForTransfers()
const max = transactions[0].timestamp
const min = transactions.at(-1)!.timestamp

const standByInRange = standByTransactions.filter((tx) => {
const inRange = tx.timestamp >= min && tx.timestamp <= max
const newTransaction = currentCursor === FIRST_PAGE_TIMESTAMP && tx.timestamp > max
const newTransaction = isFirstPage && tx.timestamp > max
return inRange || newTransaction
})
const deduplicatedTransactions = deduplicateTransactions([...transactions, ...standByInRange])
Expand Down

0 comments on commit 8533127

Please sign in to comment.