2023-03-01 09:45:27 +01:00
|
|
|
import React, { useContext } from 'react';
|
2021-02-04 19:15:23 +01:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { useDispatch, useSelector } from 'react-redux';
|
|
|
|
import classnames from 'classnames';
|
2023-04-21 04:27:18 +02:00
|
|
|
import { useHistory, useLocation } from 'react-router-dom';
|
2020-05-21 19:33:48 +02:00
|
|
|
|
2023-04-25 16:32:51 +02:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
2023-04-21 13:16:09 +02:00
|
|
|
import {
|
|
|
|
getMmiPortfolioEnabled,
|
|
|
|
getMmiPortfolioUrl,
|
|
|
|
} from '../../../selectors/institutional/selectors';
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
import { I18nContext } from '../../../contexts/i18n';
|
2020-11-03 00:41:28 +01:00
|
|
|
import {
|
|
|
|
SEND_ROUTE,
|
|
|
|
BUILD_QUOTE_ROUTE,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../../helpers/constants/routes';
|
|
|
|
import Tooltip from '../../ui/tooltip';
|
|
|
|
import UserPreferencedCurrencyDisplay from '../user-preferenced-currency-display';
|
|
|
|
import { PRIMARY, SECONDARY } from '../../../helpers/constants/common';
|
2020-11-03 00:41:28 +01:00
|
|
|
import {
|
|
|
|
isBalanceCached,
|
|
|
|
getShouldShowFiat,
|
|
|
|
getCurrentKeyring,
|
2021-03-18 11:20:06 +01:00
|
|
|
getSwapsDefaultToken,
|
|
|
|
getIsSwapsChain,
|
2023-03-23 18:24:10 +01:00
|
|
|
getIsBridgeChain,
|
2022-01-28 14:46:26 +01:00
|
|
|
getIsBuyableChain,
|
2022-06-13 21:39:48 +02:00
|
|
|
getSelectedAccountCachedBalance,
|
2023-04-27 16:28:08 +02:00
|
|
|
getCurrentChainId,
|
|
|
|
getMetaMetricsId,
|
2023-02-02 21:15:26 +01:00
|
|
|
} from '../../../selectors';
|
2021-04-14 09:16:27 +02:00
|
|
|
import { setSwapsFromToken } from '../../../ducks/swaps/swaps';
|
2021-02-04 19:15:23 +01:00
|
|
|
import IconButton from '../../ui/icon-button';
|
2021-10-28 01:54:18 +02:00
|
|
|
import { isHardwareKeyring } from '../../../helpers/utils/hardware';
|
2022-04-01 21:11:12 +02:00
|
|
|
import { MetaMetricsContext } from '../../../contexts/metametrics';
|
2023-02-21 16:32:08 +01:00
|
|
|
import {
|
2023-04-03 17:31:04 +02:00
|
|
|
MetaMetricsEventCategory,
|
|
|
|
MetaMetricsEventName,
|
|
|
|
MetaMetricsSwapsEventSource,
|
2023-02-21 16:32:08 +01:00
|
|
|
} from '../../../../shared/constants/metametrics';
|
2022-06-13 21:39:48 +02:00
|
|
|
import Spinner from '../../ui/spinner';
|
2022-07-01 15:58:35 +02:00
|
|
|
import { startNewDraftTransaction } from '../../../ducks/send';
|
2023-01-18 15:47:29 +01:00
|
|
|
import { AssetType } from '../../../../shared/constants/transaction';
|
2023-06-23 13:58:41 +02:00
|
|
|
import { Icon, IconName } from '../../component-library';
|
2023-02-02 21:15:26 +01:00
|
|
|
import { IconColor } from '../../../helpers/constants/design-system';
|
2023-03-01 09:45:27 +01:00
|
|
|
import useRamps from '../../../hooks/experiences/useRamps';
|
2023-04-27 16:28:08 +02:00
|
|
|
import { getPortfolioUrl } from '../../../helpers/utils/portfolio';
|
2021-02-04 19:15:23 +01:00
|
|
|
import WalletOverview from './wallet-overview';
|
2020-05-21 19:33:48 +02:00
|
|
|
|
2023-06-26 18:13:26 +02:00
|
|
|
const EthOverview = ({ className, showAddress }) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const dispatch = useDispatch();
|
|
|
|
const t = useContext(I18nContext);
|
2022-03-14 19:12:38 +01:00
|
|
|
const trackEvent = useContext(MetaMetricsContext);
|
2021-02-04 19:15:23 +01:00
|
|
|
const history = useHistory();
|
2023-04-21 04:27:18 +02:00
|
|
|
const location = useLocation();
|
2021-02-04 19:15:23 +01:00
|
|
|
const keyring = useSelector(getCurrentKeyring);
|
2022-02-22 16:59:31 +01:00
|
|
|
const usingHardwareWallet = isHardwareKeyring(keyring?.type);
|
2021-02-04 19:15:23 +01:00
|
|
|
const balanceIsCached = useSelector(isBalanceCached);
|
|
|
|
const showFiat = useSelector(getShouldShowFiat);
|
2022-06-13 21:39:48 +02:00
|
|
|
const balance = useSelector(getSelectedAccountCachedBalance);
|
2021-03-18 11:20:06 +01:00
|
|
|
const isSwapsChain = useSelector(getIsSwapsChain);
|
2023-03-23 18:24:10 +01:00
|
|
|
const isBridgeChain = useSelector(getIsBridgeChain);
|
2022-01-28 14:46:26 +01:00
|
|
|
const isBuyableChain = useSelector(getIsBuyableChain);
|
2021-03-18 11:20:06 +01:00
|
|
|
const defaultSwapsToken = useSelector(getSwapsDefaultToken);
|
2023-04-27 16:28:08 +02:00
|
|
|
const chainId = useSelector(getCurrentChainId);
|
|
|
|
const metaMetricsId = useSelector(getMetaMetricsId);
|
2020-05-21 19:33:48 +02:00
|
|
|
|
2023-04-25 16:32:51 +02:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
2023-04-21 13:16:09 +02:00
|
|
|
const mmiPortfolioEnabled = useSelector(getMmiPortfolioEnabled);
|
|
|
|
const mmiPortfolioUrl = useSelector(getMmiPortfolioUrl);
|
|
|
|
|
|
|
|
const portfolioEvent = () => {
|
|
|
|
trackEvent({
|
2023-07-18 15:55:37 +02:00
|
|
|
category: MetaMetricsEventCategory.Navigation,
|
|
|
|
event: MetaMetricsEventName.MMIPortfolioButtonClicked,
|
2023-04-21 13:16:09 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const stakingEvent = () => {
|
|
|
|
trackEvent({
|
2023-07-18 15:55:37 +02:00
|
|
|
category: MetaMetricsEventCategory.Navigation,
|
|
|
|
event: MetaMetricsEventName.MMIPortfolioButtonClicked,
|
2023-04-21 13:16:09 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const renderInstitutionalButtons = () => {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<IconButton
|
|
|
|
className="eth-overview__button"
|
2023-06-23 11:54:59 +02:00
|
|
|
Icon={<Icon name={IconName.Stake} color={IconColor.primaryInverse} />}
|
2023-04-21 13:16:09 +02:00
|
|
|
label={t('stake')}
|
|
|
|
onClick={() => {
|
|
|
|
stakingEvent();
|
|
|
|
global.platform.openTab({
|
|
|
|
url: 'https://metamask-institutional.io/staking',
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
{mmiPortfolioEnabled && (
|
|
|
|
<IconButton
|
|
|
|
className="eth-overview__button"
|
|
|
|
Icon={
|
2023-06-23 11:54:59 +02:00
|
|
|
<Icon name={IconName.Diagram} color={IconColor.primaryInverse} />
|
2023-04-21 13:16:09 +02:00
|
|
|
}
|
|
|
|
label={t('portfolio')}
|
|
|
|
onClick={() => {
|
|
|
|
portfolioEvent();
|
|
|
|
window.open(mmiPortfolioUrl, '_blank');
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
|
|
|
|
2023-03-01 09:45:27 +01:00
|
|
|
const { openBuyCryptoInPdapp } = useRamps();
|
|
|
|
|
2020-05-21 19:33:48 +02:00
|
|
|
return (
|
2023-03-01 09:45:27 +01:00
|
|
|
<WalletOverview
|
2023-06-26 18:13:26 +02:00
|
|
|
showAddress={showAddress}
|
2023-03-01 09:45:27 +01:00
|
|
|
balance={
|
|
|
|
<Tooltip
|
|
|
|
position="top"
|
|
|
|
title={t('balanceOutdated')}
|
|
|
|
disabled={!balanceIsCached}
|
|
|
|
>
|
|
|
|
<div className="eth-overview__balance">
|
|
|
|
<div className="eth-overview__primary-container">
|
|
|
|
{balance ? (
|
2022-06-13 21:39:48 +02:00
|
|
|
<UserPreferencedCurrencyDisplay
|
2023-03-13 16:50:12 +01:00
|
|
|
style={{ display: 'contents' }}
|
2023-03-01 09:45:27 +01:00
|
|
|
className={classnames('eth-overview__primary-balance', {
|
|
|
|
'eth-overview__cached-balance': balanceIsCached,
|
2022-06-13 21:39:48 +02:00
|
|
|
})}
|
2023-03-01 09:45:27 +01:00
|
|
|
data-testid="eth-overview__primary-currency"
|
2022-06-13 21:39:48 +02:00
|
|
|
value={balance}
|
2023-03-01 09:45:27 +01:00
|
|
|
type={PRIMARY}
|
2022-06-13 21:39:48 +02:00
|
|
|
ethNumberOfDecimals={4}
|
|
|
|
hideTitle
|
|
|
|
/>
|
2023-03-01 09:45:27 +01:00
|
|
|
) : (
|
|
|
|
<Spinner
|
|
|
|
color="var(--color-secondary-default)"
|
|
|
|
className="loading-overlay__spinner"
|
|
|
|
/>
|
2022-06-13 21:39:48 +02:00
|
|
|
)}
|
2023-03-01 09:45:27 +01:00
|
|
|
{balanceIsCached ? (
|
|
|
|
<span className="eth-overview__cached-star">*</span>
|
|
|
|
) : null}
|
2020-05-21 19:33:48 +02:00
|
|
|
</div>
|
2023-03-01 09:45:27 +01:00
|
|
|
{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={
|
|
|
|
<>
|
2023-04-21 13:16:09 +02:00
|
|
|
{
|
2023-04-25 16:32:51 +02:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-main,build-beta,build-flask)
|
2023-04-21 13:16:09 +02:00
|
|
|
<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',
|
2023-04-27 16:28:08 +02:00
|
|
|
chain_id: chainId,
|
|
|
|
token_symbol: defaultSwapsToken,
|
2023-04-21 13:16:09 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2023-04-25 16:32:51 +02:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
2023-04-21 13:16:09 +02:00
|
|
|
renderInstitutionalButtons()
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
|
|
|
}
|
|
|
|
|
2023-03-01 09:45:27 +01:00
|
|
|
<IconButton
|
|
|
|
className="eth-overview__button"
|
|
|
|
data-testid="eth-overview-send"
|
|
|
|
Icon={
|
|
|
|
<Icon
|
2023-04-19 23:16:49 +02:00
|
|
|
name={IconName.Arrow2UpRight}
|
2023-03-01 09:45:27 +01:00
|
|
|
color={IconColor.primaryInverse}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
label={t('send')}
|
|
|
|
onClick={() => {
|
|
|
|
trackEvent({
|
2023-04-03 17:31:04 +02:00
|
|
|
event: MetaMetricsEventName.NavSendButtonClicked,
|
|
|
|
category: MetaMetricsEventCategory.Navigation,
|
2023-03-01 09:45:27 +01:00
|
|
|
properties: {
|
|
|
|
token_symbol: 'ETH',
|
|
|
|
location: 'Home',
|
|
|
|
text: 'Send',
|
2023-04-27 16:28:08 +02:00
|
|
|
chain_id: chainId,
|
2023-03-01 09:45:27 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
dispatch(
|
|
|
|
startNewDraftTransaction({ type: AssetType.native }),
|
|
|
|
).then(() => {
|
|
|
|
history.push(SEND_ROUTE);
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<IconButton
|
|
|
|
className="eth-overview__button"
|
|
|
|
disabled={!isSwapsChain}
|
|
|
|
Icon={
|
|
|
|
<Icon
|
2023-04-19 23:16:49 +02:00
|
|
|
name={IconName.SwapHorizontal}
|
2023-03-01 09:45:27 +01:00
|
|
|
color={IconColor.primaryInverse}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
onClick={() => {
|
|
|
|
if (isSwapsChain) {
|
2022-03-25 14:21:29 +01:00
|
|
|
trackEvent({
|
2023-04-03 17:31:04 +02:00
|
|
|
event: MetaMetricsEventName.NavSwapButtonClicked,
|
|
|
|
category: MetaMetricsEventCategory.Swaps,
|
2022-03-25 14:21:29 +01:00
|
|
|
properties: {
|
2022-08-16 18:39:23 +02:00
|
|
|
token_symbol: 'ETH',
|
2023-04-03 17:31:04 +02:00
|
|
|
location: MetaMetricsSwapsEventSource.MainView,
|
2023-03-01 09:45:27 +01:00
|
|
|
text: 'Swap',
|
2023-04-27 16:28:08 +02:00
|
|
|
chain_id: chainId,
|
2022-03-25 14:21:29 +01:00
|
|
|
},
|
|
|
|
});
|
2023-03-01 09:45:27 +01:00
|
|
|
dispatch(setSwapsFromToken(defaultSwapsToken));
|
|
|
|
if (usingHardwareWallet) {
|
|
|
|
global.platform.openExtensionInBrowser(BUILD_QUOTE_ROUTE);
|
|
|
|
} else {
|
|
|
|
history.push(BUILD_QUOTE_ROUTE);
|
2020-10-06 20:28:38 +02:00
|
|
|
}
|
2023-02-21 16:32:08 +01:00
|
|
|
}
|
2023-03-01 09:45:27 +01:00
|
|
|
}}
|
|
|
|
label={t('swap')}
|
2023-06-15 20:17:21 +02:00
|
|
|
data-testid="token-overview-button-swap"
|
2023-03-01 09:45:27 +01:00
|
|
|
tooltipRender={
|
|
|
|
isSwapsChain
|
|
|
|
? null
|
|
|
|
: (contents) => (
|
|
|
|
<Tooltip
|
|
|
|
title={t('currentlyUnavailable')}
|
|
|
|
position="bottom"
|
|
|
|
>
|
|
|
|
{contents}
|
|
|
|
</Tooltip>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
/>
|
2023-04-21 13:16:09 +02:00
|
|
|
{
|
2023-04-25 16:32:51 +02:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-main,build-beta,build-flask)
|
2023-04-21 13:16:09 +02:00
|
|
|
<IconButton
|
|
|
|
className="eth-overview__button"
|
|
|
|
disabled={!isBridgeChain}
|
|
|
|
data-testid="eth-overview-bridge"
|
|
|
|
Icon={
|
|
|
|
<Icon name={IconName.Bridge} color={IconColor.primaryInverse} />
|
2023-03-23 18:24:10 +01:00
|
|
|
}
|
2023-04-21 13:16:09 +02:00
|
|
|
label={t('bridge')}
|
|
|
|
onClick={() => {
|
|
|
|
if (isBridgeChain) {
|
2023-04-27 16:28:08 +02:00
|
|
|
const portfolioUrl = getPortfolioUrl(
|
|
|
|
'bridge',
|
|
|
|
'ext_bridge_button',
|
|
|
|
metaMetricsId,
|
|
|
|
);
|
2023-04-21 13:16:09 +02:00
|
|
|
global.platform.openTab({
|
2023-04-27 16:28:08 +02:00
|
|
|
url: `${portfolioUrl}${
|
2023-04-21 13:16:09 +02:00
|
|
|
location.pathname.includes('asset') ? '&token=native' : ''
|
|
|
|
}`,
|
|
|
|
});
|
|
|
|
trackEvent({
|
|
|
|
category: MetaMetricsEventCategory.Navigation,
|
|
|
|
event: MetaMetricsEventName.BridgeLinkClicked,
|
|
|
|
properties: {
|
|
|
|
location: 'Home',
|
|
|
|
text: 'Bridge',
|
2023-04-27 16:28:08 +02:00
|
|
|
chain_id: chainId,
|
|
|
|
token_symbol: 'ETH',
|
2023-04-21 13:16:09 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
tooltipRender={
|
|
|
|
isBridgeChain
|
|
|
|
? null
|
|
|
|
: (contents) => (
|
|
|
|
<Tooltip
|
|
|
|
title={t('currentlyUnavailable')}
|
|
|
|
position="bottom"
|
|
|
|
>
|
|
|
|
{contents}
|
|
|
|
</Tooltip>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
|
|
|
}
|
2023-06-15 15:17:29 +02:00
|
|
|
{
|
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-main,build-beta,build-flask)
|
|
|
|
<IconButton
|
|
|
|
className="eth-overview__button"
|
|
|
|
data-testid="eth-overview-portfolio"
|
|
|
|
Icon={
|
|
|
|
<Icon
|
|
|
|
name={IconName.Diagram}
|
|
|
|
color={IconColor.primaryInverse}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
label={t('portfolio')}
|
|
|
|
onClick={() => {
|
|
|
|
const url = getPortfolioUrl(
|
|
|
|
'',
|
|
|
|
'ext_portfolio_button',
|
|
|
|
metaMetricsId,
|
|
|
|
);
|
|
|
|
global.platform.openTab({ url });
|
|
|
|
trackEvent({
|
|
|
|
category: MetaMetricsEventCategory.Navigation,
|
|
|
|
event: MetaMetricsEventName.PortfolioLinkClicked,
|
|
|
|
properties: {
|
|
|
|
location: 'Home',
|
|
|
|
text: 'Portfolio',
|
|
|
|
chain_id: chainId,
|
|
|
|
token_symbol: 'ETH',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
|
|
|
}
|
2023-03-01 09:45:27 +01:00
|
|
|
</>
|
|
|
|
}
|
|
|
|
className={className}
|
|
|
|
/>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
};
|
2020-05-21 19:33:48 +02:00
|
|
|
|
|
|
|
EthOverview.propTypes = {
|
2020-06-01 19:54:32 +02:00
|
|
|
className: PropTypes.string,
|
2023-06-26 18:13:26 +02:00
|
|
|
showAddress: PropTypes.bool,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-05-21 19:33:48 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
export default EthOverview;
|