Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UX: Show same balance on eth overview and account list item #23059

Merged
merged 6 commits into from
Feb 21, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 14 additions & 21 deletions test/e2e/tests/account-token-list.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,24 @@ const { strict: assert } = require('assert');
const {
withFixtures,
defaultGanacheOptions,
unlockWallet,
logInWithBalanceValidation,
} = require('../helpers');

const FixtureBuilder = require('../fixture-builder');
const { SMART_CONTRACTS } = require('../seeder/smart-contracts');

describe('Settings', function () {
const smartContract = SMART_CONTRACTS.ERC1155;
it('Should match the value of token list item and account list item for eth conversion', async function () {
await withFixtures(
{
dapp: true,
fixtures: new FixtureBuilder().build(),
defaultGanacheOptions,
smartContract,
ganacheOptions: defaultGanacheOptions,
title: this.test.fullTitle(),
},
async ({ driver }) => {
await unlockWallet(driver);
async ({ driver, ganacheServer }) => {
await logInWithBalanceValidation(driver, ganacheServer);

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

assert.equal(await accountTokenValue.getText(), '0', 'ETH');
assert.equal(await accountTokenValue.getText(), '25', 'ETH');
},
);
});

it('Should match the value of token list item and account list item for fiat conversion', async function () {
await withFixtures(
{
dapp: true,
fixtures: new FixtureBuilder().build(),
defaultGanacheOptions,
smartContract,
ganacheOptions: defaultGanacheOptions,
title: this.test.fullTitle(),
},
async ({ driver }) => {
await unlockWallet(driver);
async ({ driver, ganacheServer }) => {
await logInWithBalanceValidation(driver, ganacheServer);

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

const tokenValue = '0 ETH';
const tokenListAmount = await driver.findElement(
'[data-testid="multichain-token-list-item-value"]',
'.eth-overview__primary-container',
);
assert.equal(await tokenListAmount.getText(), tokenValue);

assert.equal(await tokenListAmount.getText(), '$42,500.00\nUSD');
await driver.clickElement('[data-testid="account-menu-icon"]');
const accountTokenValue = await driver.waitForSelector(
'.multichain-account-list-item .multichain-account-list-item__avatar-currency .currency-display-component__text',
'.multichain-account-list-item .multichain-account-list-item__asset',
);

assert.equal(await accountTokenValue.getText(), '0', 'ETH');
assert.equal(await accountTokenValue.getText(), '$42,500.00USD');
},
);
});
Expand Down
17 changes: 13 additions & 4 deletions ui/components/app/wallet-overview/eth-overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
getShouldHideZeroBalanceTokens,
getCurrentNetwork,
getSelectedAccountCachedBalance,
getShowFiatInTestnets,
///: BEGIN:ONLY_INCLUDE_IF(build-main,build-beta,build-flask)
getSwapsDefaultToken,
getCurrentKeyring,
Expand Down Expand Up @@ -106,10 +107,15 @@ const EthOverview = ({ className, showAddress }) => {
selectedAddress,
shouldHideZeroBalanceTokens,
);
const showFiatInTestnets = useSelector(getShowFiatInTestnets);
const showFiat =
TEST_NETWORKS.includes(currentNetwork?.nickname) && !showFiatInTestnets;

const balanceToUse = TEST_NETWORKS.includes(currentNetwork?.nickname)
? balance
: totalWeiBalance;
let balanceToUse = totalWeiBalance;

if (showFiat) {
balanceToUse = balance;
}

const isSwapsChain = useSelector(getIsSwapsChain);

Expand Down Expand Up @@ -196,7 +202,10 @@ const EthOverview = ({ className, showAddress }) => {
? PRIMARY
: SECONDARY
}
showFiat={!TEST_NETWORKS.includes(currentNetwork?.nickname)}
showFiat={
!showFiat ||
!TEST_NETWORKS.includes(currentNetwork?.nickname)
}
ethNumberOfDecimals={4}
hideTitle
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ exports[`AccountListItem renders AccountListItem component and shows account nam
>
<div
class="mm-box currency-display-component mm-box--display-flex mm-box--flex-wrap-wrap mm-box--align-items-center"
title="$3.31 USD"
title="$880.18 USD"
>
<span
class="mm-box mm-text currency-display-component__text mm-text--inherit mm-text--ellipsis mm-box--color-text-default"
>
$3.31
$880.18
</span>
<span
class="mm-box mm-text currency-display-component__suffix mm-text--inherit mm-box--margin-inline-start-1 mm-box--color-text-default"
Expand Down
16 changes: 11 additions & 5 deletions ui/components/multichain/account-list-item/account-list-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { MetaMetricsContext } from '../../../contexts/metametrics';
import {
getCurrentNetwork,
getNativeCurrencyImage,
getShowFiatInTestnets,
getUseBlockie,
} from '../../../selectors';
import { useAccountTotalFiatBalance } from '../../../hooks/useAccountTotalFiatBalance';
Expand Down Expand Up @@ -79,14 +80,17 @@ export const AccountListItem = ({
const setAccountListItemMenuRef = (ref) => {
setAccountListItemMenuElement(ref);
};

const showFiatInTestnets = useSelector(getShowFiatInTestnets);
const showFiat =
TEST_NETWORKS.includes(currentNetwork?.nickname) && !showFiatInTestnets;
const { totalWeiBalance, orderedTokenList } = useAccountTotalFiatBalance(
identity.address,
);

const balanceToTranslate = TEST_NETWORKS.includes(currentNetwork?.nickname)
? totalWeiBalance
: identity.balance;
let balanceToTranslate = totalWeiBalance;
if (showFiat) {
balanceToTranslate = identity.balance;
}

// If this is the selected item in the Account menu,
// scroll the item into view
Expand Down Expand Up @@ -209,7 +213,9 @@ export const AccountListItem = ({
ethNumberOfDecimals={MAXIMUM_CURRENCY_DECIMALS}
value={balanceToTranslate}
type={PRIMARY}
showFiat={!TEST_NETWORKS.includes(currentNetwork?.nickname)}
showFiat={
!showFiat || !TEST_NETWORKS.includes(currentNetwork?.nickname)
}
/>
</Text>
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ exports[`SendPageYourAccounts render renders correctly 1`] = `
>
<div
class="mm-box currency-display-component mm-box--display-flex mm-box--flex-wrap-wrap mm-box--align-items-center"
title="$537,761.36 USD"
title="$880.18 USD"
>
<span
class="mm-box mm-text currency-display-component__text mm-text--inherit mm-text--ellipsis mm-box--color-text-default"
>
$537,761.36
$880.18
</span>
<span
class="mm-box mm-text currency-display-component__suffix mm-text--inherit mm-box--margin-inline-start-1 mm-box--color-text-default"
Expand Down
5 changes: 5 additions & 0 deletions ui/selectors/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2011,6 +2011,11 @@ export const useSafeChainsListValidationSelector = (state) => {
return state.metamask.useSafeChainsListValidation;
};

export function getShowFiatInTestnets(state) {
const { showFiatInTestnets } = getPreferences(state);
return showFiatInTestnets;
}

/**
* To get the useCurrencyRateCheck flag which to check if the user prefers currency conversion
*
Expand Down