Skip to content

Commit

Permalink
Merge branch 'main' into l10n/main
Browse files Browse the repository at this point in the history
  • Loading branch information
valora-bot authored Oct 26, 2024
2 parents 4139faf + 65b4db4 commit 1c28623
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 110 deletions.
9 changes: 5 additions & 4 deletions knip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const config: KnipConfig = {
'jest-snapshot',
'lint-staged', // pre-commit hook
'lokijs', // walletconnect e2e tests requires
'prettier-plugin-java',
'react-devtools', // application profiling
'react-native-version',
'react-native-kill-packager',
Expand All @@ -34,9 +33,11 @@ const config: KnipConfig = {
'husky',
],
ignore: [
'src/utils/inputValidation.ts',
'src/utils/country.json',
'src/redux/reducersForSchemaGeneration.ts',
'src/redux/reducersForSchemaGeneration.ts', // used for root state schema generation
'src/analytics/docs.ts', // documents analytics events, no references
'src/account/__mocks__/Persona.tsx', // unit test mocks
'src/firebase/remoteConfigValuesDefaults.e2e.ts', // e2e test setup
'src/setupE2eEnv.e2e.ts', // e2e test setup
],
}

Expand Down
9 changes: 0 additions & 9 deletions src/redux/api.ts

This file was deleted.

36 changes: 24 additions & 12 deletions src/transactions/api.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
import { createApi } from '@reduxjs/toolkit/query/react'
import { baseQuery } from 'src/redux/api'
import type { TokenTransaction } from 'src/transactions/types'

export const FIRST_PAGE_TIMESTAMP = 0 // placeholder
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
import { type LocalCurrencyCode } from 'src/localCurrency/consts'
import {
TokenTransactionTypeV2,
type PageInfo,
type TokenTransaction,
} from 'src/transactions/types'
import networkConfig from 'src/web3/networkConfig'

export type TransactionFeedV2Response = {
transactions: TokenTransaction[]
pageInfo: {
hasNextPage: boolean
}
pageInfo: PageInfo
}

const baseQuery = fetchBaseQuery({
baseUrl: networkConfig.getWalletTransactionsUrl,
headers: { Accept: 'application/json' },
})

