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';
|
|
|
|
import { useHistory } from 'react-router-dom';
|
2020-05-21 19:33:48 +02:00
|
|
|
|
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,
|
|
|
|
BUTTON_ICON_SIZES,
|
|
|
|
} from '../../component-library/button-icon/deprecated';
|
2023-04-04 18:48:04 +02:00
|
|
|
import { Icon, ICON_NAMES } from '../../component-library/icon/deprecated';
|
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();
|
|
|
|
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-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-19 18:52:53 +02:00
|
|
|
{process.env.MULTICHAIN ? null : (
|
|
|
|
<ButtonIcon
|
|
|
|
className="eth-overview__portfolio-button"
|
|
|
|
data-testid="home__portfolio-site"
|
|
|
|
color={IconColor.primaryDefault}
|
|
|
|
iconName={ICON_NAMES.DIAGRAM}
|
|
|
|
ariaLabel={t('portfolio')}
|
|
|
|
size={BUTTON_ICON_SIZES.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-03-06 20:34:06 +01:00
|
|
|
},
|
2023-04-19 18:52:53 +02:00
|
|
|
{
|
|
|
|
contextPropsIntoEventProperties: [
|
|
|
|
MetaMetricsContextProp.PageTitle,
|
|
|
|
],
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
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={
|
|
|
|
<>
|
|
|
|
<IconButton
|
|
|
|
className="eth-overview__button"
|
|
|
|
Icon={
|
2023-03-13 20:14:43 +01:00
|
|
|
<Icon name={ICON_NAMES.ADD} color={IconColor.primaryInverse} />
|
2023-03-01 09:45:27 +01:00
|
|
|
}
|
|
|
|
disabled={!isBuyableChain}
|
|
|
|
data-testid="eth-overview-buy"
|
|
|
|
label={t('buy')}
|
|
|
|
onClick={() => {
|
|
|
|
openBuyCryptoInPdapp();
|
|
|
|
trackEvent({
|
2023-04-03 17:31:04 +02:00
|
|
|
event: MetaMetricsEventName.NavBuyButtonClicked,
|
|
|
|
category: MetaMetricsEventCategory.Navigation,
|
2023-03-01 09:45:27 +01:00
|
|
|
properties: {
|
|
|
|
location: 'Home',
|
|
|
|
text: 'Buy',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<IconButton
|
|
|
|
className="eth-overview__button"
|
|
|
|
data-testid="eth-overview-send"
|
|
|
|
Icon={
|
|
|
|
<Icon
|
2023-04-07 02:43:15 +02:00
|
|
|
name={ICON_NAMES.ARROW_2_UP_RIGHT}
|
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
|
|
|
|
name={ICON_NAMES.SWAP_HORIZONTAL}
|
|
|
|
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>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<IconButton
|
|
|
|
className="eth-overview__button"
|
2023-03-23 18:24:10 +01:00
|
|
|
disabled={!isBridgeChain}
|
2023-03-06 20:34:06 +01:00
|
|
|
data-testid="eth-overview-bridge"
|
2023-03-01 09:45:27 +01:00
|
|
|
Icon={
|
2023-03-06 20:34:06 +01:00
|
|
|
<Icon name={ICON_NAMES.BRIDGE} color={IconColor.primaryInverse} />
|
2023-03-01 09:45:27 +01:00
|
|
|
}
|
2023-03-06 20:34:06 +01:00
|
|
|
label={t('bridge')}
|
2023-03-01 09:45:27 +01:00
|
|
|
onClick={() => {
|
2023-03-23 18:24:10 +01:00
|
|
|
if (isBridgeChain) {
|
|
|
|
const portfolioUrl = process.env.PORTFOLIO_URL;
|
|
|
|
const bridgeUrl = `${portfolioUrl}/bridge`;
|
|
|
|
global.platform.openTab({
|
|
|
|
url: `${bridgeUrl}?metamaskEntry=ext`,
|
|
|
|
});
|
|
|
|
trackEvent({
|
2023-04-03 17:31:04 +02:00
|
|
|
category: MetaMetricsEventCategory.Navigation,
|
|
|
|
event: MetaMetricsEventName.BridgeLinkClicked,
|
2023-03-23 18:24:10 +01:00
|
|
|
properties: {
|
|
|
|
location: 'Home',
|
|
|
|
text: 'Bridge',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2023-03-01 09:45:27 +01:00
|
|
|
}}
|
2023-03-23 18:24:10 +01:00
|
|
|
tooltipRender={
|
|
|
|
isBridgeChain
|
|
|
|
? null
|
|
|
|
: (contents) => (
|
|
|
|
<Tooltip
|
|
|
|
title={t('currentlyUnavailable')}
|
|
|
|
position="bottom"
|
|
|
|
>
|
|
|
|
{contents}
|
|
|
|
</Tooltip>
|
|
|
|
)
|
|
|
|
}
|
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;
|