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.
442 lines
14 KiB
442 lines
14 KiB
6 years ago
|
import React, { Component } from 'react'
|
||
|
import PropTypes from 'prop-types'
|
||
|
import { connect } from 'react-redux'
|
||
|
import { Route, Switch, withRouter, matchPath } from 'react-router-dom'
|
||
|
import { compose } from 'recompose'
|
||
6 years ago
|
import actions from '../../store/actions'
|
||
6 years ago
|
import log from 'loglevel'
|
||
6 years ago
|
import { getMetaMaskAccounts, getNetworkIdentifier } from '../../selectors/selectors'
|
||
7 years ago
|
|
||
7 years ago
|
// init
|
||
6 years ago
|
import FirstTimeFlow from '../first-time-flow'
|
||
9 years ago
|
// accounts
|
||
6 years ago
|
const SendTransactionScreen = require('../../components/app/send/send.container')
|
||
|
const ConfirmTransaction = require('../confirm-transaction')
|
||
7 years ago
|
|
||
|
// slideout menu
|
||
6 years ago
|
const Sidebar = require('../../components/app/sidebars').default
|
||
|
const { WALLET_VIEW_SIDEBAR } = require('../../components/app/sidebars/sidebar.constants')
|
||
7 years ago
|
|
||
9 years ago
|
// other views
|
||
6 years ago
|
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 UiMigrationAnnouncement from '../../components/app/ui-migration-annoucement'
|
||
|
const RestoreVaultPage = require('../keychains/restore-vault').default
|
||
|
const RevealSeedConfirmation = require('../keychains/reveal-seed')
|
||
|
const MobileSyncPage = require('../mobile-sync')
|
||
|
const AddTokenPage = require('../add-token')
|
||
|
const ConfirmAddTokenPage = require('../confirm-add-token')
|
||
|
const ConfirmAddSuggestedTokenPage = require('../confirm-add-suggested-token')
|
||
|
const CreateAccountPage = require('../create-account')
|
||
|
const NoticeScreen = require('../notice/notice')
|
||
|
|
||
|
const Loading = require('../../components/ui/loading-screen')
|
||
|
const LoadingNetwork = require('../../components/app/loading-network-screen').default
|
||
|
const NetworkDropdown = require('../../components/app/dropdowns/network-dropdown')
|
||
|
import AccountMenu from '../../components/app/account-menu'
|
||
7 years ago
|
|
||
|
// Global Modals
|
||
6 years ago
|
const Modal = require('../../components/app/modals').Modal
|
||
6 years ago
|
// Global Alert
|
||
6 years ago
|
const Alert = require('../../components/ui/alert')
|
||
8 years ago
|
|
||
6 years ago
|
import AppHeader from '../../components/app/app-header'
|
||
|
import UnlockPage from '../unlock-page'
|
||
6 years ago
|
|
||
6 years ago
|
import {
|
||
|
submittedPendingTransactionsSelector,
|
||
6 years ago
|
} from '../../selectors/transactions'
|
||
6 years ago
|
|
||
7 years ago
|
// Routes
|
||
6 years ago
|
import {
|
||
7 years ago
|
DEFAULT_ROUTE,
|
||
6 years ago
|
LOCK_ROUTE,
|
||
7 years ago
|
UNLOCK_ROUTE,
|
||
|
SETTINGS_ROUTE,
|
||
|
REVEAL_SEED_ROUTE,
|
||
6 years ago
|
MOBILE_SYNC_ROUTE,
|
||
7 years ago
|
RESTORE_VAULT_ROUTE,
|
||
|
ADD_TOKEN_ROUTE,
|
||
7 years ago
|
CONFIRM_ADD_TOKEN_ROUTE,
|
||
6 years ago
|
CONFIRM_ADD_SUGGESTED_TOKEN_ROUTE,
|
||
7 years ago
|
NEW_ACCOUNT_ROUTE,
|
||
7 years ago
|
SEND_ROUTE,
|
||
|
CONFIRM_TRANSACTION_ROUTE,
|
||
7 years ago
|
INITIALIZE_ROUTE,
|
||
6 years ago
|
INITIALIZE_UNLOCK_ROUTE,
|
||
7 years ago
|
NOTICE_ROUTE,
|
||
6 years ago
|
} from '../../helpers/constants/routes'
|
||
6 years ago
|
|
||
|
// enums
|
||
|
import {
|
||
|
ENVIRONMENT_TYPE_NOTIFICATION,
|
||
|
ENVIRONMENT_TYPE_POPUP,
|
||
6 years ago
|
} from '../../../../app/scripts/lib/enums'
|
||
7 years ago
|
|
||
6 years ago
|
class Routes extends Component {
|
||
7 years ago
|
componentWillMount () {
|
||
7 years ago
|
const { currentCurrency, setCurrentCurrencyToUSD } = this.props
|
||
7 years ago
|
|
||
|
if (!currentCurrency) {
|
||
|
setCurrentCurrencyToUSD()
|
||
|
}
|
||
6 years ago
|
|
||
|
this.props.history.listen((locationObj, action) => {
|
||
|
if (action === 'PUSH') {
|
||
|
const url = `&url=${encodeURIComponent('http://www.metamask.io/metametrics' + locationObj.pathname)}`
|
||
|
this.context.metricsEvent({}, {
|
||
|
currentPath: '',
|
||
|
pathname: locationObj.pathname,
|
||
|
url,
|
||
|
pageOpts: {
|
||
|
hideDimensions: true,
|
||
|
},
|
||
|
})
|
||
|
}
|
||
|
})
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
renderRoutes () {
|
||
|
return (
|
||
6 years ago
|
<Switch>
|
||
|
<Route path={LOCK_ROUTE} component={Lock} exact />
|
||
|
<Route path={INITIALIZE_ROUTE} component={FirstTimeFlow} />
|
||
|
<Initialized path={UNLOCK_ROUTE} component={UnlockPage} exact />
|
||
|
<Initialized path={RESTORE_VAULT_ROUTE} component={RestoreVaultPage} exact />
|
||
|
<Authenticated path={REVEAL_SEED_ROUTE} component={RevealSeedConfirmation} exact />
|
||
6 years ago
|
<Authenticated path={MOBILE_SYNC_ROUTE} component={MobileSyncPage} exact />
|
||
6 years ago
|
<Authenticated path={SETTINGS_ROUTE} component={Settings} />
|
||
|
<Authenticated path={NOTICE_ROUTE} component={NoticeScreen} exact />
|
||
|
<Authenticated path={`${CONFIRM_TRANSACTION_ROUTE}/:id?`} component={ConfirmTransaction} />
|
||
|
<Authenticated path={SEND_ROUTE} component={SendTransactionScreen} exact />
|
||
|
<Authenticated path={ADD_TOKEN_ROUTE} component={AddTokenPage} exact />
|
||
|
<Authenticated path={CONFIRM_ADD_TOKEN_ROUTE} component={ConfirmAddTokenPage} exact />
|
||
|
<Authenticated path={CONFIRM_ADD_SUGGESTED_TOKEN_ROUTE} component={ConfirmAddSuggestedTokenPage} exact />
|
||
|
<Authenticated path={NEW_ACCOUNT_ROUTE} component={CreateAccountPage} />
|
||
|
<Authenticated path={DEFAULT_ROUTE} component={Home} exact />
|
||
|
</Switch>
|
||
7 years ago
|
)
|
||
7 years ago
|
}
|
||
7 years ago
|
|
||
6 years ago
|
onInitializationUnlockPage () {
|
||
|
const { location } = this.props
|
||
|
return Boolean(matchPath(location.pathname, { path: INITIALIZE_UNLOCK_ROUTE, exact: true }))
|
||
|
}
|
||
|
|
||
|
onConfirmPage () {
|
||
|
const { location } = this.props
|
||
|
return Boolean(matchPath(location.pathname, { path: CONFIRM_TRANSACTION_ROUTE, exact: false }))
|
||
|
}
|
||
|
|
||
|
hasProviderRequests () {
|
||
|
const { providerRequests } = this.props
|
||
|
return Array.isArray(providerRequests) && providerRequests.length > 0
|
||
|
}
|
||
|
|
||
|
hideAppHeader () {
|
||
|
const { location } = this.props
|
||
|
|
||
|
const isInitializing = Boolean(matchPath(location.pathname, {
|
||
|
path: INITIALIZE_ROUTE, exact: false,
|
||
|
}))
|
||
|
|
||
|
if (isInitializing && !this.onInitializationUnlockPage()) {
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
if (window.METAMASK_UI_TYPE === ENVIRONMENT_TYPE_NOTIFICATION) {
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
if (window.METAMASK_UI_TYPE === ENVIRONMENT_TYPE_POPUP) {
|
||
|
return this.onConfirmPage() || this.hasProviderRequests()
|
||
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
render () {
|
||
7 years ago
|
const {
|
||
|
isLoading,
|
||
6 years ago
|
alertMessage,
|
||
7 years ago
|
loadingMessage,
|
||
|
network,
|
||
|
provider,
|
||
6 years ago
|
frequentRpcListDetail,
|
||
7 years ago
|
currentView,
|
||
7 years ago
|
setMouseUserState,
|
||
6 years ago
|
sidebar,
|
||
6 years ago
|
submittedPendingTransactions,
|
||
7 years ago
|
} = this.props
|
||
|
const isLoadingNetwork = network === 'loading' && currentView.name !== 'config'
|
||
7 years ago
|
const loadMessage = loadingMessage || isLoadingNetwork ?
|
||
7 years ago
|
this.getConnectingLabel(loadingMessage) : null
|
||
7 years ago
|
log.debug('Main ui render function')
|
||
9 years ago
|
|
||
6 years ago
|
const sidebarOnOverlayClose = sidebarType === WALLET_VIEW_SIDEBAR
|
||
|
? () => {
|
||
|
this.context.metricsEvent({
|
||
|
eventOpts: {
|
||
|
category: 'Navigation',
|
||
|
action: 'Wallet Sidebar',
|
||
|
name: 'Closed Sidebare Via Overlay',
|
||
|
},
|
||
|
})
|
||
|
}
|
||
|
: null
|
||
|
|
||
6 years ago
|
const {
|
||
|
isOpen: sidebarIsOpen,
|
||
|
transitionName: sidebarTransitionName,
|
||
|
type: sidebarType,
|
||
6 years ago
|
props,
|
||
6 years ago
|
} = sidebar
|
||
6 years ago
|
const { transaction: sidebarTransaction } = props || {}
|
||
6 years ago
|
|
||
7 years ago
|
return (
|
||
6 years ago
|
<div
|
||
|
className="app"
|
||
|
onClick={() => setMouseUserState(true)}
|
||
|
onKeyDown={e => {
|
||
7 years ago
|
if (e.keyCode === 9) {
|
||
|
setMouseUserState(false)
|
||
|
}
|
||
6 years ago
|
}}
|
||
|
>
|
||
6 years ago
|
<UiMigrationAnnouncement />
|
||
6 years ago
|
<Modal />
|
||
|
<Alert
|
||
|
visible={this.props.alertOpen}
|
||
|
msg={alertMessage}
|
||
|
/>
|
||
|
{
|
||
|
!this.hideAppHeader() && (
|
||
|
<AppHeader
|
||
|
hideNetworkIndicator={this.onInitializationUnlockPage()}
|
||
|
disabled={this.onConfirmPage()}
|
||
|
/>
|
||
|
)
|
||
|
}
|
||
|
<Sidebar
|
||
|
sidebarOpen={sidebarIsOpen}
|
||
|
sidebarShouldClose={sidebarTransaction && !submittedPendingTransactions.find(({ id }) => id === sidebarTransaction.id)}
|
||
|
hideSidebar={this.props.hideSidebar}
|
||
|
transitionName={sidebarTransitionName}
|
||
|
type={sidebarType}
|
||
|
sidebarProps={sidebar.props}
|
||
6 years ago
|
onOverlayClose={sidebarOnOverlayClose}
|
||
6 years ago
|
/>
|
||
|
<NetworkDropdown
|
||
|
provider={provider}
|
||
|
frequentRpcListDetail={frequentRpcListDetail}
|
||
|
/>
|
||
|
<AccountMenu />
|
||
|
<div className="main-container-wrapper">
|
||
|
{ isLoading && <Loading loadingMessage={loadMessage} /> }
|
||
|
{ !isLoading && isLoadingNetwork && <LoadingNetwork /> }
|
||
|
{ this.renderRoutes() }
|
||
|
</div>
|
||
|
</div>
|
||
7 years ago
|
)
|
||
|
}
|
||
7 years ago
|
|
||
7 years ago
|
toggleMetamaskActive () {
|
||
|
if (!this.props.isUnlocked) {
|
||
|
// currently inactive: redirect to password box
|
||
|
var passwordBox = document.querySelector('input[type=password]')
|
||
|
if (!passwordBox) return
|
||
|
passwordBox.focus()
|
||
|
} else {
|
||
|
// currently active: deactivate
|
||
|
this.props.dispatch(actions.lockMetamask(false))
|
||
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
getConnectingLabel = function (loadingMessage) {
|
||
|
if (loadingMessage) {
|
||
|
return loadingMessage
|
||
|
}
|
||
6 years ago
|
const { provider, providerId } = this.props
|
||
7 years ago
|
const providerName = provider.type
|
||
|
|
||
|
let name
|
||
|
|
||
|
if (providerName === 'mainnet') {
|
||
7 years ago
|
name = this.context.t('connectingToMainnet')
|
||
7 years ago
|
} else if (providerName === 'ropsten') {
|
||
7 years ago
|
name = this.context.t('connectingToRopsten')
|
||
7 years ago
|
} else if (providerName === 'kovan') {
|
||
6 years ago
|
name = this.context.t('connectingToKovan')
|
||
7 years ago
|
} else if (providerName === 'rinkeby') {
|
||
7 years ago
|
name = this.context.t('connectingToRinkeby')
|
||
7 years ago
|
} else {
|
||
6 years ago
|
name = this.context.t('connectingTo', [providerId])
|
||
7 years ago
|
}
|
||
|
|
||
|
return name
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
getNetworkName () {
|
||
|
const { provider } = this.props
|
||
|
const providerName = provider.type
|
||
|
|
||
|
let name
|
||
|
|
||
|
if (providerName === 'mainnet') {
|
||
7 years ago
|
name = this.context.t('mainnet')
|
||
7 years ago
|
} else if (providerName === 'ropsten') {
|
||
7 years ago
|
name = this.context.t('ropsten')
|
||
7 years ago
|
} else if (providerName === 'kovan') {
|
||
7 years ago
|
name = this.context.t('kovan')
|
||
7 years ago
|
} else if (providerName === 'rinkeby') {
|
||
7 years ago
|
name = this.context.t('rinkeby')
|
||
7 years ago
|
} else {
|
||
7 years ago
|
name = this.context.t('unknownNetwork')
|
||
7 years ago
|
}
|
||
|
|
||
|
return name
|
||
9 years ago
|
}
|
||
|
}
|
||
9 years ago
|
|
||
6 years ago
|
Routes.propTypes = {
|
||
7 years ago
|
currentCurrency: PropTypes.string,
|
||
|
setCurrentCurrencyToUSD: PropTypes.func,
|
||
|
isLoading: PropTypes.bool,
|
||
|
loadingMessage: PropTypes.string,
|
||
6 years ago
|
alertMessage: PropTypes.string,
|
||
7 years ago
|
network: PropTypes.string,
|
||
|
provider: PropTypes.object,
|
||
6 years ago
|
frequentRpcListDetail: PropTypes.array,
|
||
7 years ago
|
currentView: PropTypes.object,
|
||
6 years ago
|
sidebar: PropTypes.object,
|
||
6 years ago
|
alertOpen: PropTypes.bool,
|
||
7 years ago
|
hideSidebar: PropTypes.func,
|
||
|
isOnboarding: PropTypes.bool,
|
||
|
isUnlocked: PropTypes.bool,
|
||
|
networkDropdownOpen: PropTypes.bool,
|
||
|
showNetworkDropdown: PropTypes.func,
|
||
|
hideNetworkDropdown: PropTypes.func,
|
||
|
history: PropTypes.object,
|
||
7 years ago
|
location: PropTypes.object,
|
||
7 years ago
|
dispatch: PropTypes.func,
|
||
|
toggleAccountMenu: PropTypes.func,
|
||
|
selectedAddress: PropTypes.string,
|
||
|
noActiveNotices: PropTypes.bool,
|
||
|
lostAccounts: PropTypes.array,
|
||
|
isInitialized: PropTypes.bool,
|
||
|
forgottenPassword: PropTypes.bool,
|
||
|
activeAddress: PropTypes.string,
|
||
|
unapprovedTxs: PropTypes.object,
|
||
|
seedWords: PropTypes.string,
|
||
6 years ago
|
submittedPendingTransactions: PropTypes.array,
|
||
7 years ago
|
unapprovedMsgCount: PropTypes.number,
|
||
|
unapprovedPersonalMsgCount: PropTypes.number,
|
||
|
unapprovedTypedMessagesCount: PropTypes.number,
|
||
7 years ago
|
welcomeScreenSeen: PropTypes.bool,
|
||
|
isPopup: PropTypes.bool,
|
||
|
isMouseUser: PropTypes.bool,
|
||
|
setMouseUserState: PropTypes.func,
|
||
7 years ago
|
t: PropTypes.func,
|
||
6 years ago
|
providerId: PropTypes.string,
|
||
6 years ago
|
providerRequests: PropTypes.array,
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
function mapStateToProps (state) {
|
||
|
const { appState, metamask } = state
|
||
|
const {
|
||
|
networkDropdownOpen,
|
||
6 years ago
|
sidebar,
|
||
6 years ago
|
alertOpen,
|
||
|
alertMessage,
|
||
7 years ago
|
isLoading,
|
||
|
loadingMessage,
|
||
|
} = appState
|
||
|
|
||
6 years ago
|
const accounts = getMetaMaskAccounts(state)
|
||
|
|
||
7 years ago
|
const {
|
||
|
identities,
|
||
|
address,
|
||
|
keyrings,
|
||
|
isInitialized,
|
||
|
noActiveNotices,
|
||
|
seedWords,
|
||
|
unapprovedTxs,
|
||
7 years ago
|
nextUnreadNotice,
|
||
7 years ago
|
lostAccounts,
|
||
7 years ago
|
unapprovedMsgCount,
|
||
|
unapprovedPersonalMsgCount,
|
||
|
unapprovedTypedMessagesCount,
|
||
6 years ago
|
providerRequests,
|
||
7 years ago
|
} = metamask
|
||
|
const selected = address || Object.keys(accounts)[0]
|
||
|
|
||
|
return {
|
||
|
// state from plugin
|
||
|
networkDropdownOpen,
|
||
6 years ago
|
sidebar,
|
||
6 years ago
|
alertOpen,
|
||
|
alertMessage,
|
||
7 years ago
|
isLoading,
|
||
|
loadingMessage,
|
||
|
noActiveNotices,
|
||
|
isInitialized,
|
||
|
isUnlocked: state.metamask.isUnlocked,
|
||
|
selectedAddress: state.metamask.selectedAddress,
|
||
|
currentView: state.appState.currentView,
|
||
|
activeAddress: state.appState.activeAddress,
|
||
|
transForward: state.appState.transForward,
|
||
|
isOnboarding: Boolean(!noActiveNotices || seedWords || !isInitialized),
|
||
7 years ago
|
isPopup: state.metamask.isPopup,
|
||
7 years ago
|
seedWords: state.metamask.seedWords,
|
||
6 years ago
|
submittedPendingTransactions: submittedPendingTransactionsSelector(state),
|
||
7 years ago
|
unapprovedTxs,
|
||
7 years ago
|
unapprovedMsgs: state.metamask.unapprovedMsgs,
|
||
7 years ago
|
unapprovedMsgCount,
|
||
|
unapprovedPersonalMsgCount,
|
||
|
unapprovedTypedMessagesCount,
|
||
7 years ago
|
menuOpen: state.appState.menuOpen,
|
||
|
network: state.metamask.network,
|
||
|
provider: state.metamask.provider,
|
||
|
forgottenPassword: state.appState.forgottenPassword,
|
||
7 years ago
|
nextUnreadNotice,
|
||
7 years ago
|
lostAccounts,
|
||
6 years ago
|
frequentRpcListDetail: state.metamask.frequentRpcListDetail || [],
|
||
7 years ago
|
currentCurrency: state.metamask.currentCurrency,
|
||
7 years ago
|
isMouseUser: state.appState.isMouseUser,
|
||
|
isRevealingSeedWords: state.metamask.isRevealingSeedWords,
|
||
|
Qr: state.appState.Qr,
|
||
|
welcomeScreenSeen: state.metamask.welcomeScreenSeen,
|
||
6 years ago
|
providerId: getNetworkIdentifier(state),
|
||
7 years ago
|
|
||
|
// state needed to get account dropdown temporarily rendering from app bar
|
||
|
identities,
|
||
|
selected,
|
||
|
keyrings,
|
||
6 years ago
|
providerRequests,
|
||
8 years ago
|
}
|
||
7 years ago
|
}
|
||
8 years ago
|
|
||
7 years ago
|
function mapDispatchToProps (dispatch, ownProps) {
|
||
|
return {
|
||
|
dispatch,
|
||
|
hideSidebar: () => dispatch(actions.hideSidebar()),
|
||
|
showNetworkDropdown: () => dispatch(actions.showNetworkDropdown()),
|
||
|
hideNetworkDropdown: () => dispatch(actions.hideNetworkDropdown()),
|
||
|
setCurrentCurrencyToUSD: () => dispatch(actions.setCurrentCurrency('usd')),
|
||
|
toggleAccountMenu: () => dispatch(actions.toggleAccountMenu()),
|
||
7 years ago
|
setMouseUserState: (isMouseUser) => dispatch(actions.setMouseUserState(isMouseUser)),
|
||
7 years ago
|
}
|
||
8 years ago
|
}
|
||
7 years ago
|
|
||
6 years ago
|
Routes.contextTypes = {
|
||
7 years ago
|
t: PropTypes.func,
|
||
6 years ago
|
metricsEvent: PropTypes.func,
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
module.exports = compose(
|
||
|
withRouter,
|
||
|
connect(mapStateToProps, mapDispatchToProps)
|
||
6 years ago
|
)(Routes)
|