export const transactionFeedV2Api = createApi({
reducerPath: 'transactionFeedV2Api',
baseQuery,
endpoints: (builder) => ({
transactionFeedV2: builder.query<
TransactionFeedV2Response,
{ address: string; endCursor: number }
{
address: string
localCurrencyCode: LocalCurrencyCode
endCursor: PageInfo['endCursor'] | undefined
}
>({
query: ({ address, endCursor }) => {
const cursor = endCursor ? `?endCursor=${endCursor}` : ''
return `/wallet/${address}/transactions${cursor}`
query: ({ address, localCurrencyCode, endCursor }) => {
const networkIds = Object.values(networkConfig.networkToNetworkId).join('&networkIds[]=')
const includeTypes = Object.values(TokenTransactionTypeV2).join('&includeTypes[]=')
const cursor = endCursor === undefined ? '' : `&afterCursor=${endCursor}`
return `?networkIds[]=${networkIds}&includeTypes[]=${includeTypes}&address=${address}&localCurrencyCode=${localCurrencyCode}${cursor}`
},
keepUnusedDataFor: 60, // 1 min
}),
Expand Down
102 changes: 87 additions & 15 deletions src/transactions/feed/TransactionFeedV2.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,17 @@ function getNumTransactionItems(sectionList: ReactTestInstance) {
return sectionList.props.data[0].data.length
}

const typedResponse = (response: Partial<TransactionFeedV2Response>) => JSON.stringify(response)
const typedResponse = (response: Partial<TransactionFeedV2Response>) => {
return JSON.stringify({
pageInfo: {
startCursor: '1',
endCursor: '2',
hasPreviousPage: false,
hasNextPage: true,
},
...response,
} satisfies Partial<TransactionFeedV2Response>)
}

function getInitialStore(storeOverrides: RecursivePartial<Omit<RootState, ApiReducersKeys>> = {}) {
const state: typeof storeOverrides = {
Expand Down Expand Up @@ -209,6 +219,7 @@ describe('TransactionFeedV2', () => {
.mockResponseOnce(
typedResponse({
transactions: [mockTransaction({ transactionHash: '0x02', timestamp: 20 })],
pageInfo: { startCursor: '2', endCursor: '', hasNextPage: false, hasPreviousPage: true },
})
)
.mockResponseOnce(typedResponse({ transactions: [] }))
Expand All @@ -221,12 +232,7 @@ describe('TransactionFeedV2', () => {
await waitFor(() => expect(tree.getByTestId('TransactionList/loading')).toBeVisible())
await waitFor(() => expect(tree.queryByTestId('TransactionList/loading')).toBeFalsy())

fireEvent(tree.getByTestId('TransactionList'), 'onEndReached')
await waitFor(() => expect(mockFetch).toBeCalled())
await waitFor(() => expect(tree.getByTestId('TransactionList/loading')).toBeVisible())
await waitFor(() => expect(tree.queryByTestId('TransactionList/loading')).toBeFalsy())

expect(mockFetch).toHaveBeenCalledTimes(3)
expect(mockFetch).toHaveBeenCalledTimes(2)
expect(getNumTransactionItems(tree.getByTestId('TransactionList'))).toBe(2)
})

Expand Down Expand Up @@ -361,7 +367,12 @@ describe('TransactionFeedV2', () => {
],
})
)
.mockResponseOnce(typedResponse({ transactions: [] }))
.mockResponseOnce(
typedResponse({
transactions: [],
pageInfo: { hasNextPage: false, hasPreviousPage: true, startCursor: '2', endCursor: '' },
})
)

const tree = renderScreen()

Expand Down Expand Up @@ -402,13 +413,32 @@ describe('TransactionFeedV2', () => {
await waitFor(() => expect(Toast.showWithGravity).not.toBeCalled())
})

it('should vibrate when there is a pending transaction that turned into completed', async () => {
// eslint-disable-next-line jest/no-disabled-tests
it.skip('should vibrate when there is a pending transaction that turned into completed', async () => {
const standByTransactionHash = '0x02' as string
mockFetch.mockResponseOnce(typedResponse({ transactions: [] })).mockResponseOnce(
typedResponse({
transactions: [mockTransaction({ transactionHash: standByTransactionHash })],
})
)
mockFetch
.mockResponseOnce(
typedResponse({
transactions: [],
pageInfo: {
startCursor: '1',
endCursor: '',
hasPreviousPage: false,
hasNextPage: false,
},
})
)
.mockResponseOnce(
typedResponse({
transactions: [mockTransaction({ transactionHash: standByTransactionHash })],
pageInfo: {
startCursor: '1',
endCursor: '',
hasPreviousPage: false,
hasNextPage: false,
},
})
)

const { store, ...tree } = renderScreen({
transactions: {
Expand Down Expand Up @@ -552,9 +582,51 @@ describe('TransactionFeedV2', () => {
})

it('should pre-populate persisted first page of the feed', async () => {
mockFetch.mockResponse(typedResponse({ transactions: [] }))
mockFetch.mockResponse(
typedResponse({
transactions: [],
pageInfo: { startCursor: '1', endCursor: '', hasPreviousPage: false, hasNextPage: false },
})
)
const tree = renderScreen({ transactions: { feedFirstPage: [mockTransaction()] } })
expect(tree.getByTestId('TransactionList').props.data[0].data.length).toBe(1)
expect(mockFetch).not.toBeCalled()
})

it('should merge the rest of stand by transactions after the last page', async () => {
mockFetch.mockResponse(
typedResponse({
transactions: [
mockTransaction({ transactionHash: '0x100', timestamp: 100 }),
mockTransaction({ transactionHash: '0x90', timestamp: 90 }),
mockTransaction({ transactionHash: '0x80', timestamp: 80 }),
],
pageInfo: {
startCursor: '1',
endCursor: '',
hasPreviousPage: false,
hasNextPage: false,
},
})
)

const tree = renderScreen({
transactions: {
standbyTransactions: [
mockTransaction({ transactionHash: '0x95', timestamp: 95 }),
mockTransaction({ transactionHash: '0x85', timestamp: 85 }),
mockTransaction({ transactionHash: '0x30', timestamp: 30 }),
mockTransaction({ transactionHash: '0x20', timestamp: 20 }),
mockTransaction({ transactionHash: '0x10', timestamp: 10 }),
],
},
})

await waitFor(() => expect(tree.getByTestId('TransactionList')).toBeVisible())

const hashes = tree
.getByTestId('TransactionList')
.props.data[0].data.map((item: TokenTransaction) => item.transactionHash)
expect(hashes).toStrictEqual(['0x100', '0x95', '0x90', '0x85', '0x80', '0x30', '0x20', '0x10'])
})
})
Loading

0 comments on commit 1c28623

Please sign in to comment.