diff options
author | kumavis <kumavis@users.noreply.github.com> | 2018-04-10 04:56:59 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-10 04:56:59 +0800 |
commit | df1f891585dc41a7d725d592902a84e432e66dc4 (patch) | |
tree | e450c931e8d6d4a1277fd57e330fa8882d7cc93f /ui/app/components/pages/authenticated.js | |
parent | 931ce120737210cbbf6736b454580ac0610f527a (diff) | |
parent | 305f5f0034f347ee3eacbc4e6ef41817c1de9ab2 (diff) | |
download | tangerine-wallet-browser-df1f891585dc41a7d725d592902a84e432e66dc4.tar.gz tangerine-wallet-browser-df1f891585dc41a7d725d592902a84e432e66dc4.tar.zst tangerine-wallet-browser-df1f891585dc41a7d725d592902a84e432e66dc4.zip |
Merge branch 'master' into i3621-LogoPerformance
Diffstat (limited to 'ui/app/components/pages/authenticated.js')
-rw-r--r-- | ui/app/components/pages/authenticated.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/ui/app/components/pages/authenticated.js b/ui/app/components/pages/authenticated.js new file mode 100644 index 000000000..1f6b0be49 --- /dev/null +++ b/ui/app/components/pages/authenticated.js @@ -0,0 +1,34 @@ +const { connect } = require('react-redux') +const PropTypes = require('prop-types') +const { Redirect } = require('react-router-dom') +const h = require('react-hyperscript') +const MetamaskRoute = require('./metamask-route') +const { UNLOCK_ROUTE, INITIALIZE_ROUTE } = require('../../routes') + +const Authenticated = props => { + const { isUnlocked, isInitialized } = props + + switch (true) { + case isUnlocked && isInitialized: + return h(MetamaskRoute, { ...props }) + case !isInitialized: + return h(Redirect, { to: { pathname: INITIALIZE_ROUTE } }) + default: + return h(Redirect, { to: { pathname: UNLOCK_ROUTE } }) + } +} + +Authenticated.propTypes = { + isUnlocked: PropTypes.bool, + isInitialized: PropTypes.bool, +} + +const mapStateToProps = state => { + const { metamask: { isUnlocked, isInitialized } } = state + return { + isUnlocked, + isInitialized, + } +} + +module.exports = connect(mapStateToProps)(Authenticated) |