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 Identicon from '../../ui/identicon';
|
|
|
|
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,
|
2021-04-02 00:57:00 +02:00
|
|
|
getNativeCurrencyImage,
|
2022-06-13 21:39:48 +02:00
|
|
|
getSelectedAccountCachedBalance,
|
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
|
|
|
MetaMetricsContextProp,
|
|
|
|
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-04-12 17:55:24 +02:00
|
|
|
import {
|
|
|
|
ButtonIcon,
|
2023-04-19 23:16:49 +02:00
|
|
|
ButtonIconSize,
|
|
|
|
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';
|
2021-02-04 19:15:23 +01:00
|
|
|
import WalletOverview from './wallet-overview';
|
2020-05-21 19:33:48 +02:00
|
|
|
|
2020-06-01 19:54:32 +02:00
|
|
|
const EthOverview = ({ className }) => {
|
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-04-02 00:57:00 +02:00
|
|
|
const primaryTokenImage = useSelector(getNativeCurrencyImage);
|
2021-03-18 11:20:06 +01:00
|
|
|
const defaultSwapsToken = useSelector(getSwapsDefaultToken);
|
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({
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
loading={!balance}
|
|
|
|
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}
|
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
|
|
|
process.env.MULTICHAIN ? null : (
|
|
|
|
<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 = process.env.PORTFOLIO_URL;
|
|
|
|
global.platform.openTab({
|
|
|
|
url: `${portfolioUrl}?metamaskEntry=ext`,
|
|
|
|
});
|
|
|
|
trackEvent(
|
|
|
|
{
|
|
|
|
category: MetaMetricsEventCategory.Home,
|
|
|
|
event: MetaMetricsEventName.PortfolioLinkClicked,
|
|
|
|
properties: {
|
|
|
|
url: portfolioUrl,
|
|
|
|
},
|
2023-04-19 18:52:53 +02:00
|
|
|
},
|
2023-04-21 13:16:09 +02:00
|
|
|
{
|
|
|
|
contextPropsIntoEventProperties: [
|
|
|
|
MetaMetricsContextProp.PageTitle,
|
|
|
|
],
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
|
|
|
}
|
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',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
///: 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',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
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',
|
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')}
|
|
|
|
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) {
|
|
|
|
const portfolioUrl = process.env.PORTFOLIO_URL;
|
|
|
|
const bridgeUrl = `${portfolioUrl}/bridge`;
|
|
|
|
global.platform.openTab({
|
|
|
|
url: `${bridgeUrl}?metamaskEntry=ext_bridge_button${
|
|
|
|
location.pathname.includes('asset') ? '&token=native' : ''
|
|
|
|
}`,
|
|
|
|
});
|
|
|
|
trackEvent({
|
|
|
|
category: MetaMetricsEventCategory.Navigation,
|
|
|
|
event: MetaMetricsEventName.BridgeLinkClicked,
|
|
|
|
properties: {
|
|
|
|
location: 'Home',
|
|
|
|
text: 'Bridge',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
tooltipRender={
|
|
|
|
isBridgeChain
|
|
|
|
? null
|
|
|
|
: (contents) => (
|
|
|
|
<Tooltip
|
|
|
|
title={t('currentlyUnavailable')}
|
|
|
|
position="bottom"
|
|
|
|
>
|
|
|
|
{contents}
|
|
|
|
</Tooltip>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
|
|
|
}
|
2023-03-01 09:45:27 +01:00
|
|
|
</>
|
|
|
|
}
|
|
|
|
className={className}
|
2023-04-19 17:25:19 +02:00
|
|
|
icon={<Identicon diameter={32} image={primaryTokenImage} />}
|
2023-03-01 09:45:27 +01:00
|
|
|
/>
|
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,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-05-21 19:33:48 +02:00
|
|
|
|
2020-06-01 19:54:32 +02:00
|
|
|
EthOverview.defaultProps = {
|
|
|
|
className: undefined,
|
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;
|