1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Add initialized checks for first time flow routes

This commit is contained in:
Alexander Tseung 2017-12-04 15:13:02 -05:00
parent d9ea2df6c2
commit 706a6b0ad6
6 changed files with 60 additions and 83 deletions

View File

@ -12,10 +12,10 @@ import { DEFAULT_ROUTE } from '../../../../ui/app/routes'
class ConfirmSeedScreen extends Component { class ConfirmSeedScreen extends Component {
static propTypes = { static propTypes = {
isLoading: PropTypes.bool.isRequired, isLoading: PropTypes.bool,
address: PropTypes.string.isRequired, address: PropTypes.string,
seedWords: PropTypes.string, seedWords: PropTypes.string,
confirmSeedWords: PropTypes.func.isRequired, confirmSeedWords: PropTypes.func,
history: PropTypes.object, history: PropTypes.object,
}; };
@ -28,7 +28,7 @@ class ConfirmSeedScreen extends Component {
const { seedWords } = props const { seedWords } = props
this.state = { this.state = {
selectedSeeds: [], selectedSeeds: [],
shuffledSeeds: seedWords && shuffle(seedWords.split(' ')), shuffledSeeds: seedWords && shuffle(seedWords.split(' ')) || [],
} }
} }

View File

@ -24,10 +24,10 @@ const WalletView = require('./components/wallet-view')
// other views // other views
const Authenticated = require('./components/pages/authenticated') const Authenticated = require('./components/pages/authenticated')
const Unauthenticated = require('./components/pages/unauthenticated') const Initialized = require('./components/pages/initialized')
const MetamaskRoute = require('./components/pages/metamask-route') const MetamaskRoute = require('./components/pages/metamask-route')
const Settings = require('./components/pages/settings') const Settings = require('./components/pages/settings')
const UnlockPage = require('./components/pages/unauthenticated/unlock') const UnlockPage = require('./components/pages/unlock')
const RestoreVaultPage = require('./components/pages/keychains/restore-vault') const RestoreVaultPage = require('./components/pages/keychains/restore-vault')
const RevealSeedPage = require('./components/pages/keychains/reveal-seed') const RevealSeedPage = require('./components/pages/keychains/reveal-seed')
const AddTokenPage = require('./components/pages/add-token') const AddTokenPage = require('./components/pages/add-token')
@ -88,21 +88,21 @@ class App extends Component {
component: InitializeMenuScreen, component: InitializeMenuScreen,
mascaraComponent: MascaraCreatePassword, mascaraComponent: MascaraCreatePassword,
}), }),
h(MetamaskRoute, { h(Initialized, {
path: REVEAL_SEED_ROUTE, path: REVEAL_SEED_ROUTE,
exact, exact,
component: RevealSeedPage, component: RevealSeedPage,
mascaraComponent: MascaraSeedScreen, mascaraComponent: MascaraSeedScreen,
}), }),
h(MetamaskRoute, { h(Initialized, {
path: CONFIRM_SEED_ROUTE, path: CONFIRM_SEED_ROUTE,
exact, exact,
mascaraComponent: MascaraConfirmSeedScreen, mascaraComponent: MascaraConfirmSeedScreen,
}), }),
h(Unauthenticated, { path: UNLOCK_ROUTE, exact, component: UnlockPage }), h(Initialized, { path: UNLOCK_ROUTE, exact, component: UnlockPage }),
h(Unauthenticated, { path: SETTINGS_ROUTE, component: Settings }), h(Initialized, { path: SETTINGS_ROUTE, component: Settings }),
h(Unauthenticated, { path: RESTORE_VAULT_ROUTE, exact, component: RestoreVaultPage }), h(Initialized, { path: RESTORE_VAULT_ROUTE, exact, component: RestoreVaultPage }),
h(Unauthenticated, { h(Initialized, {
path: NOTICE_ROUTE, path: NOTICE_ROUTE,
exact, exact,
component: NoticeScreen, component: NoticeScreen,

View File

@ -5,28 +5,20 @@ const h = require('react-hyperscript')
const MetamaskRoute = require('./metamask-route') const MetamaskRoute = require('./metamask-route')
const { UNLOCK_ROUTE, INITIALIZE_ROUTE } = require('../../routes') const { UNLOCK_ROUTE, INITIALIZE_ROUTE } = require('../../routes')
const Authenticated = ({ component: Component, isUnlocked, isInitialized, ...props }) => { const Authenticated = props => {
const component = renderProps => { const { isUnlocked, isInitialized } = props
switch (true) {
case isUnlocked:
return h(Component, { ...renderProps })
case !isInitialized:
return h(Redirect, { to: { pathname: INITIALIZE_ROUTE } })
default:
return h(Redirect, { to: { pathname: UNLOCK_ROUTE } })
}
}
return ( switch (true) {
h(MetamaskRoute, { case isUnlocked && isInitialized:
...props, return h(MetamaskRoute, { ...props })
component, case !isInitialized:
}) return h(Redirect, { to: { pathname: INITIALIZE_ROUTE } })
) default:
return h(Redirect, { to: { pathname: UNLOCK_ROUTE } })
}
} }
Authenticated.propTypes = { Authenticated.propTypes = {
component: PropTypes.func,
isUnlocked: PropTypes.bool, isUnlocked: PropTypes.bool,
isInitialized: PropTypes.bool, isInitialized: PropTypes.bool,
} }

View File

@ -0,0 +1,25 @@
const { connect } = require('react-redux')
const PropTypes = require('prop-types')
const { Redirect } = require('react-router-dom')
const h = require('react-hyperscript')
const { INITIALIZE_ROUTE } = require('../../routes')
const MetamaskRoute = require('./metamask-route')
const Initialized = props => {
return props.isInitialized
? h(MetamaskRoute, { ...props })
: h(Redirect, { to: { pathname: INITIALIZE_ROUTE } })
}
Initialized.propTypes = {
isInitialized: PropTypes.bool,
}
const mapStateToProps = state => {
const { metamask: { isInitialized } } = state
return {
isInitialized,
}
}
module.exports = connect(mapStateToProps)(Initialized)

View File

@ -1,38 +0,0 @@
const { connect } = require('react-redux')
const PropTypes = require('prop-types')
const { Redirect } = require('react-router-dom')
const h = require('react-hyperscript')
const { INITIALIZE_ROUTE } = require('../../../routes')
const MetamaskRoute = require('../metamask-route')
const Unauthenticated = ({ component: Component, isInitialized, ...props }) => {
const component = renderProps => {
return isInitialized
? h(Component, { ...renderProps })
: h(Redirect, { to: { pathname: INITIALIZE_ROUTE } })
}
return (
h(MetamaskRoute, {
...props,
component,
})
)
}
Unauthenticated.propTypes = {
component: PropTypes.func,
isInitialized: PropTypes.bool,
isMascara: PropTypes.bool,
mascaraComponent: PropTypes.func,
}
const mapStateToProps = state => {
const { metamask: { isInitialized, isMascara } } = state
return {
isInitialized,
isMascara,
}
}
module.exports = connect(mapStateToProps)(Unauthenticated)

View File

@ -2,13 +2,13 @@ const { Component } = require('react')
const PropTypes = require('prop-types') const PropTypes = require('prop-types')
const { connect } = require('react-redux') const { connect } = require('react-redux')
const h = require('react-hyperscript') const h = require('react-hyperscript')
const { Redirect, withRouter } = require('react-router-dom') const { withRouter } = require('react-router-dom')
const { compose } = require('recompose') const { compose } = require('recompose')
const { tryUnlockMetamask, forgotPassword } = require('../../../actions') const { tryUnlockMetamask, forgotPassword } = require('../../actions')
const getCaretCoordinates = require('textarea-caret') const getCaretCoordinates = require('textarea-caret')
const EventEmitter = require('events').EventEmitter const EventEmitter = require('events').EventEmitter
const Mascot = require('../../mascot') const Mascot = require('../mascot')
const { DEFAULT_ROUTE, RESTORE_VAULT_ROUTE } = require('../../../routes') const { DEFAULT_ROUTE, RESTORE_VAULT_ROUTE } = require('../../routes')
class UnlockScreen extends Component { class UnlockScreen extends Component {
constructor (props) { constructor (props) {
@ -21,6 +21,14 @@ class UnlockScreen extends Component {
this.animationEventEmitter = new EventEmitter() this.animationEventEmitter = new EventEmitter()
} }
componentWillMount () {
const { isUnlocked, history } = this.props
if (isUnlocked) {
history.push(DEFAULT_ROUTE)
}
}
componentDidMount () { componentDidMount () {
const passwordBox = document.getElementById('password-box') const passwordBox = document.getElementById('password-box')
@ -69,17 +77,7 @@ class UnlockScreen extends Component {
render () { render () {
const { error } = this.state const { error } = this.state
const { isUnlocked, history } = this.props const { history } = this.props
if (isUnlocked) {
return (
h(Redirect, {
to: {
pathname: DEFAULT_ROUTE,
},
})
)
}
return ( return (
h('.unlock-page.main-container', [ h('.unlock-page.main-container', [