Skip to content

Commit 9dcb499

Browse files
Merge pull request #38086 from MetaMask/release/13.10.1
release: 13.10.1
2 parents 207b2f6 + e3a108b commit 9dcb499

File tree

11 files changed

+182
-17
lines changed

11 files changed

+182
-17
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
diff --git a/dist/TokenBalancesController.cjs b/dist/TokenBalancesController.cjs
2+
index 24c2b2d22d3678352fd2ea4932181f3f11ffe41a..e63d3bcd80d68391d713394ec7f340b80fd8b79d 100644
3+
--- a/dist/TokenBalancesController.cjs
4+
+++ b/dist/TokenBalancesController.cjs
5+
@@ -527,14 +527,16 @@ class TokenBalancesController extends (0, polling_controller_1.StaticIntervalPol
6+
}
7+
// Update with actual fetched balances only if the value has changed
8+
aggregated.forEach(({ success, value, account, token, chainId }) => {
9+
- var _a, _b, _c;
10+
+ var _a, _b;
11+
if (success && value !== undefined) {
12+
+ // Ensure all accounts we add/update are in lower-case
13+
+ const lowerCaseAccount = account.toLowerCase();
14+
const newBalance = (0, controller_utils_1.toHex)(value);
15+
const tokenAddress = checksum(token);
16+
- const currentBalance = d.tokenBalances[account]?.[chainId]?.[tokenAddress];
17+
+ const currentBalance = d.tokenBalances[lowerCaseAccount]?.[chainId]?.[tokenAddress];
18+
// Only update if the balance has actually changed
19+
if (currentBalance !== newBalance) {
20+
- ((_c = ((_a = d.tokenBalances)[_b = account] ?? (_a[_b] = {})))[chainId] ?? (_c[chainId] = {}))[tokenAddress] = newBalance;
21+
+ ((_b = ((_a = d.tokenBalances)[lowerCaseAccount] ?? (_a[lowerCaseAccount] = {})))[chainId] ?? (_b[chainId] = {}))[tokenAddress] = newBalance;
22+
}
23+
}
24+
});
25+
diff --git a/dist/TokenBalancesController.mjs b/dist/TokenBalancesController.mjs
26+
index 420934fb16ed6151b5b80fb7be04f81352b4aaf4..d735379adcaf77cbd46b4659f9bfd32046abebdf 100644
27+
--- a/dist/TokenBalancesController.mjs
28+
+++ b/dist/TokenBalancesController.mjs
29+
@@ -523,14 +523,16 @@ export class TokenBalancesController extends StaticIntervalPollingController() {
30+
}
31+
// Update with actual fetched balances only if the value has changed
32+
aggregated.forEach(({ success, value, account, token, chainId }) => {
33+
- var _a, _b, _c;
34+
+ var _a, _b;
35+
if (success && value !== undefined) {
36+
+ // Ensure all accounts we add/update are in lower-case
37+
+ const lowerCaseAccount = account.toLowerCase();
38+
const newBalance = toHex(value);
39+
const tokenAddress = checksum(token);
40+
- const currentBalance = d.tokenBalances[account]?.[chainId]?.[tokenAddress];
41+
+ const currentBalance = d.tokenBalances[lowerCaseAccount]?.[chainId]?.[tokenAddress];
42+
// Only update if the balance has actually changed
43+
if (currentBalance !== newBalance) {
44+
- ((_c = ((_a = d.tokenBalances)[_b = account] ?? (_a[_b] = {})))[chainId] ?? (_c[chainId] = {}))[tokenAddress] = newBalance;
45+
+ ((_b = ((_a = d.tokenBalances)[lowerCaseAccount] ?? (_a[lowerCaseAccount] = {})))[chainId] ?? (_b[chainId] = {}))[tokenAddress] = newBalance;
46+
}
47+
}
48+
});

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [13.10.1]
11+
12+
### Fixed
13+
14+
- Prevents token list from fetching balances for all accounts (#38065)
15+
- Fixes dapp-swap comparison fiat rate fetching for native tokens (#37980)
16+
- Fixes dapp-swap fix conversion rate for pol native token (#38102)
17+
- Removes unnecessary extension permission (#38075)
18+
- Fixes missing native token balances in wallet balance (#38126)
19+
1020
## [13.10.0]
1121

1222
### Added
@@ -1217,7 +1227,8 @@ authorized by the user.` error until the user fully revoked dapp
12171227
- This changelog was split off with 12.22.0
12181228
- All older changes can be found in [docs/CHANGELOG_older.md](https://github.com/MetaMask/metamask-extension/blob/main/docs/CHANGELOG_older.md)
12191229

1220-
[Unreleased]: https://github.com/MetaMask/metamask-extension/compare/v13.10.0...HEAD
1230+
[Unreleased]: https://github.com/MetaMask/metamask-extension/compare/v13.10.1...HEAD
1231+
[13.10.1]: https://github.com/MetaMask/metamask-extension/compare/v13.10.0...v13.10.1
12211232
[13.10.0]: https://github.com/MetaMask/metamask-extension/compare/v13.9.0...v13.10.0
12221233
[13.9.0]: https://github.com/MetaMask/metamask-extension/compare/v13.8.0...v13.9.0
12231234
[13.8.0]: https://github.com/MetaMask/metamask-extension/compare/v13.7.0...v13.8.0

app/manifest/v3/_base.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@
7777
"notifications",
7878
"scripting",
7979
"storage",
80-
"tabs",
8180
"unlimitedStorage",
8281
"webRequest",
8382
"offscreen",

app/scripts/controller-init/token-balances-controller-init.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ describe('TokenBalancesControllerInit', () => {
7272
queryMultipleAccounts: true,
7373
allowExternalServices: expect.any(Function),
7474
accountsApiChainIds: expect.any(Function),
75+
platform: 'extension',
7576
});
7677
});
7778
});

app/scripts/controller-init/token-balances-controller-init.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export const TokenBalancesControllerInit: ControllerInitFunction<
3333
? (featureFlagForAccountApiBalances as `0x${string}`[])
3434
: [];
3535
},
36+
platform: 'extension',
3637
});
3738

3839
return {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "metamask-crx",
3-
"version": "13.10.0",
3+
"version": "13.10.1",
44
"private": true,
55
"repository": {
66
"type": "git",
@@ -271,7 +271,7 @@
271271
"@metamask/address-book-controller": "^7.0.0",
272272
"@metamask/announcement-controller": "^8.0.0",
273273
"@metamask/approval-controller": "^8.0.0",
274-
"@metamask/assets-controllers": "^88.0.0",
274+
"@metamask/assets-controllers": "patch:@metamask/assets-controllers@npm%3A88.0.0#~/.yarn/patches/@metamask-assets-controllers-npm-88.0.0-3dfc0ab8f1.patch",
275275
"@metamask/base-controller": "^9.0.0",
276276
"@metamask/bitcoin-wallet-snap": "^1.6.0",
277277
"@metamask/bridge-controller": "^60.1.0",

ui/hooks/useAssetsUpdateAllAccountBalances.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ describe('useAssetsUpdateAllAccountBalances', () => {
130130
expect(mockDispatch).toHaveBeenCalledTimes(1);
131131
expect(mockUpdateBalancesFoAccounts).toHaveBeenCalledWith(
132132
initialChainIds,
133-
true,
133+
false,
134134
);
135135

136136
// Update chain IDs and rerender
@@ -140,7 +140,7 @@ describe('useAssetsUpdateAllAccountBalances', () => {
140140
expect(mockDispatch).toHaveBeenCalledTimes(2);
141141
expect(mockUpdateBalancesFoAccounts).toHaveBeenCalledWith(
142142
updatedChainIds,
143-
true,
143+
false,
144144
);
145145
});
146146

ui/hooks/useAssetsUpdateAllAccountBalances.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const useAssetsUpdateAllAccountBalances = (): {
3737
// Update balance state for ALL accounts across all enabled EVM chains
3838
// TokenBalancesController is configured with queryMultipleAccounts: true
3939
// so this will update balances for all accounts, not just the selected one
40-
await dispatch(updateBalancesFoAccounts(enabledChainIds, true));
40+
await dispatch(updateBalancesFoAccounts(enabledChainIds, false));
4141
}
4242
} catch (error) {
4343
console.warn('Error updating balances state for all accounts', error);

ui/pages/confirmations/hooks/transactions/dapp-swap-comparison/useDappSwapUSDValues.test.ts

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { BigNumber } from 'bignumber.js';
2+
import { CHAIN_IDS } from '@metamask/transaction-controller';
3+
import { Hex } from '@metamask/utils';
24
import { act } from '@testing-library/react';
35

46
import { getMockConfirmStateForTransaction } from '../../../../../../test/data/confirmations/helper';
@@ -10,18 +12,23 @@ import * as TokenUtils from '../../../utils/token';
1012
import { Confirmation } from '../../../types/confirm';
1113
import { useDappSwapUSDValues } from './useDappSwapUSDValues';
1214

13-
async function runHook() {
15+
async function runHook(
16+
tokenAddresses?: Hex[],
17+
mockConfirmation?: Confirmation,
18+
) {
1419
const response = renderHookWithConfirmContextProvider(
1520
() =>
1621
useDappSwapUSDValues({
17-
tokenAddresses: [
22+
tokenAddresses: tokenAddresses ?? [
1823
'0x0000000000000000000000000000000000000000',
1924
'0x833589fcd6edb6e08f4c7c32d4f71b54bda02913',
2025
'0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9',
2126
],
2227
destTokenAddress: '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913',
2328
}),
24-
getMockConfirmStateForTransaction(mockSwapConfirmation as Confirmation),
29+
getMockConfirmStateForTransaction(
30+
mockConfirmation ?? (mockSwapConfirmation as Confirmation),
31+
),
2532
);
2633

2734
await act(async () => {
@@ -98,4 +105,35 @@ describe('useDappSwapUSDValues', () => {
98105
'0xfdcc3dd6671eab0709a4c0f3f53de9a333d80798': 1,
99106
});
100107
});
108+
109+
it('return correct fiat rates token on Polygon', async () => {
110+
jest.spyOn(Utils, 'fetchTokenExchangeRates').mockResolvedValue({
111+
'0x0000000000000000000000000000000000001010': 4052.27,
112+
'0x833589fcd6edb6e08f4c7c32d4f71b54bda02913': 0.999804,
113+
});
114+
jest.spyOn(TokenUtils, 'fetchAllTokenDetails').mockResolvedValue({
115+
'0x0000000000000000000000000000000000000000': {
116+
symbol: 'POL',
117+
decimals: '18',
118+
} as TokenStandAndDetails,
119+
'0x833589fcd6edb6e08f4c7c32d4f71b54bda02913': {
120+
symbol: 'USDT',
121+
decimals: '6',
122+
} as TokenStandAndDetails,
123+
});
124+
125+
const result = await runHook(
126+
[
127+
'0x0000000000000000000000000000000000000000',
128+
'0x833589fcd6edb6e08f4c7c32d4f71b54bda02913',
129+
],
130+
{ ...mockSwapConfirmation, chainId: CHAIN_IDS.POLYGON } as Confirmation,
131+
);
132+
133+
expect(result.fiatRates).toEqual({
134+
'0x0000000000000000000000000000000000000000': 4052.27,
135+
'0x0000000000000000000000000000000000001010': 4052.27,
136+
'0x833589fcd6edb6e08f4c7c32d4f71b54bda02913': 0.999804,
137+
});
138+
});
101139
});

ui/pages/confirmations/hooks/transactions/dapp-swap-comparison/useDappSwapUSDValues.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
getNativeAssetForChainId,
66
isNativeAddress,
77
} from '@metamask/bridge-controller';
8-
import { TransactionMeta } from '@metamask/transaction-controller';
8+
import { CHAIN_IDS, TransactionMeta } from '@metamask/transaction-controller';
99
import { useCallback } from 'react';
1010

1111
import { TokenStandAndDetails } from '../../../../../store/actions';
@@ -15,6 +15,8 @@ import { fetchAllTokenDetails } from '../../../utils/token';
1515
import { getTokenValueFromRecord } from '../../../utils/dapp-swap-comparison-utils';
1616
import { useConfirmContext } from '../../../context/confirm';
1717

18+
const POLYGON_NATIVE_ASSET = '0x0000000000000000000000000000000000001010';
19+
1820
export function useDappSwapUSDValues({
1921
tokenAddresses = [],
2022
destTokenAddress,
@@ -30,10 +32,23 @@ export function useDappSwapUSDValues({
3032

3133
const { value: fiatRates, pending: fiatRatesPending } = useAsyncResult<
3234
Record<Hex, number | undefined>
33-
>(
34-
() => fetchTokenExchangeRates('usd', tokenAddresses as Hex[], chainId),
35-
[chainId, tokenAddresses?.length],
36-
);
35+
>(async () => {
36+
const addresses = tokenAddresses.filter(
37+
(tokenAddress) => !isNativeAddress(tokenAddress),
38+
);
39+
const exchangeRates = await fetchTokenExchangeRates(
40+
'usd',
41+
addresses as Hex[],
42+
chainId,
43+
);
44+
45+
if (chainId === CHAIN_IDS.POLYGON) {
46+
const nativeAddress = getNativeAssetForChainId(chainId).address;
47+
exchangeRates[nativeAddress] = exchangeRates[POLYGON_NATIVE_ASSET];
48+
}
49+
50+
return exchangeRates;
51+
}, [chainId, tokenAddresses?.length]);
3752

3853
const { value: tokenDetails, pending: tokenDetailsPending } = useAsyncResult<
3954
Record<Hex, TokenStandAndDetails>

0 commit comments

Comments
 (0)