mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-04 15:14:29 +01:00
b89630fdd2
* Show portfolio icon in ETH overview
* Show new copy button in QR code modal
* Show address copy button in wallet overview
* Update connected status component
* Remove legacy MenuBar
* Remove legacy ImportTokenLink
* Remove AssetListItem
* Remove DetectedTokensLink
* Remove legacy AppHeader
* Remove MULTICHAIN flag from builds.yml
* Remove legacy AccountMenu
* FIX: Token cell snapshot
* Add data-testid for Account Picker
* Remove multichain check in LoadingNetworkScreen
* Remove MULTICHAIN check for AccountDetailsModal
* Remove MULTICHAIN check for AssetList
* Update QR dimensions
* Remove MULTICHAIN declaration from metamaskrc.dist
* Implement PickerNetwork and NetworkListMenu in onboarding
* Remove legacy NetworkDropdown and Dropdown
* Remove documentation about legacy account menu
* FIX: Fixes route tests for missing data-testid=network-display
* Fix account-menu-icon data-testid
* Fix TokenCell test
* FIX Onboarding Flow tests
* Remove unused locales from AccountMenu removal
* E2E: Fix Import Secret Recovery Phrase: logs out of the vault
* E2E: Fix Show account details: should show the QR code for the account
* E2E: Fix add-account.spec.js
* E2E: Fix state-logs.spec.js
* E2E: Fix lock-account.spec.js
* E2E: Fix settings-general.spec.js
* E2E: Fix advanced-settings.spec.js
* E2E: Fix auto-lock.spec.js
* E2E: Fix backup-restore.spec.js
* E2E: Fix clear-activity.spec.js
* E2E: Fix settings-search.spec.js
* E2E: Fix encrypt-decrypt.spec.js
* E2E: Fix dapp-interactions.spec.js
* E2E: Fix test-snap-management.spec.js
* E2E: Fix add-custom-network.spec.js
* E2E: Fix from-import-ui.spec.js
* E2E: Fix provider-api.spec.js
* E2E: Fix chain-interactions.spec.js
* E2E: Fix custom-rpc-history.spec.js
* Remove network icon from overview components
* E2E: Fix user-actions-benchmark.js
* E2E: Fix benchmark.js
* E2E: Fix add-hide-token.spec.js
* E2E: Fix address-book.spec.js
* E2E: Fix custom-token-add-approve.spec.js
* E2E: Fix incremental-security.spec.js
* E2E: Fix metamask-responsive-ui.spec.js
* E2E: Onboarding.spec.js
* E2E: Fix permissions.spec.js
* E2E: Fix send-hex-address.spec.js
* E2E: Fix send-to-contract.spec.js
* Remove dead AccountOptionsMenu test
* E2E: Fix token-details.spec.js
* E2E: Fix switch-custom-network.spec.js
* E2E: Fix metamask-ui.spec.js
* Revert "UX Multichain: updated border top for activity list (#19176)"
This reverts commit 15598f2a23
.
* E2Es: Fix test-snap-management.spec.js and test-snap-notification.spec.js
* E2Es: Fix add-account.spec.js after flaky test fixes
* e2e flaky test
* adds back the mmi options
* scss fix
* test fix
* removes unnecessary double quotes
* Prevent double logos on login screen
* Update ui/components/ui/list-item/index.scss
Co-authored-by: Nidhi Kumari <nidhi.kumari@consensys.net>
---------
Co-authored-by: seaona <mariona@gmx.es>
Co-authored-by: Antonio Regadas <antonio.regadas@consensys.net>
Co-authored-by: Nidhi Kumari <nidhi.kumari@consensys.net>
383 lines
12 KiB
JavaScript
383 lines
12 KiB
JavaScript
import React, { useContext } from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import { useDispatch, useSelector } from 'react-redux';
|
|
import classnames from 'classnames';
|
|
import { useHistory, useLocation } from 'react-router-dom';
|
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
|
import {
|
|
getMmiPortfolioEnabled,
|
|
getMmiPortfolioUrl,
|
|
} from '../../../selectors/institutional/selectors';
|
|
///: END:ONLY_INCLUDE_IN
|
|
|
|
import { I18nContext } from '../../../contexts/i18n';
|
|
import {
|
|
SEND_ROUTE,
|
|
BUILD_QUOTE_ROUTE,
|
|
} from '../../../helpers/constants/routes';
|
|
import Tooltip from '../../ui/tooltip';
|
|
import UserPreferencedCurrencyDisplay from '../user-preferenced-currency-display';
|
|
import { PRIMARY, SECONDARY } from '../../../helpers/constants/common';
|
|
import {
|
|
isBalanceCached,
|
|
getShouldShowFiat,
|
|
getCurrentKeyring,
|
|
getSwapsDefaultToken,
|
|
getIsSwapsChain,
|
|
getIsBridgeChain,
|
|
getIsBuyableChain,
|
|
getSelectedAccountCachedBalance,
|
|
getCurrentChainId,
|
|
getMetaMetricsId,
|
|
} from '../../../selectors';
|
|
import { setSwapsFromToken } from '../../../ducks/swaps/swaps';
|
|
import IconButton from '../../ui/icon-button';
|
|
import { isHardwareKeyring } from '../../../helpers/utils/hardware';
|
|
import { MetaMetricsContext } from '../../../contexts/metametrics';
|
|
import {
|
|
MetaMetricsContextProp,
|
|
MetaMetricsEventCategory,
|
|
MetaMetricsEventName,
|
|
MetaMetricsSwapsEventSource,
|
|
} from '../../../../shared/constants/metametrics';
|
|
import Spinner from '../../ui/spinner';
|
|
import { startNewDraftTransaction } from '../../../ducks/send';
|
|
import { AssetType } from '../../../../shared/constants/transaction';
|
|
import {
|
|
ButtonIcon,
|
|
ButtonIconSize,
|
|
Icon,
|
|
IconName,
|
|
} from '../../component-library';
|
|
import { IconColor } from '../../../helpers/constants/design-system';
|
|
import useRamps from '../../../hooks/experiences/useRamps';
|
|
import { getPortfolioUrl } from '../../../helpers/utils/portfolio';
|
|
import WalletOverview from './wallet-overview';
|
|
|
|
const EthOverview = ({ className }) => {
|
|
const dispatch = useDispatch();
|
|
const t = useContext(I18nContext);
|
|
const trackEvent = useContext(MetaMetricsContext);
|
|
const history = useHistory();
|
|
const location = useLocation();
|
|
const keyring = useSelector(getCurrentKeyring);
|
|
const usingHardwareWallet = isHardwareKeyring(keyring?.type);
|
|
const balanceIsCached = useSelector(isBalanceCached);
|
|
const showFiat = useSelector(getShouldShowFiat);
|
|
const balance = useSelector(getSelectedAccountCachedBalance);
|
|
const isSwapsChain = useSelector(getIsSwapsChain);
|
|
const isBridgeChain = useSelector(getIsBridgeChain);
|
|
const isBuyableChain = useSelector(getIsBuyableChain);
|
|
const defaultSwapsToken = useSelector(getSwapsDefaultToken);
|
|
const chainId = useSelector(getCurrentChainId);
|
|
const metaMetricsId = useSelector(getMetaMetricsId);
|
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
|
const mmiPortfolioEnabled = useSelector(getMmiPortfolioEnabled);
|
|
const mmiPortfolioUrl = useSelector(getMmiPortfolioUrl);
|
|
|
|
const portfolioEvent = () => {
|
|
trackEvent({
|
|
category: 'Navigation',
|
|
event: 'Clicked Portfolio Button',
|
|
});
|
|
};
|
|
|
|
const stakingEvent = () => {
|
|
trackEvent({
|
|
category: 'Navigation',
|
|
event: 'Clicked Stake Button',
|
|
});
|
|
};
|
|
|
|
const renderInstitutionalButtons = () => {
|
|
return (
|
|
<>
|
|
<IconButton
|
|
className="eth-overview__button"
|
|
Icon={<Icon name={IconName.Stake} color={IconColor.primaryDefault} />}
|
|
label={t('stake')}
|
|
onClick={() => {
|
|
stakingEvent();
|
|
global.platform.openTab({
|
|
url: 'https://metamask-institutional.io/staking',
|
|
});
|
|
}}
|
|
/>
|
|
{mmiPortfolioEnabled && (
|
|
<IconButton
|
|
className="eth-overview__button"
|
|
Icon={
|
|
<Icon name={IconName.Diagram} color={IconColor.primaryDefault} />
|
|
}
|
|
label={t('portfolio')}
|
|
onClick={() => {
|
|
portfolioEvent();
|
|
window.open(mmiPortfolioUrl, '_blank');
|
|
}}
|
|
/>
|
|
)}
|
|
</>
|
|
);
|
|
};
|
|
///: END:ONLY_INCLUDE_IN
|
|
|
|
const { openBuyCryptoInPdapp } = useRamps();
|
|
|
|
return (
|
|
<WalletOverview
|
|
balance={
|
|
<Tooltip
|
|
position="top"
|
|
title={t('balanceOutdated')}
|
|
disabled={!balanceIsCached}
|
|
>
|
|
<div className="eth-overview__balance">
|
|
<div className="eth-overview__primary-container">
|
|
{balance ? (
|
|
<UserPreferencedCurrencyDisplay
|
|
style={{ display: 'contents' }}
|
|
className={classnames('eth-overview__primary-balance', {
|
|
'eth-overview__cached-balance': balanceIsCached,
|
|
})}
|
|
data-testid="eth-overview__primary-currency"
|
|
value={balance}
|
|
type={PRIMARY}
|
|
ethNumberOfDecimals={4}
|
|
hideTitle
|
|
/>
|
|
) : (
|
|
<Spinner
|
|
color="var(--color-secondary-default)"
|
|
className="loading-overlay__spinner"
|
|
/>
|
|
)}
|
|
{balanceIsCached ? (
|
|
<span className="eth-overview__cached-star">*</span>
|
|
) : null}
|
|
{
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-main,build-beta,build-flask)
|
|
<ButtonIcon
|
|
className="eth-overview__portfolio-button"
|
|
data-testid="home__portfolio-site"
|
|
color={IconColor.primaryDefault}
|
|
iconName={IconName.Diagram}
|
|
ariaLabel={t('portfolio')}
|
|
size={ButtonIconSize.Lg}
|
|
onClick={() => {
|
|
const portfolioUrl = getPortfolioUrl(
|
|
'',
|
|
'ext',
|
|
metaMetricsId,
|
|
);
|
|
global.platform.openTab({
|
|
url: portfolioUrl,
|
|
});
|
|
trackEvent(
|
|
{
|
|
category: MetaMetricsEventCategory.Home,
|
|
event: MetaMetricsEventName.PortfolioLinkClicked,
|
|
properties: {
|
|
url: portfolioUrl,
|
|
},
|
|
},
|
|
{
|
|
contextPropsIntoEventProperties: [
|
|
MetaMetricsContextProp.PageTitle,
|
|
],
|
|
},
|
|
);
|
|
}}
|
|
/>
|
|
///: END:ONLY_INCLUDE_IN
|
|
}
|
|
</div>
|
|
{showFiat && 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>
|
|
}
|
|
buttons={
|
|
<>
|
|
{
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-main,build-beta,build-flask)
|
|
<IconButton
|
|
className="eth-overview__button"
|
|
Icon={
|
|
<Icon name={IconName.Add} color={IconColor.primaryInverse} />
|
|
}
|
|
disabled={!isBuyableChain}
|
|
data-testid="eth-overview-buy"
|
|
label={t('buy')}
|
|
onClick={() => {
|
|
openBuyCryptoInPdapp();
|
|
trackEvent({
|
|
event: MetaMetricsEventName.NavBuyButtonClicked,
|
|
category: MetaMetricsEventCategory.Navigation,
|
|
properties: {
|
|
location: 'Home',
|
|
text: 'Buy',
|
|
chain_id: chainId,
|
|
token_symbol: defaultSwapsToken,
|
|
},
|
|
});
|
|
}}
|
|
/>
|
|
///: END:ONLY_INCLUDE_IN
|
|
}
|
|
|
|
{
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
|
renderInstitutionalButtons()
|
|
///: END:ONLY_INCLUDE_IN
|
|
}
|
|
|
|
<IconButton
|
|
className="eth-overview__button"
|
|
data-testid="eth-overview-send"
|
|
Icon={
|
|
<Icon
|
|
name={IconName.Arrow2UpRight}
|
|
color={IconColor.primaryInverse}
|
|
/>
|
|
}
|
|
label={t('send')}
|
|
onClick={() => {
|
|
trackEvent({
|
|
event: MetaMetricsEventName.NavSendButtonClicked,
|
|
category: MetaMetricsEventCategory.Navigation,
|
|
properties: {
|
|
token_symbol: 'ETH',
|
|
location: 'Home',
|
|
text: 'Send',
|
|
chain_id: chainId,
|
|
},
|
|
});
|
|
dispatch(
|
|
startNewDraftTransaction({ type: AssetType.native }),
|
|
).then(() => {
|
|
history.push(SEND_ROUTE);
|
|
});
|
|
}}
|
|
/>
|
|
<IconButton
|
|
className="eth-overview__button"
|
|
disabled={!isSwapsChain}
|
|
Icon={
|
|
<Icon
|
|
name={IconName.SwapHorizontal}
|
|
color={IconColor.primaryInverse}
|
|
/>
|
|
}
|
|
onClick={() => {
|
|
if (isSwapsChain) {
|
|
trackEvent({
|
|
event: MetaMetricsEventName.NavSwapButtonClicked,
|
|
category: MetaMetricsEventCategory.Swaps,
|
|
properties: {
|
|
token_symbol: 'ETH',
|
|
location: MetaMetricsSwapsEventSource.MainView,
|
|
text: 'Swap',
|
|
chain_id: chainId,
|
|
},
|
|
});
|
|
dispatch(setSwapsFromToken(defaultSwapsToken));
|
|
if (usingHardwareWallet) {
|
|
global.platform.openExtensionInBrowser(BUILD_QUOTE_ROUTE);
|
|
} else {
|
|
history.push(BUILD_QUOTE_ROUTE);
|
|
}
|
|
}
|
|
}}
|
|
label={t('swap')}
|
|
tooltipRender={
|
|
isSwapsChain
|
|
? null
|
|
: (contents) => (
|
|
<Tooltip
|
|
title={t('currentlyUnavailable')}
|
|
position="bottom"
|
|
>
|
|
{contents}
|
|
</Tooltip>
|
|
)
|
|
}
|
|
/>
|
|
{
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-main,build-beta,build-flask)
|
|
<IconButton
|
|
className="eth-overview__button"
|
|
disabled={!isBridgeChain}
|
|
data-testid="eth-overview-bridge"
|
|
Icon={
|
|
<Icon name={IconName.Bridge} color={IconColor.primaryInverse} />
|
|
}
|
|
label={t('bridge')}
|
|
onClick={() => {
|
|
if (isBridgeChain) {
|
|
const portfolioUrl = getPortfolioUrl(
|
|
'bridge',
|
|
'ext_bridge_button',
|
|
metaMetricsId,
|
|
);
|
|
global.platform.openTab({
|
|
url: `${portfolioUrl}${
|
|
location.pathname.includes('asset') ? '&token=native' : ''
|
|
}`,
|
|
});
|
|
trackEvent({
|
|
category: MetaMetricsEventCategory.Navigation,
|
|
event: MetaMetricsEventName.BridgeLinkClicked,
|
|
properties: {
|
|
location: 'Home',
|
|
text: 'Bridge',
|
|
chain_id: chainId,
|
|
token_symbol: 'ETH',
|
|
},
|
|
});
|
|
}
|
|
}}
|
|
tooltipRender={
|
|
isBridgeChain
|
|
? null
|
|
: (contents) => (
|
|
<Tooltip
|
|
title={t('currentlyUnavailable')}
|
|
position="bottom"
|
|
>
|
|
{contents}
|
|
</Tooltip>
|
|
)
|
|
}
|
|
/>
|
|
///: END:ONLY_INCLUDE_IN
|
|
}
|
|
</>
|
|
}
|
|
className={className}
|
|
/>
|
|
);
|
|
};
|
|
|
|
EthOverview.propTypes = {
|
|
className: PropTypes.string,
|
|
};
|
|
|
|
EthOverview.defaultProps = {
|
|
className: undefined,
|
|
};
|
|
|
|
export default EthOverview;
|