aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/pages/unauthenticated/index.js
blob: f8b5fa172b75119166fc8b8aecf7fc2be08e5815 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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)