From c50620cecc192711d218ad5c60f88ef9640df799 Mon Sep 17 00:00:00 2001 From: Brian Bergeron Date: Wed, 30 Oct 2024 17:34:56 -0700 Subject: [PATCH 1/2] pass header to accounts api --- .../src/TokenDetectionController.test.ts | 1 + .../src/TokenDetectionController.ts | 16 +++++++++++++--- .../multi-chain-accounts.ts | 10 ++++++++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/packages/assets-controllers/src/TokenDetectionController.test.ts b/packages/assets-controllers/src/TokenDetectionController.test.ts index 7dc2fd6616..7413ad9ff2 100644 --- a/packages/assets-controllers/src/TokenDetectionController.test.ts +++ b/packages/assets-controllers/src/TokenDetectionController.test.ts @@ -2931,6 +2931,7 @@ async function withController( trackMetaMetricsEvent: jest.fn(), messenger: buildTokenDetectionControllerMessenger(controllerMessenger), useAccountsAPI: false, + platform: 'extension', ...options, }); try { diff --git a/packages/assets-controllers/src/TokenDetectionController.ts b/packages/assets-controllers/src/TokenDetectionController.ts index e5846abb4a..52a84bfc01 100644 --- a/packages/assets-controllers/src/TokenDetectionController.ts +++ b/packages/assets-controllers/src/TokenDetectionController.ts @@ -201,6 +201,8 @@ export class TokenDetectionController extends StaticIntervalPollingController void; messenger: TokenDetectionControllerMessenger; useAccountsAPI?: boolean; + platform: 'extension' | 'mobile'; }) { super({ name: controllerName, @@ -315,6 +324,7 @@ export class TokenDetectionController extends StaticIntervalPollingController { * @param address - address to fetch balances from * @param options - params to pass down for a more refined search * @param options.networks - the networks (in decimal) that you want to filter by + * @param platform - indicates whether the platform is extension or mobile * @returns a Balances Response */ export async function fetchMultiChainBalances( address: string, - options?: { networks?: number[] }, + options: { networks?: number[] }, + platform: 'extension' | 'mobile', ) { const url = getBalancesUrl(address, { networks: options?.networks?.join(), }); - const response: GetBalancesResponse = await handleFetch(url); + const response: GetBalancesResponse = await handleFetch(url, { + headers: { + 'x-metamask-clientproduct': `metamask-${platform}`, + }, + }); return response; } From ad39686d96aca82a851c17d3c276bd1b83280701 Mon Sep 17 00:00:00 2001 From: Brian Bergeron Date: Wed, 30 Oct 2024 17:40:56 -0700 Subject: [PATCH 2/2] fix unit test --- .../multi-chain-accounts.test.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/assets-controllers/src/multi-chain-accounts-service/multi-chain-accounts.test.ts b/packages/assets-controllers/src/multi-chain-accounts-service/multi-chain-accounts.test.ts index 0545a5ef4a..06ebd7fffd 100644 --- a/packages/assets-controllers/src/multi-chain-accounts-service/multi-chain-accounts.test.ts +++ b/packages/assets-controllers/src/multi-chain-accounts-service/multi-chain-accounts.test.ts @@ -46,7 +46,7 @@ describe('fetchMultiChainBalances()', () => { it('should successfully return balances response', async () => { const mockAPI = createMockAPI().reply(200, MOCK_GET_BALANCES_RESPONSE); - const result = await fetchMultiChainBalances(MOCK_ADDRESS); + const result = await fetchMultiChainBalances(MOCK_ADDRESS, {}, 'extension'); expect(result).toBeDefined(); expect(result).toStrictEqual(MOCK_GET_BALANCES_RESPONSE); expect(mockAPI.isDone()).toBe(true); @@ -59,9 +59,13 @@ describe('fetchMultiChainBalances()', () => { }) .reply(200, MOCK_GET_BALANCES_RESPONSE); - const result = await fetchMultiChainBalances(MOCK_ADDRESS, { - networks: [1, 10], - }); + const result = await fetchMultiChainBalances( + MOCK_ADDRESS, + { + networks: [1, 10], + }, + 'extension', + ); expect(result).toBeDefined(); expect(result).toStrictEqual(MOCK_GET_BALANCES_RESPONSE); expect(mockAPI.isDone()).toBe(true); @@ -79,7 +83,8 @@ describe('fetchMultiChainBalances()', () => { const mockAPI = createMockAPI().reply(httpCode); await expect( - async () => await fetchMultiChainBalances(MOCK_ADDRESS), + async () => + await fetchMultiChainBalances(MOCK_ADDRESS, {}, 'extension'), ).rejects.toThrow(expect.any(Error)); expect(mockAPI.isDone()).toBe(true); },