diff options
author | Dan <danjm.com@gmail.com> | 2018-04-10 17:49:01 +0800 |
---|---|---|
committer | Dan <danjm.com@gmail.com> | 2018-04-10 17:49:01 +0800 |
commit | f4d8da927734b2dcd597d1cc833f9fe6ac59cc77 (patch) | |
tree | 24984f09e1a0a86b8187ffee5197e3857a2b10cc /ui/app/components/pages/authenticated.js | |
parent | 284dd85a99f538b77fd477f4952117d1792f64a5 (diff) | |
parent | 29dab1e9e00c1c1e6ad834026df51b2839d3171d (diff) | |
download | tangerine-wallet-browser-f4d8da927734b2dcd597d1cc833f9fe6ac59cc77.tar.gz tangerine-wallet-browser-f4d8da927734b2dcd597d1cc833f9fe6ac59cc77.tar.zst tangerine-wallet-browser-f4d8da927734b2dcd597d1cc833f9fe6ac59cc77.zip |
Merge branch 'master' into i3725-refactor-send-component
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) |