diff --git a/packages/core/src/controllers/BlockchainApiController.ts b/packages/core/src/controllers/BlockchainApiController.ts index 1568d1da43..2f4c56bccd 100644 --- a/packages/core/src/controllers/BlockchainApiController.ts +++ b/packages/core/src/controllers/BlockchainApiController.ts @@ -143,14 +143,16 @@ export const BlockchainApiController = { cursor, onramp, signal, - cache + cache, + chainId }: BlockchainApiTransactionsRequest) { return state.api.get({ path: `/v1/account/${account}/history`, params: { projectId, cursor, - onramp + onramp, + chainId }, signal, cache diff --git a/packages/core/src/controllers/TransactionsController.ts b/packages/core/src/controllers/TransactionsController.ts index d8b1b00579..b637ca0117 100644 --- a/packages/core/src/controllers/TransactionsController.ts +++ b/packages/core/src/controllers/TransactionsController.ts @@ -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) diff --git a/packages/core/src/utils/TypeUtil.ts b/packages/core/src/utils/TypeUtil.ts index f41b6b3ca0..5a1cb414d5 100644 --- a/packages/core/src/utils/TypeUtil.ts +++ b/packages/core/src/utils/TypeUtil.ts @@ -187,6 +187,7 @@ export interface BlockchainApiTransactionsRequest { onramp?: 'coinbase' signal?: AbortSignal cache?: RequestCache + chainId?: string } export interface BlockchainApiTransactionsResponse { diff --git a/packages/core/tests/controllers/TransactionsController.test.ts b/packages/core/tests/controllers/TransactionsController.test.ts index 00749921a8..4d01fca42d 100644 --- a/packages/core/tests/controllers/TransactionsController.test.ts +++ b/packages/core/tests/controllers/TransactionsController.test.ts @@ -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 @@ -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' + }) + }) })