Skip to content

Commit a8c8fae

Browse files
committed
fix: fix cursor comment
1 parent e31693c commit a8c8fae

File tree

3 files changed

+8
-66
lines changed

3 files changed

+8
-66
lines changed

packages/assets-controllers/src/multi-chain-accounts-service/api-balance-fetcher.test.ts

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,47 +1888,6 @@ describe('AccountsApiBalanceFetcher', () => {
18881888
expect(oldMethodCalculation.toString()).toContain('e+'); // Should be in scientific notation
18891889
});
18901890

1891-
it('should create error entries for all addresses when API fails completely (lines 383-385)', async () => {
1892-
// Mock the API to throw an error directly (this will trigger apiError = true)
1893-
mockFetchMultiChainBalancesV4.mockRejectedValue(
1894-
new Error('API completely failed'),
1895-
);
1896-
// Mock staking provider to return successful staked balances
1897-
const mockProvider = {
1898-
call: jest.fn().mockResolvedValue('0x0de0b6b3a7640000'), // 1 ETH in hex
1899-
};
1900-
const mockGetProvider = jest.fn().mockReturnValue(mockProvider);
1901-
const balanceFetcherWithStaking = new AccountsApiBalanceFetcher(
1902-
'extension',
1903-
mockGetProvider,
1904-
);
1905-
1906-
const result = await balanceFetcherWithStaking.fetch({
1907-
chainIds: [MOCK_CHAIN_ID, '0x89'], // Multiple chains
1908-
queryAllAccounts: true, // Multiple accounts
1909-
selectedAccount: MOCK_ADDRESS_1 as ChecksumAddress,
1910-
allAccounts: MOCK_INTERNAL_ACCOUNTS,
1911-
});
1912-
1913-
// Should have error entries for each address/chain combination (from API failure)
1914-
const errorEntries = result.filter((r) => !r.success);
1915-
1916-
// Should also have successful entries (from staking)
1917-
const successEntries = result.filter((r) => r.success);
1918-
1919-
expect(errorEntries.length).toBeGreaterThan(0);
1920-
expect(successEntries.length).toBeGreaterThan(0); // This prevents line 400 from throwing
1921-
1922-
// Verify error entries have correct structure (can be native token or staking contract)
1923-
errorEntries.forEach((entry) => {
1924-
expect(entry.success).toBe(false);
1925-
// Error entries can be for native token (API failure) or staking contract (staking failure)
1926-
expect([ZERO_ADDRESS, STAKING_CONTRACT_ADDRESS]).toContain(entry.token);
1927-
expect(['0x1', '0x89']).toContain(entry.chainId);
1928-
expect([MOCK_ADDRESS_1, MOCK_ADDRESS_2]).toContain(entry.account);
1929-
});
1930-
});
1931-
19321891
it('should throw error when API fails and no successful results exist (line 400)', async () => {
19331892
const mockApiError = new Error('Complete API failure');
19341893

packages/assets-controllers/src/multi-chain-accounts-service/api-balance-fetcher.ts

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Contract } from '@ethersproject/contracts';
33
import type { Web3Provider } from '@ethersproject/providers';
44
import {
55
safelyExecute,
6-
safelyExecuteWithTimeout,
76
toHex,
87
toChecksumHexAddress,
98
} from '@metamask/controller-utils';
@@ -22,7 +21,6 @@ import { SUPPORTED_NETWORKS_ACCOUNTS_API_V4 } from '../constants';
2221

2322
// Maximum number of account addresses that can be sent to the accounts API in a single request
2423
const ACCOUNTS_API_BATCH_SIZE = 50;
25-
const API_TIMEOUT_MS = 30000;
2624

2725
export type ChainIdHex = Hex;
2826
export type ChecksumAddress = Hex;
@@ -207,18 +205,11 @@ export class AccountsApiBalanceFetcher implements BalanceFetcher {
207205
async #fetchBalances(addrs: CaipAccountAddress[]) {
208206
// If we have fewer than or equal to the batch size, make a single request
209207
if (addrs.length <= ACCOUNTS_API_BATCH_SIZE) {
210-
const result = await safelyExecuteWithTimeout(
211-
async () => {
212-
const { balances } = await fetchMultiChainBalancesV4(
213-
{ accountAddresses: addrs },
214-
this.#platform,
215-
);
216-
return balances;
217-
},
218-
true,
219-
API_TIMEOUT_MS,
208+
const { balances } = await fetchMultiChainBalancesV4(
209+
{ accountAddresses: addrs },
210+
this.#platform,
220211
);
221-
return result || [];
212+
return balances;
222213
}
223214

224215
// Otherwise, batch the requests to respect the 50-element limit
@@ -233,18 +224,10 @@ export class AccountsApiBalanceFetcher implements BalanceFetcher {
233224
values: addrs,
234225
batchSize: ACCOUNTS_API_BATCH_SIZE,
235226
eachBatch: async (workingResult, batch) => {
236-
const result = await safelyExecuteWithTimeout(
237-
async () => {
238-
const { balances } = await fetchMultiChainBalancesV4(
239-
{ accountAddresses: batch },
240-
this.#platform,
241-
);
242-
return balances;
243-
},
244-
true, // logError
245-
API_TIMEOUT_MS,
227+
const { balances } = await fetchMultiChainBalancesV4(
228+
{ accountAddresses: batch },
229+
this.#platform,
246230
);
247-
const balances = result || [];
248231
return [...(workingResult || []), ...balances];
249232
},
250233
initialResult: [],

packages/assets-controllers/src/multicall.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ export const getTokenBalancesForMultipleAddresses = async (
10401040
// Note: Staking balances will be handled separately in two steps after token/native calls
10411041

10421042
// Execute all calls in batches
1043-
const maxCallsPerBatch = 100; // Limit calls per batch to avoid gas/size limits
1043+
const maxCallsPerBatch = 300; // Limit calls per batch to avoid gas/size limits
10441044
const allResults: Aggregate3Result[] = [];
10451045

10461046
await reduceInBatchesSerially<Aggregate3Call, void>({

0 commit comments

Comments
 (0)