Skip to content

Commit da1a1f6

Browse files
authored
Merge branch 'main' into latency_metrics_fix
2 parents db2e162 + bba4201 commit da1a1f6

File tree

16 files changed

+336
-71
lines changed

16 files changed

+336
-71
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 4918812dde60b8d0e24a7bded27d88f233968858..4e8018bce92b9e5d47fc40784409e16db22be615 100644
3+
--- a/dist/TokenBalancesController.cjs
4+
+++ b/dist/TokenBalancesController.cjs
5+
@@ -535,14 +535,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 f64d13f8de56631345a44e6ebb025e62e03f51bc..99aa7f27c574c94b26daa56091ac50d15281dd30 100644
27+
--- a/dist/TokenBalancesController.mjs
28+
+++ b/dist/TokenBalancesController.mjs
29+
@@ -531,14 +531,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+
});
14.6 KB
Binary file not shown.
-601 Bytes
Binary file not shown.

app/manifest/v3/_base.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
"notifications",
8585
"scripting",
8686
"storage",
87-
"tabs",
8887
"unlimitedStorage",
8988
"webRequest",
9089
"offscreen",

development/webpack/test/config.test.ts

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fs from 'node:fs';
2-
import { describe, it, after, mock } from 'node:test';
2+
import { describe, it, afterEach, mock } from 'node:test';
33
import assert from 'node:assert';
44
import { resolve } from 'node:path';
55
import { version } from '../../../package.json';
@@ -13,21 +13,29 @@ describe('./utils/config.ts', () => {
1313
// behaving
1414
describe('variables', () => {
1515
const originalReadFileSync = fs.readFileSync;
16-
function mockRc(env: Record<string, string> = {}) {
16+
function mockRc(
17+
env: Record<string, string> = {},
18+
prodEnv: Record<string, string> = {},
19+
) {
1720
mock.method(fs, 'readFileSync', (path: string, options: object) => {
21+
// mock the rc files as users might have customized it which may break our tests
1822
if (path === resolve(__dirname, '../../../.metamaskrc')) {
19-
// mock `.metamaskrc`, as users might have customized it which may
20-
// break our tests
2123
return `
22-
${Object.entries(env)
23-
.map(([key, value]) => `${key}=${value}`)
24-
.join('\n')}
25-
`;
24+
${Object.entries(env)
25+
.map(([key, value]) => `${key}=${value}`)
26+
.join('\n')}
27+
`;
28+
} else if (path === resolve(__dirname, '../../../.metamaskprodrc')) {
29+
return `
30+
${Object.entries(prodEnv)
31+
.map(([key, value]) => `${key}=${value}`)
32+
.join('\n')}
33+
`;
2634
}
2735
return originalReadFileSync(path, options);
2836
});
2937
}
30-
after(() => mock.restoreAll());
38+
afterEach(() => mock.restoreAll());
3139

3240
it('should return valid build variables for the default build', () => {
3341
const buildTypes = loadBuildTypesConfig();
@@ -49,17 +57,31 @@ ${Object.entries(env)
4957
);
5058
});
5159

52-
it('should prefer .metamaskrc variables over others', () => {
60+
it('should prefer .metamaskprodrc over .metamaskrc', () => {
5361
const buildTypes = loadBuildTypesConfig();
5462
const { args } = parseArgv([], buildTypes);
5563
const defaultVars = config.getVariables(args, buildTypes);
5664

5765
// verify the default value of the main build is false
5866
assert.strictEqual(defaultVars.variables.get('ALLOW_LOCAL_SNAPS'), false);
5967

60-
mockRc({
61-
ALLOW_LOCAL_SNAPS: 'true',
62-
});
68+
mockRc({ ALLOW_LOCAL_SNAPS: 'false' }, { ALLOW_LOCAL_SNAPS: 'true' });
69+
70+
const overrides = config.getVariables(args, buildTypes);
71+
72+
// verify the value of the main build is set to the value in .metamaskprodrc
73+
assert.strictEqual(overrides.variables.get('ALLOW_LOCAL_SNAPS'), true);
74+
});
75+
76+
it('should prefer .metamaskrc variables over builds.yml', () => {
77+
const buildTypes = loadBuildTypesConfig();
78+
const { args } = parseArgv([], buildTypes);
79+
const defaultVars = config.getVariables(args, buildTypes);
80+
81+
// verify the default value of the main build is false
82+
assert.strictEqual(defaultVars.variables.get('ALLOW_LOCAL_SNAPS'), false);
83+
84+
mockRc({ ALLOW_LOCAL_SNAPS: 'true' });
6385

6486
const overrides = config.getVariables(args, buildTypes);
6587

@@ -68,10 +90,8 @@ ${Object.entries(env)
6890
});
6991

7092
it('should return valid build variables for a non-default build', () => {
71-
mockRc({
72-
// required by the `beta` build type
73-
SEGMENT_BETA_WRITE_KEY: '.',
74-
});
93+
// required by the `beta` build type
94+
mockRc({ SEGMENT_BETA_WRITE_KEY: '.' });
7595
const buildTypes = loadBuildTypesConfig();
7696
const { args } = parseArgv(
7797
['--type', 'beta', '--test', '--env', 'production'],

development/webpack/utils/config.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,16 @@ export function getVariables(
155155
}
156156

157157
/**
158-
* Loads configuration variables from process.env, .metamaskrc, and build.yml.
158+
* Loads configuration variables from process.env, .metamaskprodrc, .metamaskrc, and build.yml.
159159
*
160160
* The order of precedence is:
161161
* 1. process.env
162-
* 2. .metamaskrc
163-
* 3. build.yml
162+
* 2. .metamaskprodrc
163+
* 3. .metamaskrc
164+
* 4. builds.yml
164165
*
165166
* i.e., if a variable is defined in `process.env`, it will take precedence over
166-
* the same variable defined in `.metamaskrc` or `build.yml`.
167+
* the same variable defined in `.metamaskprodrc`, `.metamaskrc` or `build.yml`.
167168
*
168169
* @param activeBuild
169170
* @param build
@@ -175,6 +176,7 @@ function loadConfigVars(
175176
{ env }: BuildTypesConfig,
176177
) {
177178
const definitions = loadEnv();
179+
addRc(definitions, join(__dirname, '../../../.metamaskprodrc'));
178180
addRc(definitions, join(__dirname, '../../../.metamaskrc'));
179181
addVars(activeBuild.env);
180182
addVars(env);

development/webpack/utils/plugins/ManifestPlugin/helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ export function transformManifest(
8282
}
8383
}
8484

85-
if (args.test && args.manifest_version === 2) {
86-
// test builds need "tabs" permission for switchToWindowWithTitle in MV2
85+
if (args.test) {
86+
// test builds need "tabs" permission for switchToWindowWithTitle
8787
transforms.push(addTabsPermission);
8888
}
8989

development/webpack/webpack.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ const cache = args.cache
8181
// `buildDependencies`
8282
config: [
8383
__filename,
84+
join(context, '../.metamaskprodrc'),
8485
join(context, '../.metamaskrc'),
8586
join(context, '../builds.yml'),
8687
browsersListPath,

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@
274274
"@metamask/address-book-controller": "^7.0.0",
275275
"@metamask/announcement-controller": "^8.0.0",
276276
"@metamask/approval-controller": "^8.0.0",
277-
"@metamask/assets-controllers": "^89.0.1",
277+
"@metamask/assets-controllers": "patch:@metamask/assets-controllers@npm%3A89.0.1#~/.yarn/patches/@metamask-assets-controllers-npm-89.0.1-02fa7acd54.patch",
278278
"@metamask/base-controller": "^9.0.0",
279279
"@metamask/bitcoin-wallet-snap": "^1.6.0",
280280
"@metamask/bridge-controller": "^61.0.0",
@@ -369,7 +369,7 @@
369369
"@metamask/streams": "^0.4.0",
370370
"@metamask/subscription-controller": "^4.2.2",
371371
"@metamask/transaction-controller": "^61.2.0",
372-
"@metamask/tron-wallet-snap": "^1.9.1",
372+
"@metamask/tron-wallet-snap": "^1.10.0",
373373
"@metamask/user-operation-controller": "^40.0.0",
374374
"@metamask/utils": "^11.4.2",
375375
"@ngraveio/bc-ur": "^1.1.13",

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 () => {
@@ -105,4 +112,35 @@ describe('useDappSwapUSDValues', () => {
105112
),
106113
).toBe('0.00');
107114
});
115+
116+
it('return correct fiat rates token on Polygon', async () => {
117+
jest.spyOn(Utils, 'fetchTokenExchangeRates').mockResolvedValue({
118+
'0x0000000000000000000000000000000000001010': 4052.27,
119+
'0x833589fcd6edb6e08f4c7c32d4f71b54bda02913': 0.999804,
120+
});
121+
jest.spyOn(TokenUtils, 'fetchAllTokenDetails').mockResolvedValue({
122+
'0x0000000000000000000000000000000000000000': {
123+
symbol: 'POL',
124+
decimals: '18',
125+
} as TokenStandAndDetails,
126+
'0x833589fcd6edb6e08f4c7c32d4f71b54bda02913': {
127+
symbol: 'USDT',
128+
decimals: '6',
129+
} as TokenStandAndDetails,
130+
});
131+
132+
const result = await runHook(
133+
[
134+
'0x0000000000000000000000000000000000000000',
135+
'0x833589fcd6edb6e08f4c7c32d4f71b54bda02913',
136+
],
137+
{ ...mockSwapConfirmation, chainId: CHAIN_IDS.POLYGON } as Confirmation,
138+
);
139+
140+
expect(result.fiatRates).toEqual({
141+
'0x0000000000000000000000000000000000000000': 4052.27,
142+
'0x0000000000000000000000000000000000001010': 4052.27,
143+
'0x833589fcd6edb6e08f4c7c32d4f71b54bda02913': 0.999804,
144+
});
145+
});
108146
});

0 commit comments

Comments
 (0)