Skip to content

Commit cb14ec5

Browse files
NidhiKJhadarkwing
andauthored
UX: Show same balance on eth overview and account list item (#23059)
This PR is to ensure total balance shows up for both eth overview and account list item ## **Related issues** Fixes: #23058 ## **Manual testing steps** 1. Go to Eth Overview section, on a non test network. Look at the eth overview balance 2. Account list item should show same balance as eth overview 3. Total balance logic works only for NON-TEST Networks ## **Screenshots/Recordings** ### **Before** https://github.com/MetaMask/metamask-extension/assets/39872794/aaab32c5-cbb8-43e2-b78d-6d3ee71535ee ### **After** https://github.com/MetaMask/metamask-extension/assets/39872794/54d61617-33e1-4b99-a699-cfd372d21b72 ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [x] I've clearly explained what problem this PR is solving and how it is solved. - [x] I've linked related issues - [x] I've included manual testing steps - [x] I've included screenshots/recordings if applicable - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. - [x] I’ve properly set the pull request status: - [ ] In case it's not yet "ready for review", I've set it to "draft". - [ ] In case it's "ready for review", I've changed it from "draft" to "non-draft". ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --------- Co-authored-by: David Walsh <davidwalsh83@gmail.com>
1 parent 9a4b132 commit cb14ec5

File tree

6 files changed

+47
-34
lines changed

6 files changed

+47
-34
lines changed

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

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,24 @@ const { strict: assert } = require('assert');
22
const {
33
withFixtures,
44
defaultGanacheOptions,
5-
unlockWallet,
5+
logInWithBalanceValidation,
66
} = require('../helpers');
7+
78
const FixtureBuilder = require('../fixture-builder');
8-
const { SMART_CONTRACTS } = require('../seeder/smart-contracts');
99

1010
describe('Settings', function () {
11-
const smartContract = SMART_CONTRACTS.ERC1155;
1211
it('Should match the value of token list item and account list item for eth conversion', async function () {
1312
await withFixtures(
1413
{
15-
dapp: true,
1614
fixtures: new FixtureBuilder().build(),
17-
defaultGanacheOptions,
18-
smartContract,
15+
ganacheOptions: defaultGanacheOptions,
1916
title: this.test.fullTitle(),
2017
},
21-
async ({ driver }) => {
22-
await unlockWallet(driver);
18+
async ({ driver, ganacheServer }) => {
19+
await logInWithBalanceValidation(driver, ganacheServer);
2320

2421
await driver.clickElement('[data-testid="home__asset-tab"]');
25-
const tokenValue = '0 ETH';
22+
const tokenValue = '25 ETH';
2623
const tokenListAmount = await driver.findElement(
2724
'[data-testid="multichain-token-list-item-value"]',
2825
);
@@ -33,22 +30,20 @@ describe('Settings', function () {
3330
'.multichain-account-list-item .multichain-account-list-item__avatar-currency .currency-display-component__text',
3431
);
3532

36-
assert.equal(await accountTokenValue.getText(), '0', 'ETH');
33+
assert.equal(await accountTokenValue.getText(), '25', 'ETH');
3734
},
3835
);
3936
});
4037

4138
it('Should match the value of token list item and account list item for fiat conversion', async function () {
4239
await withFixtures(
4340
{
44-
dapp: true,
4541
fixtures: new FixtureBuilder().build(),
46-
defaultGanacheOptions,
47-
smartContract,
42+
ganacheOptions: defaultGanacheOptions,
4843
title: this.test.fullTitle(),
4944
},
50-
async ({ driver }) => {
51-
await unlockWallet(driver);
45+
async ({ driver, ganacheServer }) => {
46+
await logInWithBalanceValidation(driver, ganacheServer);
5247

5348
await driver.clickElement(
5449
'[data-testid="account-options-menu-button"]',
@@ -65,18 +60,16 @@ describe('Settings', function () {
6560
);
6661
await driver.clickElement('[data-testid="home__asset-tab"]');
6762

68-
const tokenValue = '0 ETH';
6963
const tokenListAmount = await driver.findElement(
70-
'[data-testid="multichain-token-list-item-value"]',
64+
'.eth-overview__primary-container',
7165
);
72-
assert.equal(await tokenListAmount.getText(), tokenValue);
73-
66+
assert.equal(await tokenListAmount.getText(), '$42,500.00\nUSD');
7467
await driver.clickElement('[data-testid="account-menu-icon"]');
7568
const accountTokenValue = await driver.waitForSelector(
76-
'.multichain-account-list-item .multichain-account-list-item__avatar-currency .currency-display-component__text',
69+
'.multichain-account-list-item .multichain-account-list-item__asset',
7770
);
7871

79-
assert.equal(await accountTokenValue.getText(), '0', 'ETH');
72+
assert.equal(await accountTokenValue.getText(), '$42,500.00USD');
8073
},
8174
);
8275
});

ui/components/app/wallet-overview/eth-overview.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
getShouldHideZeroBalanceTokens,
3535
getCurrentNetwork,
3636
getSelectedAccountCachedBalance,
37+
getShowFiatInTestnets,
3738
///: BEGIN:ONLY_INCLUDE_IF(build-main,build-beta,build-flask)
3839
getSwapsDefaultToken,
3940
getCurrentKeyring,
@@ -106,10 +107,15 @@ const EthOverview = ({ className, showAddress }) => {
106107
selectedAddress,
107108
shouldHideZeroBalanceTokens,
108109
);
110+
const showFiatInTestnets = useSelector(getShowFiatInTestnets);
111+
const showFiat =
112+
TEST_NETWORKS.includes(currentNetwork?.nickname) && !showFiatInTestnets;
109113

110-
const balanceToUse = TEST_NETWORKS.includes(currentNetwork?.nickname)
111-
? balance
112-
: totalWeiBalance;
114+
let balanceToUse = totalWeiBalance;
115+
116+
if (showFiat) {
117+
balanceToUse = balance;
118+
}
113119

114120
const isSwapsChain = useSelector(getIsSwapsChain);
115121

@@ -196,7 +202,10 @@ const EthOverview = ({ className, showAddress }) => {
196202
? PRIMARY
197203
: SECONDARY
198204
}
199-
showFiat={!TEST_NETWORKS.includes(currentNetwork?.nickname)}
205+
showFiat={
206+
!showFiat ||
207+
!TEST_NETWORKS.includes(currentNetwork?.nickname)
208+
}
200209
ethNumberOfDecimals={4}
201210
hideTitle
202211
/>

ui/components/multichain/account-list-item/__snapshots__/account-list-item.test.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ exports[`AccountListItem renders AccountListItem component and shows account nam
7171
>
7272
<div
7373
class="mm-box currency-display-component mm-box--display-flex mm-box--flex-wrap-wrap mm-box--align-items-center"
74-
title="$3.31 USD"
74+
title="$880.18 USD"
7575
>
7676
<span
7777
class="mm-box mm-text currency-display-component__text mm-text--inherit mm-text--ellipsis mm-box--color-text-default"
7878
>
79-
$3.31
79+
$880.18
8080
</span>
8181
<span
8282
class="mm-box mm-text currency-display-component__suffix mm-text--inherit mm-box--margin-inline-start-1 mm-box--color-text-default"

ui/components/multichain/account-list-item/account-list-item.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import { MetaMetricsContext } from '../../../contexts/metametrics';
5050
import {
5151
getCurrentNetwork,
5252
getNativeCurrencyImage,
53+
getShowFiatInTestnets,
5354
getUseBlockie,
5455
} from '../../../selectors';
5556
import { useAccountTotalFiatBalance } from '../../../hooks/useAccountTotalFiatBalance';
@@ -79,14 +80,17 @@ export const AccountListItem = ({
7980
const setAccountListItemMenuRef = (ref) => {
8081
setAccountListItemMenuElement(ref);
8182
};
82-
83+
const showFiatInTestnets = useSelector(getShowFiatInTestnets);
84+
const showFiat =
85+
TEST_NETWORKS.includes(currentNetwork?.nickname) && !showFiatInTestnets;
8386
const { totalWeiBalance, orderedTokenList } = useAccountTotalFiatBalance(
8487
identity.address,
8588
);
8689

87-
const balanceToTranslate = TEST_NETWORKS.includes(currentNetwork?.nickname)
88-
? totalWeiBalance
89-
: identity.balance;
90+
let balanceToTranslate = totalWeiBalance;
91+
if (showFiat) {
92+
balanceToTranslate = identity.balance;
93+
}
9094

9195
// If this is the selected item in the Account menu,
9296
// scroll the item into view
@@ -209,7 +213,9 @@ export const AccountListItem = ({
209213
ethNumberOfDecimals={MAXIMUM_CURRENCY_DECIMALS}
210214
value={balanceToTranslate}
211215
type={PRIMARY}
212-
showFiat={!TEST_NETWORKS.includes(currentNetwork?.nickname)}
216+
showFiat={
217+
!showFiat || !TEST_NETWORKS.includes(currentNetwork?.nickname)
218+
}
213219
/>
214220
</Text>
215221
</Box>

ui/components/multichain/pages/send/components/__snapshots__/your-accounts.test.tsx.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ exports[`SendPageYourAccounts render renders correctly 1`] = `
7474
>
7575
<div
7676
class="mm-box currency-display-component mm-box--display-flex mm-box--flex-wrap-wrap mm-box--align-items-center"
77-
title="$537,761.36 USD"
77+
title="$880.18 USD"
7878
>
7979
<span
8080
class="mm-box mm-text currency-display-component__text mm-text--inherit mm-text--ellipsis mm-box--color-text-default"
8181
>
82-
$537,761.36
82+
$880.18
8383
</span>
8484
<span
8585
class="mm-box mm-text currency-display-component__suffix mm-text--inherit mm-box--margin-inline-start-1 mm-box--color-text-default"

ui/selectors/selectors.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,6 +2011,11 @@ export const useSafeChainsListValidationSelector = (state) => {
20112011
return state.metamask.useSafeChainsListValidation;
20122012
};
20132013

2014+
export function getShowFiatInTestnets(state) {
2015+
const { showFiatInTestnets } = getPreferences(state);
2016+
return showFiatInTestnets;
2017+
}
2018+
20142019
/**
20152020
* To get the useCurrencyRateCheck flag which to check if the user prefers currency conversion
20162021
*

0 commit comments

Comments
 (0)