Skip to content

Commit

Permalink
fix: add missing chainId param for transactions request (#2779)
Browse files Browse the repository at this point in the history
  • Loading branch information
zoruka authored Sep 2, 2024
1 parent 6b95ad8 commit 5869107
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
6 changes: 4 additions & 2 deletions packages/core/src/controllers/BlockchainApiController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,16 @@ export const BlockchainApiController = {
cursor,
onramp,
signal,
cache
cache,
chainId
}: BlockchainApiTransactionsRequest) {
return state.api.get<BlockchainApiTransactionsResponse>({
path: `/v1/account/${account}/history`,
params: {
projectId,
cursor,
onramp
onramp,
chainId
},
signal,
cache
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/controllers/TransactionsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ export const TransactionsController = {
cursor: state.next,
onramp,
// Coinbase transaction history state updates require the latest data
cache: onramp === 'coinbase' ? 'no-cache' : undefined
cache: onramp === 'coinbase' ? 'no-cache' : undefined,
chainId: NetworkController.state.caipNetwork?.id
})

const nonSpamTransactions = this.filterSpamTransactions(response.data)
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/utils/TypeUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export interface BlockchainApiTransactionsRequest {
onramp?: 'coinbase'
signal?: AbortSignal
cache?: RequestCache
chainId?: string
}

export interface BlockchainApiTransactionsResponse {
Expand Down
32 changes: 31 additions & 1 deletion packages/core/tests/controllers/TransactionsController.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { describe, expect, it, vi } from 'vitest'
import { BlockchainApiController, OptionsController, TransactionsController } from '../../index.js'
import {
BlockchainApiController,
NetworkController,
OptionsController,
TransactionsController
} from '../../index.js'
import {
ONRAMP_TRANSACTIONS_RESPONSES_FEB,
ONRAMP_TRANSACTIONS_RESPONSES_JAN
Expand Down Expand Up @@ -273,4 +278,29 @@ describe('TransactionsController', () => {
})
expect(TransactionsController.state.next).toBe('cursor')
})

it('should call fetchTransactions with chainId', async () => {
const fetchTransactions = vi
.spyOn(BlockchainApiController, 'fetchTransactions')
.mockResolvedValue({
data: [],
next: 'cursor'
})

vi.spyOn(NetworkController, 'state', 'get').mockReturnValue({
caipNetwork: {
id: 'eip155:1'
}
} as any)

await TransactionsController.fetchTransactions('0x123', 'coinbase')
expect(fetchTransactions).toHaveBeenCalledWith({
account: '0x123',
projectId,
cursor: 'cursor',
onramp: 'coinbase',
cache: 'no-cache',
chainId: 'eip155:1'
})
})
})

0 comments on commit 5869107

Please sign in to comment.