Skip to content

Commit c2f24fd

Browse files
authored
Merge branch 'develop' into improv/account_syncing_various_updates
2 parents d3e1925 + 4cfd133 commit c2f24fd

29 files changed

+1642
-49
lines changed

app/_locales/en/messages.json

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

privacy-snapshot.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,13 @@
5252
"security-alerts.api.cx.metamask.io",
5353
"security-alerts.dev-api.cx.metamask.io",
5454
"sentry.io",
55+
"sepolia.infura.io",
5556
"snaps.metamask.io",
5657
"sourcify.dev",
5758
"start.metamask.io",
5859
"static.cx.metamask.io",
59-
"support.metamask.io",
6060
"support.metamask-institutional.io",
61+
"support.metamask.io",
6162
"swap.api.cx.metamask.io",
6263
"test.metamask-phishing.io",
6364
"token.api.cx.metamask.io",

test/data/mock-send-state.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"currentLocale": "en"
6464
},
6565
"metamask": {
66+
"accountsByChainId": {},
6667
"ipfsGateway": "",
6768
"dismissSeedBackUpReminder": false,
6869
"usePhishDetect": true,
@@ -131,7 +132,8 @@
131132
"preferences": {
132133
"hideZeroBalanceTokens": false,
133134
"showFiatInTestnets": false,
134-
"showTestNetworks": true
135+
"showTestNetworks": true,
136+
"tokenNetworkFilter": {}
135137
},
136138
"seedPhraseBackedUp": null,
137139
"ensResolutionsByAddress": {},

test/data/mock-state.json

+1
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@
379379
"showNativeTokenAsMainBalance": true,
380380
"showTestNetworks": true,
381381
"smartTransactionsOptInStatus": true,
382+
"tokenNetworkFilter": {},
382383
"tokenSortConfig": {
383384
"key": "tokenFiatAmount",
384385
"order": "dsc",

test/e2e/default-fixture.js

+1
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ function defaultFixture(inputChainId = CHAIN_IDS.LOCALHOST) {
225225
sortCallback: 'stringNumeric',
226226
},
227227
shouldShowAggregatedBalancePopover: true,
228+
tokenNetworkFilter: {},
228229
},
229230
selectedAddress: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
230231
theme: 'light',

test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-background-state.json

+1
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@
237237
"redesignedConfirmationsEnabled": true,
238238
"redesignedTransactionsEnabled": "boolean",
239239
"tokenSortConfig": "object",
240+
"tokenNetworkFilter": "object",
240241
"shouldShowAggregatedBalancePopover": "boolean"
241242
},
242243
"ipfsGateway": "string",

test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-ui-state.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"redesignedConfirmationsEnabled": true,
3939
"redesignedTransactionsEnabled": "boolean",
4040
"tokenSortConfig": "object",
41-
"showMultiRpcModal": "boolean",
41+
"tokenNetworkFilter": "object",
4242
"shouldShowAggregatedBalancePopover": "boolean"
4343
},
4444
"firstTimeFlowType": "import",

test/e2e/tests/metrics/state-snapshots/errors-before-init-opt-in-background-state.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@
119119
"showConfirmationAdvancedDetails": false,
120120
"tokenSortConfig": "object",
121121
"showMultiRpcModal": "boolean",
122-
"shouldShowAggregatedBalancePopover": "boolean"
122+
"shouldShowAggregatedBalancePopover": "boolean",
123+
"tokenNetworkFilter": "object"
123124
},
124125
"selectedAddress": "string",
125126
"theme": "light",

test/e2e/tests/metrics/state-snapshots/errors-before-init-opt-in-ui-state.json

+1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
"isRedesignedConfirmationsDeveloperEnabled": "boolean",
136136
"showConfirmationAdvancedDetails": false,
137137
"tokenSortConfig": "object",
138+
"tokenNetworkFilter": "object",
138139
"showMultiRpcModal": "boolean",
139140
"shouldShowAggregatedBalancePopover": "boolean"
140141
},

test/e2e/tests/settings/account-token-list.spec.js

+44
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,38 @@ const {
55
logInWithBalanceValidation,
66
unlockWallet,
77
} = require('../../helpers');
8+
const {
9+
switchToNetworkFlow,
10+
} = require('../../page-objects/flows/network.flow');
811

12+
const { mockServerJsonRpc } = require('../ppom/mocks/mock-server-json-rpc');
913
const FixtureBuilder = require('../../fixture-builder');
1014

