Skip to content

Commit

Permalink
Merge branch 'develop' into test-queue-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
BelfordZ committed Mar 20, 2024
2 parents 633db2b + a345f9b commit 6a238e1
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 70 deletions.
9 changes: 2 additions & 7 deletions test/e2e/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -833,16 +833,11 @@ const TEST_SEED_PHRASE_TWO =

// Usually happens when onboarded to make sure the state is retrieved from metamaskState properly, or after txn is made
const locateAccountBalanceDOM = async (driver, ganacheServer) => {
const balance = (await ganacheServer.getFiatBalance()).toLocaleString(
undefined,
{
minimumFractionDigits: 2,
},
);
const balance = await ganacheServer.getBalance();

await driver.findElement({
css: '[data-testid="eth-overview__primary-currency"]',
text: `$ ${balance} USD`,
text: `${balance} ETH`,
});
};

Expand Down
9 changes: 3 additions & 6 deletions test/e2e/tests/contract-interactions.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const { strict: assert } = require('assert');
const {
defaultGanacheOptions,
withFixtures,
openDapp,
unlockWallet,
largeDelayMs,
WINDOW_TITLES,
locateAccountBalanceDOM,
} = require('../helpers');

const { SMART_CONTRACTS } = require('../seeder/smart-contracts');
Expand All @@ -25,7 +25,7 @@ describe('Deploy contract and call contract methods', function () {
smartContract,
title: this.test.fullTitle(),
},
async ({ driver, contractRegistry }) => {
async ({ driver, contractRegistry, ganacheServer }) => {
const contractAddress = await contractRegistry.getContractAddress(
smartContract,
);
Expand Down Expand Up @@ -87,10 +87,7 @@ describe('Deploy contract and call contract methods', function () {
await driver.switchToWindowWithTitle(
WINDOW_TITLES.ExtensionInFullScreenView,
);
const balance = await driver.findElement(
'[data-testid="eth-overview__primary-currency"]',
);
assert.equal(await balance.getText(), '$37,399.05\nUSD');
await locateAccountBalanceDOM(driver, ganacheServer);
},
);
});
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/tests/incremental-security.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ describe('Incremental Security', function () {
// should have the correct amount of eth
let currencyDisplay = await driver.waitForSelector({
css: '.currency-display-component__text',
text: '$1,700.00',
text: '1',
});
let balance = await currencyDisplay.getText();
assert.strictEqual(balance, '$1,700.00');
assert.strictEqual(balance, '1');

// backs up the Secret Recovery Phrase
// should show a backup reminder
Expand Down Expand Up @@ -163,11 +163,11 @@ describe('Incremental Security', function () {
// should have the correct amount of eth
currencyDisplay = await driver.waitForSelector({
css: '.currency-display-component__text',
text: '$1,700.00',
text: '1',
});
balance = await currencyDisplay.getText();

assert.strictEqual(balance, '$1,700.00');
assert.strictEqual(balance, '1');

// The previous currencyDisplay wait already serves as the guard here for the assertElementNotPresent
await driver.assertElementNotPresent('.backup-notification');
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/tests/localization.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Localization', function () {
await unlockWallet(driver);

const secondaryBalance = await driver.findElement(
'[data-testid="eth-overview__primary-currency"]',
'[data-testid="eth-overview__secondary-currency"]',
);
const secondaryBalanceText = await secondaryBalance.getText();
const [fiatAmount, fiatUnit] = secondaryBalanceText
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/tests/lock-account.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('Lock and unlock', function () {
const walletBalance = await driver.findElement(
'.eth-overview__primary-balance',
);
assert.equal(await walletBalance.getText(), '$42,500.00\nUSD');
assert.equal(/^25\s*ETH$/u.test(await walletBalance.getText()), true);
},
);
});
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/tests/metamask-responsive-ui.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ describe('MetaMask Responsive UI', function () {
await driver.clickElement('[data-testid="pin-extension-done"]');
await driver.assertElementNotPresent('.loading-overlay__spinner');
// assert balance
await driver.findElement({
css: '[data-testid="eth-overview__primary-currency"]',
text: `$ 0.00 USD`,
});
const balance = await driver.findElement(
'[data-testid="eth-overview__primary-currency"]',
);
assert.ok(/^0\sETH$/u.test(await balance.getText()));
},
);
});
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/tests/migrate-old-vault.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('Migrate vault with old encryption', function () {
const walletBalance = await driver.findElement(
'.eth-overview__primary-balance',
);
assert.equal(await walletBalance.getText(), '$42,500.00\nUSD');
assert.equal(/^25\s*ETH$/u.test(await walletBalance.getText()), true);
},
);
});
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/tests/settings/account-token-list.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('Settings', function () {
const tokenListAmount = await driver.findElement(
'.eth-overview__primary-container',
);
assert.equal(await tokenListAmount.getText(), '$42,500.00\nUSD');
assert.equal(await tokenListAmount.getText(), '25\nETH');
await driver.clickElement('[data-testid="account-menu-icon"]');
const accountTokenValue = await driver.waitForSelector(
'.multichain-account-list-item .multichain-account-list-item__asset',
Expand Down
24 changes: 12 additions & 12 deletions test/e2e/tests/transaction/send-eth.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ describe('Send ETH', function () {
await driver.clickElement({ text: 'Confirm', tag: 'button' });

// Go back to home screen to check txn
await driver.findElement({
css: '[data-testid="eth-overview__primary-currency"]',
text: '$42,496.38',
});
const balance = await driver.findElement(
'[data-testid="eth-overview__primary-currency"]',
);
assert.ok(/^[\d.]+\sETH$/u.test(await balance.getText()));
await driver.clickElement('[data-testid="home__activity-tab"]');

await driver.findElement(
Expand Down Expand Up @@ -219,10 +219,10 @@ describe('Send ETH', function () {
await unlockWallet(driver);

await driver.assertElementNotPresent('.loading-overlay__spinner');
await driver.findElement({
css: '[data-testid="eth-overview__primary-currency"]',
text: '$42,500.00',
});
const balance = await driver.findElement(
'[data-testid="eth-overview__primary-currency"]',
);
assert.ok(/^[\d.]+\sETH$/u.test(await balance.getText()));

await openActionMenuAndStartSendFlow(driver);
// choose to scan via QR code
Expand Down Expand Up @@ -435,10 +435,10 @@ describe('Send ETH', function () {
await unlockWallet(driver);

await driver.assertElementNotPresent('.loading-overlay__spinner');
await driver.findElement({
css: '[data-testid="eth-overview__primary-currency"]',
text: '$42,500.00',
});
const balance = await driver.findElement(
'[data-testid="eth-overview__primary-currency"]',
);
assert.ok(/^[\d.]+\sETH$/u.test(await balance.getText()));

await openActionMenuAndStartSendFlow(driver);
await driver.fill(
Expand Down
48 changes: 17 additions & 31 deletions ui/components/app/wallet-overview/eth-overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@ import UserPreferencedCurrencyDisplay from '../user-preferenced-currency-display
import { PRIMARY, SECONDARY } from '../../../helpers/constants/common';
import {
isBalanceCached,
getShouldShowFiat,
getIsSwapsChain,
getCurrentChainId,
getPreferences,
getSelectedInternalAccount,
getShouldHideZeroBalanceTokens,
getCurrentNetwork,
getSelectedAccountCachedBalance,
getShowFiatInTestnets,
///: BEGIN:ONLY_INCLUDE_IF(build-main,build-beta,build-flask)
getSwapsDefaultToken,
getCurrentKeyring,
Expand Down Expand Up @@ -66,11 +64,9 @@ import { IconColor } from '../../../helpers/constants/design-system';
import useRamps from '../../../hooks/experiences/useRamps';
import { getPortfolioUrl } from '../../../helpers/utils/portfolio';
///: END:ONLY_INCLUDE_IF
import { useAccountTotalFiatBalance } from '../../../hooks/useAccountTotalFiatBalance';
import { useIsOriginalNativeTokenSymbol } from '../../../hooks/useIsOriginalNativeTokenSymbol';
import { getProviderConfig } from '../../../ducks/metamask/metamask';
import { showPrimaryCurrency } from '../../../../shared/modules/currency-display.utils';
import { TEST_NETWORKS } from '../../../../shared/constants/network';
import WalletOverview from './wallet-overview';

const EthOverview = ({ className, showAddress }) => {
Expand All @@ -88,37 +84,18 @@ const EthOverview = ({ className, showAddress }) => {
const defaultSwapsToken = useSelector(getSwapsDefaultToken);
///: END:ONLY_INCLUDE_IF
const balanceIsCached = useSelector(isBalanceCached);
const showFiat = useSelector(getShouldShowFiat);
const { useNativeCurrencyAsPrimaryCurrency } = useSelector(getPreferences);
const chainId = useSelector(getCurrentChainId);
const { ticker, type } = useSelector(getProviderConfig);
const currentNetwork = useSelector(getCurrentNetwork);
const balance = useSelector(getSelectedAccountCachedBalance);
const isOriginalNativeSymbol = useIsOriginalNativeTokenSymbol(
chainId,
ticker,
type,
);

// Total fiat balance
const account = useSelector(getSelectedInternalAccount);
const selectedAddress = account.address;
const shouldHideZeroBalanceTokens = useSelector(
getShouldHideZeroBalanceTokens,
);
const { totalWeiBalance } = useAccountTotalFiatBalance(
selectedAddress,
shouldHideZeroBalanceTokens,
);
const showFiatInTestnets = useSelector(getShowFiatInTestnets);
const showFiat =
TEST_NETWORKS.includes(currentNetwork?.nickname) && !showFiatInTestnets;

let balanceToUse = totalWeiBalance;

if (showFiat) {
balanceToUse = balance;
}

const isSwapsChain = useSelector(getIsSwapsChain);
const isSigningEnabled =
account.methods.includes(EthMethod.SignTransaction) ||
Expand Down Expand Up @@ -226,14 +203,14 @@ const EthOverview = ({ className, showAddress }) => {
>
<div className="eth-overview__balance">
<div className="eth-overview__primary-container">
{balanceToUse ? (
{balance ? (
<UserPreferencedCurrencyDisplay
style={{ display: 'contents' }}
className={classnames('eth-overview__primary-balance', {
'eth-overview__cached-balance': balanceIsCached,
})}
data-testid="eth-overview__primary-currency"
value={balanceToUse}
value={balance}
type={
showPrimaryCurrency(
isOriginalNativeSymbol,
Expand All @@ -242,10 +219,6 @@ const EthOverview = ({ className, showAddress }) => {
? PRIMARY
: SECONDARY
}
showFiat={
!showFiat ||
!TEST_NETWORKS.includes(currentNetwork?.nickname)
}
ethNumberOfDecimals={4}
hideTitle
/>
Expand All @@ -259,6 +232,19 @@ const EthOverview = ({ className, showAddress }) => {
<span className="eth-overview__cached-star">*</span>
) : null}
</div>
{showFiat && isOriginalNativeSymbol && balance && (
<UserPreferencedCurrencyDisplay
className={classnames({
'eth-overview__cached-secondary-balance': balanceIsCached,
'eth-overview__secondary-balance': !balanceIsCached,
})}
data-testid="eth-overview__secondary-currency"
value={balance}
type={SECONDARY}
ethNumberOfDecimals={4}
hideTitle
/>
)}
</div>
</Tooltip>
}
Expand Down
4 changes: 2 additions & 2 deletions ui/components/app/wallet-overview/eth-overview.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ describe('EthOverview', () => {

const primaryBalance = queryByTestId(ETH_OVERVIEW_PRIMARY_CURRENCY);
expect(primaryBalance).toBeInTheDocument();
expect(primaryBalance).toHaveTextContent('$0.00USD');
expect(primaryBalance).toHaveTextContent('<0.000001ETH');
expect(queryByText('*')).not.toBeInTheDocument();
});

Expand Down Expand Up @@ -203,7 +203,7 @@ describe('EthOverview', () => {

const primaryBalance = queryByTestId(ETH_OVERVIEW_PRIMARY_CURRENCY);
expect(primaryBalance).toBeInTheDocument();
expect(primaryBalance).toHaveTextContent('$0.02USD');
expect(primaryBalance).toHaveTextContent('0.0104ETH');
expect(queryByText('*')).toBeInTheDocument();
});

Expand Down

0 comments on commit 6a238e1

Please sign in to comment.