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: Multichain: Move PickerNetwork to Wallet Tabs #21220

Closed
wants to merge 10 commits into from
1 change: 1 addition & 0 deletions test/e2e/tests/import-tokens.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('Import flow', function () {
await unlockWallet(driver);

// Token list is only on mainnet
await driver.waitForSelector('[data-testid="network-display"]');
await driver.clickElement('[data-testid="network-display"]');
await driver.clickElement({ text: 'Ethereum Mainnet', tag: 'button' });

Expand Down
8 changes: 7 additions & 1 deletion ui/components/multichain/account-picker/account-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import { useSelector } from 'react-redux';
import { toChecksumHexAddress } from '@metamask/controller-utils';
import classnames from 'classnames';
import {
Box,
AvatarAccount,
Expand Down Expand Up @@ -33,14 +34,15 @@ export const AccountPicker = ({
name,
onClick,
disabled,
className = '',
showAddress = false,
}) => {
const useBlockie = useSelector(getUseBlockie);
const shortenedAddress = shortenAddress(toChecksumHexAddress(address));

return (
<ButtonBase
className="multichain-account-picker"
className={classnames('multichain-account-picker', className)}
data-testid="account-menu-icon"
onClick={onClick}
backgroundColor={BackgroundColor.transparent}
Expand Down Expand Up @@ -114,4 +116,8 @@ AccountPicker.propTypes = {
* Represents if the account address should display
*/
showAddress: PropTypes.bool,
/**
* CSS class to be added to the root element
*/
className: PropTypes.string,
};
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ exports[`App Header should match snapshot 1`] = `
<div
class="mm-box multichain-app-header__contents multichain-app-header-shadow mm-box--padding-2 mm-box--padding-right-4 mm-box--padding-left-4 mm-box--gap-2 mm-box--align-items-center mm-box--width-full mm-box--background-color-background-default"
>
<div>
<div
class="mm-box"
>
<button
class="mm-box mm-picker-network multichain-app-header__contents__network-picker mm-box--margin-2 mm-box--padding-right-4 mm-box--padding-left-2 mm-box--display-none mm-box--sm:display-flex mm-box--gap-2 mm-box--align-items-center mm-box--background-color-background-alternative mm-box--rounded-pill"
data-testid="network-display"
Expand Down
54 changes: 34 additions & 20 deletions ui/components/multichain/app-header/app-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export const AppHeader = ({ location }) => {
isTransactionEditPage ||
isConfirmationPage ||
hasUnapprovedTransactions;
const showNetworkPicker = Boolean(process.env.MULTICHAIN) === false;

// Callback for network dropdown
const networkOpenCallback = useCallback(() => {
Expand Down Expand Up @@ -212,6 +213,9 @@ export const AppHeader = ({ location }) => {
<Box
className={classnames('multichain-app-header__contents', {
'multichain-app-header-shadow': isUnlocked && !popupStatus,
'multichain-app-header__contents--no-network': Boolean(
process.env.MULTICHAIN,
),
})}
alignItems={AlignItems.center}
width={BlockSize.Full}
Expand All @@ -222,7 +226,10 @@ export const AppHeader = ({ location }) => {
gap={2}
>
{popupStatus ? (
<Box className="multichain-app-header__contents__container">
<Box
className="multichain-app-header__contents__container"
display={showNetworkPicker ? Display.Flex : Display.None}
>
<Tooltip title={currentNetwork?.nickname} position="right">
<PickerNetwork
avatarNetworkProps={{
Expand All @@ -248,25 +255,27 @@ export const AppHeader = ({ location }) => {
</Tooltip>
</Box>
) : (
<div>
<PickerNetwork
avatarNetworkProps={{
backgroundColor: testNetworkBackgroundColor,
}}
margin={2}
label={currentNetwork?.nickname}
src={currentNetwork?.rpcPrefs?.imageUrl}
onClick={(e) => {
e.stopPropagation();
e.preventDefault();
networkOpenCallback();
}}
display={[Display.None, Display.Flex]} // show on desktop hide on popover
className="multichain-app-header__contents__network-picker"
disabled={disableNetworkPicker}
data-testid="network-display"
/>
</div>
showNetworkPicker && (
<Box>
<PickerNetwork
avatarNetworkProps={{
backgroundColor: testNetworkBackgroundColor,
}}
margin={2}
label={currentNetwork?.nickname}
src={currentNetwork?.rpcPrefs?.imageUrl}
onClick={(e) => {
e.stopPropagation();
e.preventDefault();
networkOpenCallback();
}}
display={[Display.None, Display.Flex]} // show on desktop hide on popover
className="multichain-app-header__contents__network-picker"
disabled={disableNetworkPicker}
data-testid="network-display"
/>
</Box>
)
)}
{showProductTour &&
popupStatus &&
Expand Down Expand Up @@ -304,6 +313,11 @@ export const AppHeader = ({ location }) => {
}}
disabled={disableAccountPicker}
showAddress={Boolean(process.env.MULTICHAIN)}
className={classnames({
'multichain-app-header__account-picker': Boolean(
process.env.MULTICHAIN,
),
})}
/>
) : null}
<Box
Expand Down
9 changes: 9 additions & 0 deletions ui/components/multichain/app-header/app-header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
grid-template-columns: 1fr 2fr 1fr;
height: 64px;

&--no-network {
grid-template-columns: 2fr 1fr;
}

@include screen-sm-max {
height: $height-screen-sm-max;
}
Expand All @@ -38,6 +42,11 @@
}
}

/* Aligns the Account Picker left when there's no PickerNetwork */
&__account-picker {
justify-self: baseline;
}

&__lock-contents {
flex-flow: row nowrap;
height: 64px;
Expand Down
42 changes: 42 additions & 0 deletions ui/pages/home/home.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
Display,
TextColor,
TextVariant,
BlockSize,
///: BEGIN:ONLY_INCLUDE_IN(build-main)
Size,
///: END:ONLY_INCLUDE_IN
Expand All @@ -48,6 +49,7 @@ import {
ButtonLink,
///: END:ONLY_INCLUDE_IN
Text,
PickerNetwork,
} from '../../components/component-library';

import {
Expand Down Expand Up @@ -192,6 +194,9 @@ export default class Home extends PureComponent {
setWaitForConfirmDeepLinkDialog: PropTypes.func,
waitForConfirmDeepLinkDialog: PropTypes.bool,
///: END:ONLY_INCLUDE_IN
testNetworkBackgroundColor: PropTypes.string,
currentNetwork: PropTypes.object,
toggleNetworkMenu: PropTypes.func,
};

state = {
Expand Down Expand Up @@ -725,6 +730,9 @@ export default class Home extends PureComponent {
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
mmiPortfolioEnabled,
///: END:ONLY_INCLUDE_IN
testNetworkBackgroundColor,
currentNetwork,
toggleNetworkMenu,
} = this.props;

if (forgottenPassword) {
Expand All @@ -734,6 +742,37 @@ export default class Home extends PureComponent {
}
const tabPadding = process.env.MULTICHAIN ? 4 : 0; // TODO: Remove tabPadding and add paddingTop={4} to parent container Box of Tabs

const networkPicker = process.env.MULTICHAIN ? (
<Box marginTop={4} marginInlineEnd={4}>
<PickerNetwork
className="home__tab__network-picker"
avatarNetworkProps={{
backgroundColor: testNetworkBackgroundColor,
}}
margin={2}
label={currentNetwork?.nickname}
src={currentNetwork?.rpcPrefs?.imageUrl}
onClick={(e) => {
e.stopPropagation();
e.preventDefault();
Comment on lines +756 to +757
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: can we move these 2 events related actions to component PickerNetwork level?


toggleNetworkMenu();
this.context.trackEvent({
event: MetaMetricsEventName.NavNetworkMenuOpened,
category: MetaMetricsEventCategory.Navigation,
properties: {
location: 'App header',
chain_id: currentNetwork?.chainId,
},
});
}}
display={Display.Flex}
width={BlockSize.Full}
data-testid="network-display"
/>
</Box>
) : null;

///: BEGIN:ONLY_INCLUDE_IN(build-main,build-beta,build-flask)
const showWhatsNew =
completedOnboarding &&
Expand Down Expand Up @@ -841,6 +880,7 @@ export default class Home extends PureComponent {
name={this.context.t('tokens')}
tabKey="tokens"
>
{networkPicker}
<Box marginTop={2}>
<AssetList
onClickAsset={(asset) =>
Expand Down Expand Up @@ -874,6 +914,7 @@ export default class Home extends PureComponent {
name={this.context.t('nfts')}
tabKey="nfts"
>
{networkPicker}
<NftsTab />
{
///: BEGIN:ONLY_INCLUDE_IN(build-main)
Expand Down Expand Up @@ -901,6 +942,7 @@ export default class Home extends PureComponent {
name={t('activity')}
tabKey="activity"
>
{networkPicker}
<TransactionList />
{
///: BEGIN:ONLY_INCLUDE_IN(build-main)
Expand Down
6 changes: 6 additions & 0 deletions ui/pages/home/home.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import {
getSuggestedTokens,
getSuggestedNfts,
getApprovalFlows,
getTestNetworkBackgroundColor,
getCurrentNetwork,
} from '../../selectors';

import {
Expand All @@ -54,6 +56,7 @@ import {
setRemoveNftMessage,
setNewTokensImported,
setActiveNetwork,
toggleNetworkMenu,
} from '../../store/actions';
import { hideWhatsNewPopup } from '../../ducks/app/app';
import { getWeb3ShimUsageAlertEnabledness } from '../../ducks/metamask/metamask';
Expand Down Expand Up @@ -171,6 +174,8 @@ const mapStateToProps = (state) => {
mmiPortfolioEnabled: getMmiPortfolioEnabled(state),
notificationsToShow: getSortedAnnouncementsToShow(state).length > 0,
///: END:ONLY_INCLUDE_IN
testNetworkBackgroundColor: getTestNetworkBackgroundColor(state),
currentNetwork: getCurrentNetwork(state),
};
};

Expand Down Expand Up @@ -220,6 +225,7 @@ const mapDispatchToProps = (dispatch) => {
setWaitForConfirmDeepLinkDialog: (wait) =>
dispatch(mmiActions.setWaitForConfirmDeepLinkDialog(wait)),
///: END:ONLY_INCLUDE_IN
toggleNetworkMenu: () => dispatch(toggleNetworkMenu()),
};
};

Expand Down
Loading