15+
const infuraSepoliaUrl =
16+
'https://sepolia.infura.io/v3/00000000000000000000000000000000';
17+
18+
async function mockInfura(mockServer) {
19+
await mockServerJsonRpc(mockServer, [
20+
['eth_blockNumber'],
21+
['eth_getBlockByNumber'],
22+
]);
23+
await mockServer
24+
.forPost(infuraSepoliaUrl)
25+
.withJsonBodyIncluding({ method: 'eth_getBalance' })
26+
.thenCallback(() => ({
27+
statusCode: 200,
28+
json: {
29+
jsonrpc: '2.0',
30+
id: '6857940763865360',
31+
result: '0x15af1d78b58c40000',
32+
},
33+
}));
34+
}
35+
36+
async function mockInfuraResponses(mockServer) {
37+
await mockInfura(mockServer);
38+
}
39+
1140
describe('Settings', function () {
1241
it('Should match the value of token list item and account list item for eth conversion', async function () {
1342
await withFixtures(
@@ -49,6 +78,7 @@ describe('Settings', function () {
4978
.build(),
5079
ganacheOptions: defaultGanacheOptions,
5180
title: this.test.fullTitle(),
81+
testSpecificMock: mockInfuraResponses,
5282
},
5383
async ({ driver }) => {
5484
await unlockWallet(driver);
@@ -63,6 +93,20 @@ describe('Settings', function () {
6393
);
6494
await driver.delay(1000);
6595
assert.equal(await tokenListAmount.getText(), '$42,500.00\nUSD');
96+
97+
// switch to Sepolia
98+
// the account list item used to always show account.balance as long as its EVM network.
99+
// Now we are showing aggregated fiat balance on non testnetworks; but if it is a testnetwork we will show account.balance.
100+
// The current test was running initially on localhost
101+
// which is not a testnetwork resulting in the code trying to calculate the aggregated total fiat balance which shows 0.00$
102+
// If this test switches to mainnet then switches back to localhost; the test will pass because switching to mainnet
103+
// will make the code calculate the aggregate fiat balance on mainnet+Linea mainnet and because this account in this test
104+
// has 42,500.00 native Eth on mainnet then the aggregated total fiat would be 42,500.00. When the user switches back to localhost
105+
// it will show the total that the test is expecting.
106+
107+
// I think we can slightly modify this test to switch to Sepolia network before checking the account List item value
108+
await switchToNetworkFlow(driver, 'Sepolia');
109+
66110
await driver.clickElement('[data-testid="account-menu-icon"]');
67111
const accountTokenValue = await driver.waitForSelector(
68112
'.multichain-account-list-item .multichain-account-list-item__asset',

test/integration/data/integration-init-state.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,8 @@
784784
"smartTransactionsOptInStatus": true,
785785
"petnamesEnabled": false,
786786
"showConfirmationAdvancedDetails": false,
787-
"showMultiRpcModal": false
787+
"showMultiRpcModal": false,
788+
"tokenNetworkFilter": {}
788789
},
789790
"preventPollingOnNetworkRestart": true,
790791
"previousAppVersion": "11.14.4",

ui/components/app/assets/asset-list/asset-list-control-bar/asset-list-control-bar.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useRef, useState } from 'react';
1+
import React, { useMemo, useRef, useState } from 'react';
22
import { useSelector } from 'react-redux';
33
import { getCurrentNetwork, getPreferences } from '../../../../../selectors';
44
import {
@@ -28,6 +28,7 @@ import {
2828
ENVIRONMENT_TYPE_POPUP,
2929
} from '../../../../../../shared/constants/app';
3030
import NetworkFilter from '../network-filter';
31+
import { TEST_CHAINS } from '../../../../../../shared/constants/network';
3132

3233
type AssetListControlBarProps = {
3334
showTokensLinks?: boolean;
@@ -43,6 +44,9 @@ const AssetListControlBar = ({ showTokensLinks }: AssetListControlBarProps) => {
4344
useState(false);
4445

4546
const allNetworksFilterShown = Object.keys(tokenNetworkFilter ?? {}).length;
47+
const isTestNetwork = useMemo(() => {
48+
return (TEST_CHAINS as string[]).includes(currentNetwork.chainId);
49+
}, [currentNetwork.chainId, TEST_CHAINS]);
4650

4751
const windowType = getEnvironmentType();
4852
const isFullScreen =
@@ -84,6 +88,7 @@ const AssetListControlBar = ({ showTokensLinks }: AssetListControlBarProps) => {
8488
className="asset-list-control-bar__button"
8589
onClick={toggleNetworkFilterPopover}
8690
size={ButtonBaseSize.Sm}
91+
disabled={isTestNetwork}
8792
endIconName={IconName.ArrowDown}
8893
backgroundColor={
8994
isNetworkFilterPopoverOpen

ui/components/app/assets/asset-list/network-filter/network-filter.tsx

+50-18
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ import { setTokenNetworkFilter } from '../../../../../store/actions';
44
import {
55
getCurrentChainId,
66
getCurrentNetwork,
7-
getIsTestnet,
87
getPreferences,
98
getSelectedInternalAccount,
109
getShouldHideZeroBalanceTokens,
1110
getNetworkConfigurationsByChainId,
11+
getChainIdsToPoll,
1212
} from '../../../../../selectors';
1313
import { useI18nContext } from '../../../../../hooks/useI18nContext';
1414
import { SelectableListItem } from '../sort-control/sort-control';
15-
import { useAccountTotalFiatBalance } from '../../../../../hooks/useAccountTotalFiatBalance';
1615
import { Text } from '../../../../component-library/text/text';
1716
import {
1817
Display,
@@ -24,6 +23,8 @@ import { Box } from '../../../../component-library/box/box';
2423
import { AvatarNetwork } from '../../../../component-library';
2524
import UserPreferencedCurrencyDisplay from '../../../user-preferenced-currency-display';
2625
import { CHAIN_ID_TO_NETWORK_IMAGE_URL_MAP } from '../../../../../../shared/constants/network';
26+
import { useGetFormattedTokensPerChain } from '../../../../../hooks/useGetFormattedTokensPerChain';
27+
import { useAccountTotalCrossChainFiatBalance } from '../../../../../hooks/useAccountTotalCrossChainFiatBalance';
2728

2829
type SortControlProps = {
2930
handleClose: () => void;
@@ -36,15 +37,35 @@ const NetworkFilter = ({ handleClose }: SortControlProps) => {
3637
const selectedAccount = useSelector(getSelectedInternalAccount);
3738
const currentNetwork = useSelector(getCurrentNetwork);
3839
const allNetworks = useSelector(getNetworkConfigurationsByChainId);
39-
const isTestnet = useSelector(getIsTestnet);
40-
const { tokenNetworkFilter, showNativeTokenAsMainBalance } =
41-
useSelector(getPreferences);
40+
const { tokenNetworkFilter } = useSelector(getPreferences);
4241
const shouldHideZeroBalanceTokens = useSelector(
4342
getShouldHideZeroBalanceTokens,
4443
);
45-
44+
const allChainIDs = useSelector(getChainIdsToPoll);
45+
const { formattedTokensWithBalancesPerChain } = useGetFormattedTokensPerChain(
46+
selectedAccount,
47+
shouldHideZeroBalanceTokens,
48+
true, // true to get formattedTokensWithBalancesPerChain for the current chain
49+
allChainIDs,
50+
);
4651
const { totalFiatBalance: selectedAccountBalance } =
47-
useAccountTotalFiatBalance(selectedAccount, shouldHideZeroBalanceTokens);
52+
useAccountTotalCrossChainFiatBalance(
53+
selectedAccount,
54+
formattedTokensWithBalancesPerChain,
55+
);
56+
57+
const { formattedTokensWithBalancesPerChain: formattedTokensForAllNetworks } =
58+
useGetFormattedTokensPerChain(
59+
selectedAccount,
60+
shouldHideZeroBalanceTokens,
61+
false, // false to get the value for all networks
62+
allChainIDs,
63+
);
64+
const { totalFiatBalance: selectedAccountBalanceForAllNetworks } =
65+
useAccountTotalCrossChainFiatBalance(
66+
selectedAccount,
67+
formattedTokensForAllNetworks,
68+
);
4869

4970
// TODO: fetch balances across networks
5071
// const multiNetworkAccountBalance = useMultichainAccountBalance()
@@ -78,7 +99,15 @@ const NetworkFilter = ({ handleClose }: SortControlProps) => {
7899
color={TextColor.textDefault}
79100
>
80101
{/* TODO: Should query cross chain account balance */}
81-
$1,000.00
102+
103+
<UserPreferencedCurrencyDisplay
104+
value={selectedAccountBalanceForAllNetworks}
105+
type="PRIMARY"
106+
ethNumberOfDecimals={4}
107+
hideTitle
108+
showFiat
109+
isAggregatedFiatOverviewBalance
110+
/>
82111
</Text>
83112
</Box>
84113
<Box display={Display.Flex}>
@@ -120,16 +149,19 @@ const NetworkFilter = ({ handleClose }: SortControlProps) => {
120149
>
121150
{t('currentNetwork')}
122151
</Text>
123-
<UserPreferencedCurrencyDisplay
124-
value={selectedAccountBalance}
125-
type="PRIMARY"
126-
ethNumberOfDecimals={4}
127-
hideTitle
128-
shouldCheckShowNativeToken
129-
isAggregatedFiatOverviewBalance={
130-
!showNativeTokenAsMainBalance && !isTestnet
131-
}
132-
/>
152+
<Text
153+
variant={TextVariant.bodySmMedium}
154+
color={TextColor.textAlternative}
155+
>
156+
<UserPreferencedCurrencyDisplay
157+
value={selectedAccountBalance}
158+
type="PRIMARY"
159+
ethNumberOfDecimals={4}
160+
hideTitle
161+
showFiat
162+
isAggregatedFiatOverviewBalance
163+
/>
164+
</Text>
133165
</Box>
134166
<AvatarNetwork
135167
name="Current"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`AggregatedPercentageOverviewCrossChains render renders correctly 1`] = `
4+
<div>
5+
<div
6+
class="mm-box mm-box--display-flex"
7+
>
8+
<p
9+
class="mm-box mm-text mm-text--body-md-medium mm-text--ellipsis mm-box--color-success-default"
10+
data-testid="aggregated-value-change"
11+
style="white-space: pre;"
12+
>
13+
+$0.22
14+
</p>
15+
<p
16+
class="mm-box mm-text mm-text--body-md-medium mm-text--ellipsis mm-box--color-success-default"
17+
data-testid="aggregated-percentage-change"
18+
>
19+
(+0.08%)
20+
</p>
21+
</div>
22+
</div>
23+
`;

0 commit comments

Comments
 (0)