1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-23 11:46:13 +02:00
metamask-extension/ui/app/components/pages/authenticated.js

43 lines
1.1 KiB
JavaScript
Raw Normal View History

const { connect } = require('react-redux')
const PropTypes = require('prop-types')
2017-12-04 07:24:30 +01:00
const { Redirect } = require('react-router-dom')
const h = require('react-hyperscript')
2017-12-04 07:24:30 +01:00
const MetamaskRoute = require('./metamask-route')
const { UNLOCK_ROUTE, INITIALIZE_ROUTE } = require('../../routes')
const Authenticated = ({ component: Component, isUnlocked, isInitialized, ...props }) => {
2017-12-04 07:24:30 +01:00
const component = renderProps => {
switch (true) {
case isUnlocked:
2017-12-04 07:24:30 +01:00
return h(Component, { ...renderProps })
case !isInitialized:
2017-12-04 07:24:30 +01:00
return h(Redirect, { to: { pathname: INITIALIZE_ROUTE } })
default:
return h(Redirect, { to: { pathname: UNLOCK_ROUTE } })
}
}
return (
2017-12-04 07:24:30 +01:00
h(MetamaskRoute, {
...props,
2017-12-04 07:24:30 +01:00
component,
})
)
}
Authenticated.propTypes = {
component: PropTypes.func,
isUnlocked: PropTypes.bool,
isInitialized: PropTypes.bool,
}
const mapStateToProps = state => {
const { metamask: { isUnlocked, isInitialized } } = state
return {
isUnlocked,
isInitialized,
}
}
module.exports = connect(mapStateToProps)(Authenticated)