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: add missing chainId param for transactions request #2779

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
})
})
})
Loading