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 { 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); }, diff --git a/packages/assets-controllers/src/multi-chain-accounts-service/multi-chain-accounts.ts b/packages/assets-controllers/src/multi-chain-accounts-service/multi-chain-accounts.ts index f40afd2809..8723a7e9ea 100644 --- a/packages/assets-controllers/src/multi-chain-accounts-service/multi-chain-accounts.ts +++ b/packages/assets-controllers/src/multi-chain-accounts-service/multi-chain-accounts.ts @@ -38,15 +38,21 @@ export async function fetchSupportedNetworks(): Promise { * @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; }