2021-02-04 19:15:23 +01:00
|
|
|
import classnames from 'classnames';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { matchPath, Route, Switch } from 'react-router-dom';
|
|
|
|
import IdleTimer from 'react-idle-timer';
|
|
|
|
|
|
|
|
import FirstTimeFlow from '../first-time-flow';
|
|
|
|
import SendTransactionScreen from '../send';
|
|
|
|
import Swaps from '../swaps';
|
|
|
|
import ConfirmTransaction from '../confirm-transaction';
|
|
|
|
import Home from '../home';
|
|
|
|
import Settings from '../settings';
|
|
|
|
import Authenticated from '../../helpers/higher-order-components/authenticated';
|
|
|
|
import Initialized from '../../helpers/higher-order-components/initialized';
|
|
|
|
import Lock from '../lock';
|
|
|
|
import PermissionsConnect from '../permissions-connect';
|
|
|
|
import RestoreVaultPage from '../keychains/restore-vault';
|
|
|
|
import RevealSeedConfirmation from '../keychains/reveal-seed';
|
|
|
|
import MobileSyncPage from '../mobile-sync';
|
2021-09-10 22:21:04 +02:00
|
|
|
import ImportTokenPage from '../import-token';
|
2021-11-15 18:28:35 +01:00
|
|
|
import AddCollectiblePage from '../add-collectible';
|
2021-09-10 22:21:04 +02:00
|
|
|
import ConfirmImportTokenPage from '../confirm-import-token';
|
2021-02-04 19:15:23 +01:00
|
|
|
import ConfirmAddSuggestedTokenPage from '../confirm-add-suggested-token';
|
|
|
|
import CreateAccountPage from '../create-account';
|
|
|
|
import Loading from '../../components/ui/loading-screen';
|
|
|
|
import LoadingNetwork from '../../components/app/loading-network-screen';
|
|
|
|
import NetworkDropdown from '../../components/app/dropdowns/network-dropdown';
|
|
|
|
import AccountMenu from '../../components/app/account-menu';
|
|
|
|
import { Modal } from '../../components/app/modals';
|
|
|
|
import Alert from '../../components/ui/alert';
|
|
|
|
import AppHeader from '../../components/app/app-header';
|
|
|
|
import UnlockPage from '../unlock-page';
|
|
|
|
import Alerts from '../../components/app/alerts';
|
|
|
|
import Asset from '../asset';
|
2021-10-05 22:38:16 +02:00
|
|
|
import OnboardingAppHeader from '../onboarding-flow/onboarding-app-header/onboarding-app-header';
|
2022-02-16 17:59:39 +01:00
|
|
|
import TokenDetailsPage from '../token-details';
|
2022-06-01 19:09:13 +02:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(flask)
|
|
|
|
import Notifications from '../notifications';
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
2020-03-26 17:18:50 +01:00
|
|
|
|
|
|
|
import {
|
2021-09-10 22:21:04 +02:00
|
|
|
IMPORT_TOKEN_ROUTE,
|
2020-06-01 19:54:32 +02:00
|
|
|
ASSET_ROUTE,
|
2020-03-26 17:18:50 +01:00
|
|
|
CONFIRM_ADD_SUGGESTED_TOKEN_ROUTE,
|
|
|
|
CONFIRM_TRANSACTION_ROUTE,
|
|
|
|
CONNECT_ROUTE,
|
|
|
|
DEFAULT_ROUTE,
|
|
|
|
INITIALIZE_UNLOCK_ROUTE,
|
2020-11-09 14:50:24 +01:00
|
|
|
LOCK_ROUTE,
|
2020-03-26 17:18:50 +01:00
|
|
|
MOBILE_SYNC_ROUTE,
|
|
|
|
NEW_ACCOUNT_ROUTE,
|
|
|
|
RESTORE_VAULT_ROUTE,
|
|
|
|
REVEAL_SEED_ROUTE,
|
|
|
|
SEND_ROUTE,
|
2020-10-06 20:28:38 +02:00
|
|
|
SWAPS_ROUTE,
|
2020-03-26 17:18:50 +01:00
|
|
|
SETTINGS_ROUTE,
|
|
|
|
UNLOCK_ROUTE,
|
2020-10-12 18:51:01 +02:00
|
|
|
BUILD_QUOTE_ROUTE,
|
2021-02-22 17:20:42 +01:00
|
|
|
CONFIRMATION_V_NEXT_ROUTE,
|
2021-09-10 22:21:04 +02:00
|
|
|
CONFIRM_IMPORT_TOKEN_ROUTE,
|
2021-10-06 20:52:25 +02:00
|
|
|
INITIALIZE_ROUTE,
|
2021-09-30 23:34:11 +02:00
|
|
|
ONBOARDING_ROUTE,
|
2021-11-15 18:28:35 +01:00
|
|
|
ADD_COLLECTIBLE_ROUTE,
|
2022-02-16 17:59:39 +01:00
|
|
|
TOKEN_DETAILS,
|
2022-06-01 19:09:13 +02:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(flask)
|
|
|
|
NOTIFICATIONS_ROUTE,
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../helpers/constants/routes';
|
2020-03-26 17:18:50 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
import {
|
|
|
|
ENVIRONMENT_TYPE_NOTIFICATION,
|
|
|
|
ENVIRONMENT_TYPE_POPUP,
|
2021-04-28 21:53:59 +02:00
|
|
|
} from '../../../shared/constants/app';
|
2022-09-21 22:10:34 +02:00
|
|
|
import { NETWORK_TYPES } from '../../../shared/constants/network';
|
2021-04-28 21:53:59 +02:00
|
|
|
import { getEnvironmentType } from '../../../app/scripts/lib/util';
|
2021-02-22 17:20:42 +01:00
|
|
|
import ConfirmationPage from '../confirmation';
|
2021-09-30 23:34:11 +02:00
|
|
|
import OnboardingFlow from '../onboarding-flow/onboarding-flow';
|
2021-11-23 18:28:39 +01:00
|
|
|
import QRHardwarePopover from '../../components/app/qr-hardware-popover';
|
2022-03-24 16:51:22 +01:00
|
|
|
import { SEND_STAGES } from '../../ducks/send';
|
2022-09-23 17:15:02 +02:00
|
|
|
import { THEME_TYPE } from '../settings/settings-tab/settings-tab.constant';
|
2022-09-08 13:30:57 +02:00
|
|
|
import DeprecatedTestNetworks from '../../components/ui/deprecated-test-networks/deprecated-test-networks';
|
2022-08-23 17:04:07 +02:00
|
|
|
import NewNetworkInfo from '../../components/ui/new-network-info/new-network-info';
|
2020-03-26 17:18:50 +01:00
|
|
|
|
|
|
|
export default class Routes extends Component {
|
|
|
|
static propTypes = {
|
|
|
|
currentCurrency: PropTypes.string,
|
|
|
|
setCurrentCurrencyToUSD: PropTypes.func,
|
|
|
|
isLoading: PropTypes.bool,
|
|
|
|
loadingMessage: PropTypes.string,
|
|
|
|
alertMessage: PropTypes.string,
|
|
|
|
textDirection: PropTypes.string,
|
2021-03-12 23:23:26 +01:00
|
|
|
isNetworkLoading: PropTypes.bool,
|
2020-03-26 17:18:50 +01:00
|
|
|
alertOpen: PropTypes.bool,
|
|
|
|
isUnlocked: PropTypes.bool,
|
|
|
|
setLastActiveTime: PropTypes.func,
|
|
|
|
history: PropTypes.object,
|
|
|
|
location: PropTypes.object,
|
|
|
|
lockMetaMask: PropTypes.func,
|
|
|
|
isMouseUser: PropTypes.bool,
|
|
|
|
setMouseUserState: PropTypes.func,
|
|
|
|
providerId: PropTypes.string,
|
2021-12-01 17:25:09 +01:00
|
|
|
providerType: PropTypes.string,
|
2020-03-26 17:18:50 +01:00
|
|
|
autoLockTimeLimit: PropTypes.number,
|
2020-06-01 19:54:32 +02:00
|
|
|
pageChanged: PropTypes.func.isRequired,
|
2020-10-06 20:28:38 +02:00
|
|
|
prepareToLeaveSwaps: PropTypes.func,
|
2021-12-01 17:25:09 +01:00
|
|
|
browserEnvironmentOs: PropTypes.string,
|
|
|
|
browserEnvironmentBrowser: PropTypes.string,
|
2022-03-07 19:53:19 +01:00
|
|
|
theme: PropTypes.string,
|
2022-03-24 16:51:22 +01:00
|
|
|
sendStage: PropTypes.string,
|
2022-08-23 17:04:07 +02:00
|
|
|
isNetworkUsed: PropTypes.bool,
|
2022-09-14 17:35:59 +02:00
|
|
|
allAccountsOnNetworkAreEmpty: PropTypes.bool,
|
|
|
|
isTestNet: PropTypes.bool,
|
2022-09-19 17:39:28 +02:00
|
|
|
currentChainId: PropTypes.string,
|
2022-09-19 19:40:30 +02:00
|
|
|
shouldShowSeedPhraseReminder: PropTypes.bool,
|
|
|
|
portfolioTooltipIsBeingShown: PropTypes.bool,
|
2022-10-11 17:05:03 +02:00
|
|
|
forgottenPassword: PropTypes.bool,
|
2022-10-27 12:25:30 +02:00
|
|
|
isCurrentProviderCustom: PropTypes.bool,
|
2022-12-08 17:42:23 +01:00
|
|
|
completedOnboarding: PropTypes.bool,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-03-26 17:18:50 +01:00
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
|
|
|
metricsEvent: PropTypes.func,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-03-26 17:18:50 +01:00
|
|
|
|
2022-04-28 14:36:28 +02:00
|
|
|
handleOsTheme() {
|
|
|
|
const osTheme = window?.matchMedia('(prefers-color-scheme: dark)')?.matches
|
|
|
|
? THEME_TYPE.DARK
|
|
|
|
: THEME_TYPE.LIGHT;
|
|
|
|
|
|
|
|
document.documentElement.setAttribute('data-theme', osTheme);
|
|
|
|
}
|
|
|
|
|
2022-03-07 19:53:19 +01:00
|
|
|
componentDidUpdate(prevProps) {
|
2022-03-26 02:42:52 +01:00
|
|
|
const { theme } = this.props;
|
2022-04-28 14:36:28 +02:00
|
|
|
|
2022-03-26 02:42:52 +01:00
|
|
|
if (theme !== prevProps.theme) {
|
2022-04-28 14:36:28 +02:00
|
|
|
if (theme === THEME_TYPE.OS) {
|
|
|
|
this.handleOsTheme();
|
|
|
|
} else {
|
|
|
|
document.documentElement.setAttribute('data-theme', theme);
|
|
|
|
}
|
2022-03-07 19:53:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
UNSAFE_componentWillMount() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const {
|
|
|
|
currentCurrency,
|
|
|
|
pageChanged,
|
|
|
|
setCurrentCurrencyToUSD,
|
2021-04-28 18:51:41 +02:00
|
|
|
history,
|
2022-03-07 19:53:19 +01:00
|
|
|
theme,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2020-03-26 17:18:50 +01:00
|
|
|
if (!currentCurrency) {
|
2021-02-04 19:15:23 +01:00
|
|
|
setCurrentCurrencyToUSD();
|
2020-03-26 17:18:50 +01:00
|
|
|
}
|
|
|
|
|
2021-04-28 18:51:41 +02:00
|
|
|
history.listen((locationObj, action) => {
|
2020-03-26 17:18:50 +01:00
|
|
|
if (action === 'PUSH') {
|
2021-02-04 19:15:23 +01:00
|
|
|
pageChanged(locationObj.pathname);
|
2020-03-26 17:18:50 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2022-04-28 14:36:28 +02:00
|
|
|
if (theme === THEME_TYPE.OS) {
|
|
|
|
this.handleOsTheme();
|
|
|
|
} else {
|
|
|
|
document.documentElement.setAttribute('data-theme', theme);
|
|
|
|
}
|
2020-03-26 17:18:50 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderRoutes() {
|
2022-10-11 17:05:03 +02:00
|
|
|
const { autoLockTimeLimit, setLastActiveTime, forgottenPassword } =
|
|
|
|
this.props;
|
|
|
|
const RestoreVaultComponent = forgottenPassword ? Route : Initialized;
|
|
|
|
|
2020-03-26 17:18:50 +01:00
|
|
|
const routes = (
|
|
|
|
<Switch>
|
2023-01-13 17:25:01 +01:00
|
|
|
<Route path={ONBOARDING_ROUTE} component={OnboardingFlow} />
|
2020-11-09 14:50:24 +01:00
|
|
|
<Route path={LOCK_ROUTE} component={Lock} exact />
|
2020-03-26 17:18:50 +01:00
|
|
|
<Route path={INITIALIZE_ROUTE} component={FirstTimeFlow} />
|
|
|
|
<Initialized path={UNLOCK_ROUTE} component={UnlockPage} exact />
|
2022-10-11 17:05:03 +02:00
|
|
|
<RestoreVaultComponent
|
2020-11-03 00:41:28 +01:00
|
|
|
path={RESTORE_VAULT_ROUTE}
|
|
|
|
component={RestoreVaultPage}
|
|
|
|
exact
|
|
|
|
/>
|
|
|
|
<Authenticated
|
|
|
|
path={REVEAL_SEED_ROUTE}
|
|
|
|
component={RevealSeedConfirmation}
|
|
|
|
exact
|
|
|
|
/>
|
|
|
|
<Authenticated
|
|
|
|
path={MOBILE_SYNC_ROUTE}
|
|
|
|
component={MobileSyncPage}
|
|
|
|
exact
|
|
|
|
/>
|
2020-03-26 17:18:50 +01:00
|
|
|
<Authenticated path={SETTINGS_ROUTE} component={Settings} />
|
2022-06-01 19:09:13 +02:00
|
|
|
{
|
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(flask)
|
|
|
|
<Authenticated path={NOTIFICATIONS_ROUTE} component={Notifications} />
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
|
|
|
}
|
2020-11-03 00:41:28 +01:00
|
|
|
<Authenticated
|
|
|
|
path={`${CONFIRM_TRANSACTION_ROUTE}/:id?`}
|
|
|
|
component={ConfirmTransaction}
|
|
|
|
/>
|
|
|
|
<Authenticated
|
|
|
|
path={SEND_ROUTE}
|
|
|
|
component={SendTransactionScreen}
|
|
|
|
exact
|
|
|
|
/>
|
2022-02-16 17:59:39 +01:00
|
|
|
<Authenticated
|
2022-03-02 17:01:53 +01:00
|
|
|
path={`${TOKEN_DETAILS}/:address/`}
|
2022-02-16 17:59:39 +01:00
|
|
|
component={TokenDetailsPage}
|
|
|
|
exact
|
|
|
|
/>
|
2020-10-06 20:28:38 +02:00
|
|
|
<Authenticated path={SWAPS_ROUTE} component={Swaps} />
|
2020-11-03 00:41:28 +01:00
|
|
|
<Authenticated
|
2021-09-10 22:21:04 +02:00
|
|
|
path={IMPORT_TOKEN_ROUTE}
|
|
|
|
component={ImportTokenPage}
|
|
|
|
exact
|
|
|
|
/>
|
2022-12-08 18:37:47 +01:00
|
|
|
{process.env.NFTS_V1 ? (
|
2021-11-15 18:28:35 +01:00
|
|
|
<Authenticated
|
|
|
|
path={ADD_COLLECTIBLE_ROUTE}
|
|
|
|
component={AddCollectiblePage}
|
|
|
|
exact
|
|
|
|
/>
|
|
|
|
) : null}
|
2021-09-10 22:21:04 +02:00
|
|
|
<Authenticated
|
|
|
|
path={CONFIRM_IMPORT_TOKEN_ROUTE}
|
|
|
|
component={ConfirmImportTokenPage}
|
2020-11-03 00:41:28 +01:00
|
|
|
exact
|
|
|
|
/>
|
|
|
|
<Authenticated
|
|
|
|
path={CONFIRM_ADD_SUGGESTED_TOKEN_ROUTE}
|
|
|
|
component={ConfirmAddSuggestedTokenPage}
|
|
|
|
exact
|
|
|
|
/>
|
2021-02-22 17:20:42 +01:00
|
|
|
<Authenticated
|
|
|
|
path={CONFIRMATION_V_NEXT_ROUTE}
|
|
|
|
component={ConfirmationPage}
|
|
|
|
/>
|
2020-03-26 17:18:50 +01:00
|
|
|
<Authenticated path={NEW_ACCOUNT_ROUTE} component={CreateAccountPage} />
|
2020-11-03 00:41:28 +01:00
|
|
|
<Authenticated
|
|
|
|
path={`${CONNECT_ROUTE}/:id`}
|
|
|
|
component={PermissionsConnect}
|
|
|
|
/>
|
2021-12-14 00:41:10 +01:00
|
|
|
<Authenticated path={`${ASSET_ROUTE}/:asset/:id`} component={Asset} />
|
|
|
|
<Authenticated path={`${ASSET_ROUTE}/:asset/`} component={Asset} />
|
2020-03-31 01:38:02 +02:00
|
|
|
<Authenticated path={DEFAULT_ROUTE} component={Home} />
|
2020-03-26 17:18:50 +01:00
|
|
|
</Switch>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-03-26 17:18:50 +01:00
|
|
|
|
|
|
|
if (autoLockTimeLimit > 0) {
|
|
|
|
return (
|
|
|
|
<IdleTimer onAction={setLastActiveTime} throttle={1000}>
|
|
|
|
{routes}
|
|
|
|
</IdleTimer>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-03-26 17:18:50 +01:00
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
return routes;
|
2020-03-26 17:18:50 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
onInitializationUnlockPage() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { location } = this.props;
|
2020-11-03 00:41:28 +01:00
|
|
|
return Boolean(
|
|
|
|
matchPath(location.pathname, {
|
|
|
|
path: INITIALIZE_UNLOCK_ROUTE,
|
|
|
|
exact: true,
|
|
|
|
}),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-03-26 17:18:50 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
onConfirmPage() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { location } = this.props;
|
2020-11-03 00:41:28 +01:00
|
|
|
return Boolean(
|
|
|
|
matchPath(location.pathname, {
|
|
|
|
path: CONFIRM_TRANSACTION_ROUTE,
|
|
|
|
exact: false,
|
|
|
|
}),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-03-26 17:18:50 +01:00
|
|
|
}
|
|
|
|
|
2022-03-24 16:51:22 +01:00
|
|
|
onEditTransactionPage() {
|
|
|
|
return this.props.sendStage === SEND_STAGES.EDIT;
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
onSwapsPage() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { location } = this.props;
|
2020-11-03 00:41:28 +01:00
|
|
|
return Boolean(
|
|
|
|
matchPath(location.pathname, { path: SWAPS_ROUTE, exact: false }),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-10-06 20:28:38 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
onSwapsBuildQuotePage() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { location } = this.props;
|
2020-11-03 00:41:28 +01:00
|
|
|
return Boolean(
|
|
|
|
matchPath(location.pathname, { path: BUILD_QUOTE_ROUTE, exact: false }),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-10-12 18:51:01 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
hideAppHeader() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { location } = this.props;
|
2020-03-26 17:18:50 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const isInitializing = Boolean(
|
|
|
|
matchPath(location.pathname, {
|
2023-01-13 17:25:01 +01:00
|
|
|
path: ONBOARDING_ROUTE,
|
2020-11-03 00:41:28 +01:00
|
|
|
exact: false,
|
|
|
|
}),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-03-26 17:18:50 +01:00
|
|
|
|
|
|
|
if (isInitializing && !this.onInitializationUnlockPage()) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return true;
|
2020-03-26 17:18:50 +01:00
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const windowType = getEnvironmentType();
|
2020-04-02 00:28:10 +02:00
|
|
|
|
|
|
|
if (windowType === ENVIRONMENT_TYPE_NOTIFICATION) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return true;
|
2020-03-26 17:18:50 +01:00
|
|
|
}
|
|
|
|
|
2020-06-11 02:27:47 +02:00
|
|
|
if (windowType === ENVIRONMENT_TYPE_POPUP && this.onConfirmPage()) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return true;
|
2020-03-26 17:18:50 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const isHandlingPermissionsRequest = Boolean(
|
|
|
|
matchPath(location.pathname, {
|
|
|
|
path: CONNECT_ROUTE,
|
|
|
|
exact: false,
|
|
|
|
}),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-03-26 17:18:50 +01:00
|
|
|
|
2021-02-22 17:20:42 +01:00
|
|
|
const isHandlingAddEthereumChainRequest = Boolean(
|
|
|
|
matchPath(location.pathname, {
|
|
|
|
path: CONFIRMATION_V_NEXT_ROUTE,
|
|
|
|
exact: false,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
|
|
|
return isHandlingPermissionsRequest || isHandlingAddEthereumChainRequest;
|
2020-03-26 17:18:50 +01:00
|
|
|
}
|
|
|
|
|
2021-10-05 22:38:16 +02:00
|
|
|
showOnboardingHeader() {
|
|
|
|
const { location } = this.props;
|
|
|
|
|
|
|
|
return Boolean(
|
|
|
|
matchPath(location.pathname, {
|
|
|
|
path: ONBOARDING_ROUTE,
|
|
|
|
exact: false,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-12-01 17:25:09 +01:00
|
|
|
onAppHeaderClick = async () => {
|
|
|
|
const { prepareToLeaveSwaps } = this.props;
|
|
|
|
if (this.onSwapsPage()) {
|
|
|
|
await prepareToLeaveSwaps();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
2020-03-26 17:18:50 +01:00
|
|
|
const {
|
|
|
|
isLoading,
|
2020-05-12 15:01:52 +02:00
|
|
|
isUnlocked,
|
2020-03-26 17:18:50 +01:00
|
|
|
alertMessage,
|
|
|
|
textDirection,
|
|
|
|
loadingMessage,
|
2021-03-12 23:23:26 +01:00
|
|
|
isNetworkLoading,
|
2020-03-26 17:18:50 +01:00
|
|
|
setMouseUserState,
|
|
|
|
isMouseUser,
|
2021-12-01 17:25:09 +01:00
|
|
|
browserEnvironmentOs: os,
|
|
|
|
browserEnvironmentBrowser: browser,
|
2022-08-23 17:04:07 +02:00
|
|
|
isNetworkUsed,
|
2022-09-14 17:35:59 +02:00
|
|
|
allAccountsOnNetworkAreEmpty,
|
|
|
|
isTestNet,
|
2022-09-19 17:39:28 +02:00
|
|
|
currentChainId,
|
2022-09-19 19:40:30 +02:00
|
|
|
shouldShowSeedPhraseReminder,
|
|
|
|
portfolioTooltipIsBeingShown,
|
2022-10-27 12:25:30 +02:00
|
|
|
isCurrentProviderCustom,
|
2022-12-08 17:42:23 +01:00
|
|
|
completedOnboarding,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2020-11-03 00:41:28 +01:00
|
|
|
const loadMessage =
|
2021-03-12 23:23:26 +01:00
|
|
|
loadingMessage || isNetworkLoading
|
2020-11-03 00:41:28 +01:00
|
|
|
? this.getConnectingLabel(loadingMessage)
|
2021-02-04 19:15:23 +01:00
|
|
|
: null;
|
2022-08-23 17:04:07 +02:00
|
|
|
|
|
|
|
const shouldShowNetworkInfo =
|
2022-09-14 17:35:59 +02:00
|
|
|
isUnlocked &&
|
2022-09-19 17:39:28 +02:00
|
|
|
currentChainId &&
|
2022-09-14 17:35:59 +02:00
|
|
|
!isTestNet &&
|
|
|
|
!isNetworkUsed &&
|
2022-10-27 12:25:30 +02:00
|
|
|
!isCurrentProviderCustom &&
|
2022-12-08 17:42:23 +01:00
|
|
|
completedOnboarding &&
|
2022-09-14 17:35:59 +02:00
|
|
|
allAccountsOnNetworkAreEmpty;
|
2022-08-23 17:04:07 +02:00
|
|
|
|
2022-09-08 13:30:57 +02:00
|
|
|
const windowType = getEnvironmentType();
|
|
|
|
|
2022-09-19 19:40:30 +02:00
|
|
|
const shouldShowNetworkDeprecationWarning =
|
|
|
|
windowType !== ENVIRONMENT_TYPE_NOTIFICATION &&
|
|
|
|
isUnlocked &&
|
|
|
|
!shouldShowSeedPhraseReminder &&
|
|
|
|
!portfolioTooltipIsBeingShown;
|
|
|
|
|
2020-03-26 17:18:50 +01:00
|
|
|
return (
|
|
|
|
<div
|
2021-04-30 17:28:07 +02:00
|
|
|
className={classnames('app', {
|
|
|
|
[`os-${os}`]: os,
|
|
|
|
[`browser-${browser}`]: browser,
|
|
|
|
'mouse-user-styles': isMouseUser,
|
|
|
|
})}
|
2020-03-26 17:18:50 +01:00
|
|
|
dir={textDirection}
|
|
|
|
onClick={() => setMouseUserState(true)}
|
|
|
|
onKeyDown={(e) => {
|
|
|
|
if (e.keyCode === 9) {
|
2021-02-04 19:15:23 +01:00
|
|
|
setMouseUserState(false);
|
2020-03-26 17:18:50 +01:00
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
2022-09-19 19:40:30 +02:00
|
|
|
{shouldShowNetworkDeprecationWarning && <DeprecatedTestNetworks />}
|
2022-08-23 17:04:07 +02:00
|
|
|
{shouldShowNetworkInfo && <NewNetworkInfo />}
|
2021-11-23 18:28:39 +01:00
|
|
|
<QRHardwarePopover />
|
2020-03-26 17:18:50 +01:00
|
|
|
<Modal />
|
2020-11-03 00:41:28 +01:00
|
|
|
<Alert visible={this.props.alertOpen} msg={alertMessage} />
|
|
|
|
{!this.hideAppHeader() && (
|
2020-03-26 17:18:50 +01:00
|
|
|
<AppHeader
|
|
|
|
hideNetworkIndicator={this.onInitializationUnlockPage()}
|
2020-10-06 20:28:38 +02:00
|
|
|
disableNetworkIndicator={this.onSwapsPage()}
|
2021-12-01 17:25:09 +01:00
|
|
|
onClick={this.onAppHeaderClick}
|
2020-11-03 00:41:28 +01:00
|
|
|
disabled={
|
|
|
|
this.onConfirmPage() ||
|
2022-03-24 16:51:22 +01:00
|
|
|
this.onEditTransactionPage() ||
|
2020-11-03 00:41:28 +01:00
|
|
|
(this.onSwapsPage() && !this.onSwapsBuildQuotePage())
|
|
|
|
}
|
2020-03-26 17:18:50 +01:00
|
|
|
/>
|
2020-11-03 00:41:28 +01:00
|
|
|
)}
|
2023-01-13 17:25:01 +01:00
|
|
|
{this.showOnboardingHeader() && <OnboardingAppHeader />}
|
2022-12-08 17:42:23 +01:00
|
|
|
{completedOnboarding ? <NetworkDropdown /> : null}
|
2020-03-26 17:18:50 +01:00
|
|
|
<AccountMenu />
|
|
|
|
<div className="main-container-wrapper">
|
2021-10-21 18:11:31 +02:00
|
|
|
{isLoading ? <Loading loadingMessage={loadMessage} /> : null}
|
|
|
|
{!isLoading && isNetworkLoading ? <LoadingNetwork /> : null}
|
2020-11-03 00:41:28 +01:00
|
|
|
{this.renderRoutes()}
|
2020-03-26 17:18:50 +01:00
|
|
|
</div>
|
2020-11-03 00:41:28 +01:00
|
|
|
{isUnlocked ? <Alerts history={this.props.history} /> : null}
|
2020-03-26 17:18:50 +01:00
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-03-26 17:18:50 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
toggleMetamaskActive() {
|
2020-08-14 13:47:43 +02:00
|
|
|
if (this.props.isUnlocked) {
|
|
|
|
// currently active: deactivate
|
2021-02-04 19:15:23 +01:00
|
|
|
this.props.lockMetaMask();
|
2020-08-14 13:47:43 +02:00
|
|
|
} else {
|
2020-03-26 17:18:50 +01:00
|
|
|
// currently inactive: redirect to password box
|
2021-02-04 19:15:23 +01:00
|
|
|
const passwordBox = document.querySelector('input[type=password]');
|
2020-03-26 17:18:50 +01:00
|
|
|
if (!passwordBox) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return;
|
2020-03-26 17:18:50 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
passwordBox.focus();
|
2020-03-26 17:18:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
getConnectingLabel(loadingMessage) {
|
2020-03-26 17:18:50 +01:00
|
|
|
if (loadingMessage) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return loadingMessage;
|
2020-03-26 17:18:50 +01:00
|
|
|
}
|
2021-12-01 17:25:09 +01:00
|
|
|
const { providerType, providerId } = this.props;
|
2022-09-21 22:10:34 +02:00
|
|
|
const { t } = this.context;
|
2020-03-26 17:18:50 +01:00
|
|
|
|
2021-12-01 17:25:09 +01:00
|
|
|
switch (providerType) {
|
2022-09-21 22:10:34 +02:00
|
|
|
case NETWORK_TYPES.MAINNET:
|
|
|
|
return t('connectingToMainnet');
|
|
|
|
case NETWORK_TYPES.GOERLI:
|
|
|
|
return t('connectingToGoerli');
|
|
|
|
case NETWORK_TYPES.SEPOLIA:
|
|
|
|
return t('connectingToSepolia');
|
2020-03-26 17:18:50 +01:00
|
|
|
default:
|
2022-09-21 22:10:34 +02:00
|
|
|
return t('connectingTo', [providerId]);
|
2020-03-26 17:18:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|