parent
e226b10a89
commit
dde39e82b5
@ -0,0 +1,28 @@ |
||||
const { connect } = require('react-redux') |
||||
const PropTypes = require('prop-types') |
||||
const { Route } = require('react-router-dom') |
||||
const h = require('react-hyperscript') |
||||
|
||||
const MetamaskRoute = ({ component, mascaraComponent, isMascara, ...props }) => { |
||||
return ( |
||||
h(Route, { |
||||
...props, |
||||
component: isMascara && mascaraComponent ? mascaraComponent : component, |
||||
}) |
||||
) |
||||
} |
||||
|
||||
MetamaskRoute.propTypes = { |
||||
component: PropTypes.func, |
||||
mascaraComponent: PropTypes.func, |
||||
isMascara: PropTypes.bool, |
||||
} |
||||
|
||||
const mapStateToProps = state => { |
||||
const { metamask: { isMascara } } = state |
||||
return { |
||||
isMascara, |
||||
} |
||||
} |
||||
|
||||
module.exports = connect(mapStateToProps)(MetamaskRoute) |
@ -0,0 +1,38 @@ |
||||
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) |
Loading…
Reference in new issue