aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/pages/authenticated.js
diff options
context:
space:
mode:
Diffstat (limited to 'ui/app/components/pages/authenticated.js')
-rw-r--r--ui/app/components/pages/authenticated.js42
1 files changed, 42 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..78f3a4225
--- /dev/null
+++ b/ui/app/components/pages/authenticated.js
@@ -0,0 +1,42 @@
+const { connect } = require('react-redux')
+const PropTypes = require('prop-types')
+const { Redirect, Route } = require('react-router-dom')
+const h = require('react-hyperscript')
+const { UNLOCK_ROUTE, INITIALIZE_MENU_ROUTE } = require('../../routes')
+
+const Authenticated = ({ component: Component, isUnlocked, isInitialized, ...props }) => {
+
+ const render = props => {
+ switch (true) {
+ case isUnlocked:
+ return h(Component, { ...props })
+ case !isInitialized:
+ return h(Redirect, { to: { pathname: INITIALIZE_MENU_ROUTE } })
+ default:
+ return h(Redirect, { to: { pathname: UNLOCK_ROUTE } })
+ }
+ }
+
+ return (
+ h(Route, {
+ ...props,
+ render,
+ })
+ )
+}
+
+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)