diff --git a/packages/assets-controllers/CHANGELOG.md b/packages/assets-controllers/CHANGELOG.md index 16448c727cb..fe4c0ea9ffa 100644 --- a/packages/assets-controllers/CHANGELOG.md +++ b/packages/assets-controllers/CHANGELOG.md @@ -33,6 +33,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Reduce NFT detection API calls by 83% (from 6 calls to 1 call per 100 tokens) by eliminating collection endpoint requests - Remove unused collection metadata fields: `contractDeployedAt`, `creator`, and `topBid` +### Fixed + +- Fix address format compatibility between `TokenBalancesController` and `AccountTrackerController` in `AccountsApiBalanceFetcher` ([#6812](https://github.com/MetaMask/core/pull/6812)) + ## [79.0.1] ### Changed diff --git a/packages/assets-controllers/src/TokenBalancesController.ts b/packages/assets-controllers/src/TokenBalancesController.ts index c91f88b4b3e..e8d58d6bddc 100644 --- a/packages/assets-controllers/src/TokenBalancesController.ts +++ b/packages/assets-controllers/src/TokenBalancesController.ts @@ -734,12 +734,14 @@ export class TokenBalancesController extends StaticIntervalPollingController<{ const newBalance = toHex(value); const tokenAddress = checksum(token); const currentBalance = - d.tokenBalances[account]?.[chainId]?.[tokenAddress]; + d.tokenBalances[account as ChecksumAddress]?.[chainId]?.[ + tokenAddress + ]; // Only update if the balance has actually changed if (currentBalance !== newBalance) { - ((d.tokenBalances[account] ??= {})[chainId] ??= {})[tokenAddress] = - newBalance; + ((d.tokenBalances[account as ChecksumAddress] ??= {})[chainId] ??= + {})[tokenAddress] = newBalance; } } }); diff --git a/packages/assets-controllers/src/multi-chain-accounts-service/api-balance-fetcher.ts b/packages/assets-controllers/src/multi-chain-accounts-service/api-balance-fetcher.ts index a2248fac048..d03005f9ce8 100644 --- a/packages/assets-controllers/src/multi-chain-accounts-service/api-balance-fetcher.ts +++ b/packages/assets-controllers/src/multi-chain-accounts-service/api-balance-fetcher.ts @@ -28,7 +28,7 @@ export type ChecksumAddress = Hex; export type ProcessedBalance = { success: boolean; value?: BN; - account: ChecksumAddress; + account: ChecksumAddress | string; token: ChecksumAddress; chainId: ChainIdHex; }; @@ -302,6 +302,11 @@ export class AccountsApiBalanceFetcher implements BalanceFetcher { } const account = checksum(addressPart); const token = checksum(b.address); + // Use original address for zero address tokens, checksummed for others + // TODO: this is a hack to get the correct account address type but needs to be fixed + // by mgrating tokenBalancesController to checksum addresses + const finalAccount: ChecksumAddress | string = + token === ZERO_ADDRESS ? account : addressPart; const chainId = toHex(b.chainId) as ChainIdHex; let value: BN | undefined; @@ -326,14 +331,14 @@ export class AccountsApiBalanceFetcher implements BalanceFetcher { // Track native balances for later if (token === ZERO_ADDRESS && value !== undefined) { - nativeBalancesFromAPI.set(`${account}-${chainId}`, value); + nativeBalancesFromAPI.set(`${finalAccount}-${chainId}`, value); } return [ { success: value !== undefined, value, - account, + account: finalAccount, token, chainId, },