You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
402 lines
13 KiB
402 lines
13 KiB
4 years ago
|
import React, { PureComponent } from 'react';
|
||
|
import PropTypes from 'prop-types';
|
||
|
import { Redirect, Route } from 'react-router-dom';
|
||
|
import { formatDate } from '../../helpers/utils/util';
|
||
|
import AssetList from '../../components/app/asset-list';
|
||
|
import HomeNotification from '../../components/app/home-notification';
|
||
|
import MultipleNotifications from '../../components/app/multiple-notifications';
|
||
|
import TransactionList from '../../components/app/transaction-list';
|
||
|
import MenuBar from '../../components/app/menu-bar';
|
||
|
import Popover from '../../components/ui/popover';
|
||
|
import Button from '../../components/ui/button';
|
||
|
import ConnectedSites from '../connected-sites';
|
||
|
import ConnectedAccounts from '../connected-accounts';
|
||
|
import { Tabs, Tab } from '../../components/ui/tabs';
|
||
|
import { EthOverview } from '../../components/app/wallet-overview';
|
||
4 years ago
|
import WhatsNewPopup from '../../components/app/whats-new-popup';
|
||
6 years ago
|
|
||
6 years ago
|
import {
|
||
5 years ago
|
ASSET_ROUTE,
|
||
6 years ago
|
RESTORE_VAULT_ROUTE,
|
||
|
CONFIRM_TRANSACTION_ROUTE,
|
||
6 years ago
|
CONFIRM_ADD_SUGGESTED_TOKEN_ROUTE,
|
||
5 years ago
|
INITIALIZE_BACKUP_SEED_PHRASE_ROUTE,
|
||
5 years ago
|
CONNECT_ROUTE,
|
||
5 years ago
|
CONNECTED_ROUTE,
|
||
5 years ago
|
CONNECTED_ACCOUNTS_ROUTE,
|
||
4 years ago
|
AWAITING_SWAP_ROUTE,
|
||
|
BUILD_QUOTE_ROUTE,
|
||
|
VIEW_QUOTE_ROUTE,
|
||
4 years ago
|
CONFIRMATION_V_NEXT_ROUTE,
|
||
4 years ago
|
} from '../../helpers/constants/routes';
|
||
6 years ago
|
|
||
4 years ago
|
const LEARN_MORE_URL =
|
||
4 years ago
|
'https://metamask.zendesk.com/hc/en-us/articles/360045129011-Intro-to-MetaMask-v8-extension';
|
||
4 years ago
|
const LEGACY_WEB3_URL =
|
||
4 years ago
|
'https://metamask.zendesk.com/hc/en-us/articles/360053147012';
|
||
4 years ago
|
const INFURA_BLOCKAGE_URL =
|
||
|
'https://metamask.zendesk.com/hc/en-us/articles/360059386712';
|
||
5 years ago
|
|
||
6 years ago
|
export default class Home extends PureComponent {
|
||
5 years ago
|
static contextTypes = {
|
||
|
t: PropTypes.func,
|
||
4 years ago
|
};
|
||
5 years ago
|
|
||
6 years ago
|
static propTypes = {
|
||
|
history: PropTypes.object,
|
||
|
forgottenPassword: PropTypes.bool,
|
||
6 years ago
|
suggestedTokens: PropTypes.object,
|
||
6 years ago
|
unconfirmedTransactionsCount: PropTypes.number,
|
||
4 years ago
|
shouldShowSeedPhraseReminder: PropTypes.bool.isRequired,
|
||
5 years ago
|
isPopup: PropTypes.bool,
|
||
5 years ago
|
isNotification: PropTypes.bool.isRequired,
|
||
5 years ago
|
threeBoxSynced: PropTypes.bool,
|
||
|
setupThreeBox: PropTypes.func,
|
||
|
turnThreeBoxSyncingOn: PropTypes.func,
|
||
5 years ago
|
showRestorePrompt: PropTypes.bool,
|
||
5 years ago
|
selectedAddress: PropTypes.string,
|
||
|
restoreFromThreeBox: PropTypes.func,
|
||
5 years ago
|
setShowRestorePromptToFalse: PropTypes.func,
|
||
5 years ago
|
threeBoxLastUpdated: PropTypes.number,
|
||
5 years ago
|
firstPermissionsRequestId: PropTypes.string,
|
||
5 years ago
|
totalUnapprovedCount: PropTypes.number.isRequired,
|
||
5 years ago
|
setConnectedStatusPopoverHasBeenShown: PropTypes.func,
|
||
|
connectedStatusPopoverHasBeenShown: PropTypes.bool,
|
||
5 years ago
|
defaultHomeActiveTabName: PropTypes.string,
|
||
5 years ago
|
onTabClick: PropTypes.func.isRequired,
|
||
4 years ago
|
haveSwapsQuotes: PropTypes.bool.isRequired,
|
||
|
showAwaitingSwapScreen: PropTypes.bool.isRequired,
|
||
|
swapsFetchParams: PropTypes.object,
|
||
4 years ago
|
shouldShowWeb3ShimUsageNotification: PropTypes.bool.isRequired,
|
||
|
setWeb3ShimUsageAlertDismissed: PropTypes.func.isRequired,
|
||
|
originOfCurrentTab: PropTypes.string,
|
||
|
disableWeb3ShimUsageAlert: PropTypes.func.isRequired,
|
||
4 years ago
|
pendingConfirmations: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||
4 years ago
|
infuraBlocked: PropTypes.bool.isRequired,
|
||
4 years ago
|
showWhatsNewPopup: PropTypes.bool.isRequired,
|
||
|
hideWhatsNewPopup: PropTypes.func.isRequired,
|
||
|
notificationsToShow: PropTypes.bool.isRequired,
|
||
4 years ago
|
};
|
||
6 years ago
|
|
||
4 years ago
|
state = {
|
||
|
mounted: false,
|
||
4 years ago
|
canShowBlockageNotification: true,
|
||
4 years ago
|
};
|
||
6 years ago
|
|
||
4 years ago
|
componentDidMount() {
|
||
6 years ago
|
const {
|
||
4 years ago
|
firstPermissionsRequestId,
|
||
6 years ago
|
history,
|
||
5 years ago
|
isNotification,
|
||
6 years ago
|
suggestedTokens = {},
|
||
5 years ago
|
totalUnapprovedCount,
|
||
4 years ago
|
unconfirmedTransactionsCount,
|
||
4 years ago
|
haveSwapsQuotes,
|
||
|
showAwaitingSwapScreen,
|
||
|
swapsFetchParams,
|
||
4 years ago
|
pendingConfirmations,
|
||
4 years ago
|
} = this.props;
|
||
6 years ago
|
|
||
4 years ago
|
this.setState({ mounted: true });
|
||
5 years ago
|
if (isNotification && totalUnapprovedCount === 0) {
|
||
4 years ago
|
global.platform.closeCurrentWindow();
|
||
4 years ago
|
} else if (!isNotification && showAwaitingSwapScreen) {
|
||
4 years ago
|
history.push(AWAITING_SWAP_ROUTE);
|
||
4 years ago
|
} else if (!isNotification && haveSwapsQuotes) {
|
||
4 years ago
|
history.push(VIEW_QUOTE_ROUTE);
|
||
4 years ago
|
} else if (!isNotification && swapsFetchParams) {
|
||
4 years ago
|
history.push(BUILD_QUOTE_ROUTE);
|
||
4 years ago
|
} else if (firstPermissionsRequestId) {
|
||
4 years ago
|
history.push(`${CONNECT_ROUTE}/${firstPermissionsRequestId}`);
|
||
4 years ago
|
} else if (unconfirmedTransactionsCount > 0) {
|
||
4 years ago
|
history.push(CONFIRM_TRANSACTION_ROUTE);
|
||
4 years ago
|
} else if (Object.keys(suggestedTokens).length > 0) {
|
||
4 years ago
|
history.push(CONFIRM_ADD_SUGGESTED_TOKEN_ROUTE);
|
||
4 years ago
|
} else if (pendingConfirmations.length > 0) {
|
||
4 years ago
|
history.push(CONFIRMATION_V_NEXT_ROUTE);
|
||
5 years ago
|
}
|
||
4 years ago
|
}
|
||
5 years ago
|
|
||
4 years ago
|
static getDerivedStateFromProps(
|
||
4 years ago
|
{
|
||
|
firstPermissionsRequestId,
|
||
|
isNotification,
|
||
|
suggestedTokens,
|
||
|
totalUnapprovedCount,
|
||
|
unconfirmedTransactionsCount,
|
||
4 years ago
|
haveSwapsQuotes,
|
||
|
showAwaitingSwapScreen,
|
||
|
swapsFetchParams,
|
||
4 years ago
|
},
|
||
|
{ mounted },
|
||
|
) {
|
||
|
if (!mounted) {
|
||
|
if (isNotification && totalUnapprovedCount === 0) {
|
||
4 years ago
|
return { closing: true };
|
||
4 years ago
|
} else if (
|
||
|
firstPermissionsRequestId ||
|
||
|
unconfirmedTransactionsCount > 0 ||
|
||
|
Object.keys(suggestedTokens).length > 0 ||
|
||
4 years ago
|
(!isNotification &&
|
||
|
(showAwaitingSwapScreen || haveSwapsQuotes || swapsFetchParams))
|
||
4 years ago
|
) {
|
||
4 years ago
|
return { redirecting: true };
|
||
4 years ago
|
}
|
||
6 years ago
|
}
|
||
4 years ago
|
return null;
|
||
6 years ago
|
}
|
||
|
|
||
4 years ago
|
componentDidUpdate(_, prevState) {
|
||
5 years ago
|
const {
|
||
|
setupThreeBox,
|
||
5 years ago
|
showRestorePrompt,
|
||
5 years ago
|
threeBoxLastUpdated,
|
||
5 years ago
|
threeBoxSynced,
|
||
4 years ago
|
} = this.props;
|
||
5 years ago
|
|
||
4 years ago
|
if (!prevState.closing && this.state.closing) {
|
||
4 years ago
|
global.platform.closeCurrentWindow();
|
||
5 years ago
|
}
|
||
|
|
||
5 years ago
|
if (threeBoxSynced && showRestorePrompt && threeBoxLastUpdated === null) {
|
||
4 years ago
|
setupThreeBox();
|
||
5 years ago
|
}
|
||
|
}
|
||
|
|
||
4 years ago
|
renderNotifications() {
|
||
4 years ago
|
const { t } = this.context;
|
||
6 years ago
|
const {
|
||
6 years ago
|
history,
|
||
5 years ago
|
shouldShowSeedPhraseReminder,
|
||
5 years ago
|
isPopup,
|
||
5 years ago
|
selectedAddress,
|
||
|
restoreFromThreeBox,
|
||
|
turnThreeBoxSyncingOn,
|
||
5 years ago
|
setShowRestorePromptToFalse,
|
||
|
showRestorePrompt,
|
||
5 years ago
|
threeBoxLastUpdated,
|
||
4 years ago
|
shouldShowWeb3ShimUsageNotification,
|
||
|
setWeb3ShimUsageAlertDismissed,
|
||
|
originOfCurrentTab,
|
||
|
disableWeb3ShimUsageAlert,
|
||
4 years ago
|
infuraBlocked,
|
||
4 years ago
|
} = this.props;
|
||
6 years ago
|
|
||
5 years ago
|
return (
|
||
|
<MultipleNotifications>
|
||
4 years ago
|
{shouldShowWeb3ShimUsageNotification ? (
|
||
|
<HomeNotification
|
||
|
descriptionText={t('web3ShimUsageNotification', [
|
||
|
<span
|
||
|
key="web3ShimUsageNotificationLink"
|
||
|
className="home-notification__text-link"
|
||
|
onClick={() =>
|
||
|
global.platform.openTab({ url: LEGACY_WEB3_URL })
|
||
|
}
|
||
|
>
|
||
|
{t('here')}
|
||
|
</span>,
|
||
|
])}
|
||
|
ignoreText={t('dismiss')}
|
||
|
onIgnore={(disable) => {
|
||
4 years ago
|
setWeb3ShimUsageAlertDismissed(originOfCurrentTab);
|
||
4 years ago
|
if (disable) {
|
||
4 years ago
|
disableWeb3ShimUsageAlert();
|
||
4 years ago
|
}
|
||
|
}}
|
||
|
checkboxText={t('dontShowThisAgain')}
|
||
|
checkboxTooltipText={t('canToggleInSettings')}
|
||
|
key="home-web3ShimUsageNotification"
|
||
|
/>
|
||
|
) : null}
|
||
4 years ago
|
{shouldShowSeedPhraseReminder ? (
|
||
|
<HomeNotification
|
||
|
descriptionText={t('backupApprovalNotice')}
|
||
|
acceptText={t('backupNow')}
|
||
|
onAccept={() => {
|
||
|
if (isPopup) {
|
||
|
global.platform.openExtensionInBrowser(
|
||
|
INITIALIZE_BACKUP_SEED_PHRASE_ROUTE,
|
||
4 years ago
|
);
|
||
4 years ago
|
} else {
|
||
4 years ago
|
history.push(INITIALIZE_BACKUP_SEED_PHRASE_ROUTE);
|
||
4 years ago
|
}
|
||
|
}}
|
||
|
infoText={t('backupApprovalInfo')}
|
||
|
key="home-backupApprovalNotice"
|
||
|
/>
|
||
|
) : null}
|
||
|
{threeBoxLastUpdated && showRestorePrompt ? (
|
||
|
<HomeNotification
|
||
|
descriptionText={t('restoreWalletPreferences', [
|
||
|
formatDate(threeBoxLastUpdated, 'M/d/y'),
|
||
|
])}
|
||
|
acceptText={t('restore')}
|
||
|
ignoreText={t('noThanks')}
|
||
|
infoText={t('dataBackupFoundInfo')}
|
||
|
onAccept={() => {
|
||
|
restoreFromThreeBox(selectedAddress).then(() => {
|
||
4 years ago
|
turnThreeBoxSyncingOn();
|
||
|
});
|
||
4 years ago
|
}}
|
||
|
onIgnore={() => {
|
||
4 years ago
|
setShowRestorePromptToFalse();
|
||
4 years ago
|
}}
|
||
|
key="home-privacyModeDefault"
|
||
|
/>
|
||
|
) : null}
|
||
4 years ago
|
{infuraBlocked && this.state.canShowBlockageNotification ? (
|
||
|
<HomeNotification
|
||
|
descriptionText={t('infuraBlockedNotification', [
|
||
|
<span
|
||
|
key="infuraBlockedNotificationLink"
|
||
|
className="home-notification__text-link"
|
||
|
onClick={() =>
|
||
|
global.platform.openTab({ url: INFURA_BLOCKAGE_URL })
|
||
|
}
|
||
|
>
|
||
|
{t('here')}
|
||
|
</span>,
|
||
|
])}
|
||
|
ignoreText={t('dismiss')}
|
||
|
onIgnore={() => {
|
||
|
this.setState({
|
||
|
canShowBlockageNotification: false,
|
||
|
});
|
||
|
}}
|
||
|
key="home-infuraBlockedNotification"
|
||
|
/>
|
||
|
) : null}
|
||
5 years ago
|
</MultipleNotifications>
|
||
4 years ago
|
);
|
||
5 years ago
|
}
|
||
4 years ago
|
|
||
5 years ago
|
renderPopover = () => {
|
||
4 years ago
|
const { setConnectedStatusPopoverHasBeenShown } = this.props;
|
||
|
const { t } = this.context;
|
||
5 years ago
|
return (
|
||
|
<Popover
|
||
4 years ago
|
title={t('whatsThis')}
|
||
5 years ago
|
onClose={setConnectedStatusPopoverHasBeenShown}
|
||
|
className="home__connected-status-popover"
|
||
|
showArrow
|
||
|
CustomBackground={({ onClose }) => {
|
||
|
return (
|
||
|
<div
|
||
|
className="home__connected-status-popover-bg-container"
|
||
|
onClick={onClose}
|
||
|
>
|
||
|
<div className="home__connected-status-popover-bg" />
|
||
|
</div>
|
||
4 years ago
|
);
|
||
5 years ago
|
}}
|
||
4 years ago
|
footer={
|
||
5 years ago
|
<>
|
||
4 years ago
|
<a href={LEARN_MORE_URL} target="_blank" rel="noopener noreferrer">
|
||
|
{t('learnMore')}
|
||
5 years ago
|
</a>
|
||
|
<Button
|
||
|
type="primary"
|
||
|
onClick={setConnectedStatusPopoverHasBeenShown}
|
||
|
>
|
||
4 years ago
|
{t('dismiss')}
|
||
5 years ago
|
</Button>
|
||
|
</>
|
||
4 years ago
|
}
|
||
5 years ago
|
>
|
||
|
<main className="home__connect-status-text">
|
||
4 years ago
|
<div>{t('metaMaskConnectStatusParagraphOne')}</div>
|
||
|
<div>{t('metaMaskConnectStatusParagraphTwo')}</div>
|
||
|
<div>{t('metaMaskConnectStatusParagraphThree')}</div>
|
||
5 years ago
|
</main>
|
||
|
</Popover>
|
||
4 years ago
|
);
|
||
|
};
|
||
5 years ago
|
|
||
4 years ago
|
render() {
|
||
4 years ago
|
const { t } = this.context;
|
||
5 years ago
|
const {
|
||
5 years ago
|
defaultHomeActiveTabName,
|
||
|
onTabClick,
|
||
5 years ago
|
forgottenPassword,
|
||
|
history,
|
||
5 years ago
|
connectedStatusPopoverHasBeenShown,
|
||
|
isPopup,
|
||
4 years ago
|
notificationsToShow,
|
||
|
showWhatsNewPopup,
|
||
|
hideWhatsNewPopup,
|
||
4 years ago
|
} = this.props;
|
||
5 years ago
|
|
||
6 years ago
|
if (forgottenPassword) {
|
||
4 years ago
|
return <Redirect to={{ pathname: RESTORE_VAULT_ROUTE }} />;
|
||
4 years ago
|
} else if (this.state.closing || this.state.redirecting) {
|
||
4 years ago
|
return null;
|
||
6 years ago
|
}
|
||
|
|
||
|
return (
|
||
|
<div className="main-container">
|
||
5 years ago
|
<Route path={CONNECTED_ROUTE} component={ConnectedSites} exact />
|
||
4 years ago
|
<Route
|
||
|
path={CONNECTED_ACCOUNTS_ROUTE}
|
||
|
component={ConnectedAccounts}
|
||
|
exact
|
||
|
/>
|
||
5 years ago
|
<div className="home__container">
|
||
4 years ago
|
{notificationsToShow && showWhatsNewPopup ? (
|
||
|
<WhatsNewPopup onClose={hideWhatsNewPopup} />
|
||
4 years ago
|
) : null}
|
||
4 years ago
|
{isPopup && !connectedStatusPopoverHasBeenShown
|
||
|
? this.renderPopover()
|
||
|
: null}
|
||
5 years ago
|
<div className="home__main-view">
|
||
|
<MenuBar />
|
||
|
<div className="home__balance-wrapper">
|
||
5 years ago
|
<EthOverview />
|
||
5 years ago
|
</div>
|
||
4 years ago
|
<Tabs
|
||
|
defaultActiveTabName={defaultHomeActiveTabName}
|
||
|
onTabClick={onTabClick}
|
||
|
tabsClassName="home__tabs"
|
||
|
>
|
||
5 years ago
|
<Tab
|
||
|
activeClassName="home__tab--active"
|
||
|
className="home__tab"
|
||
|
data-testid="home__asset-tab"
|
||
5 years ago
|
name={t('assets')}
|
||
5 years ago
|
>
|
||
5 years ago
|
<AssetList
|
||
4 years ago
|
onClickAsset={(asset) =>
|
||
|
history.push(`${ASSET_ROUTE}/${asset}`)
|
||
|
}
|
||
5 years ago
|
/>
|
||
5 years ago
|
</Tab>
|
||
|
<Tab
|
||
|
activeClassName="home__tab--active"
|
||
|
className="home__tab"
|
||
5 years ago
|
data-testid="home__activity-tab"
|
||
|
name={t('activity')}
|
||
5 years ago
|
>
|
||
5 years ago
|
<TransactionList />
|
||
5 years ago
|
</Tab>
|
||
|
</Tabs>
|
||
4 years ago
|
<div className="home__support">
|
||
|
{t('needHelp', [
|
||
|
<a
|
||
|
href="https://support.metamask.io"
|
||
|
target="_blank"
|
||
|
rel="noopener noreferrer"
|
||
|
key="need-help-link"
|
||
|
>
|
||
|
{t('needHelpLinkText')}
|
||
|
</a>,
|
||
|
])}
|
||
|
</div>
|
||
5 years ago
|
</div>
|
||
4 years ago
|
|
||
4 years ago
|
{this.renderNotifications()}
|
||
6 years ago
|
</div>
|
||
|
</div>
|
||
4 years ago
|
);
|
||
6 years ago
|
}
|
||
|
}
|