Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/assets-controllers/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions packages/assets-controllers/src/TokenBalancesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type ChecksumAddress = Hex;
export type ProcessedBalance = {
success: boolean;
value?: BN;
account: ChecksumAddress;
account: ChecksumAddress | string;
token: ChecksumAddress;
chainId: ChainIdHex;
};
Expand Down Expand Up @@ -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;
Expand All @@ -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,
},
Expand Down
Loading