aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/pages/authenticated.js
diff options
context:
space:
mode:
authorAlexander Tseung <alextsg@gmail.com>2017-11-29 12:24:35 +0800
committerAlexander Tseung <alextsg@gmail.com>2017-12-15 04:50:20 +0800
commite226b10a89d87af07c7c35ff1251a8264f3bb1b8 (patch)
tree2a1507463ac1074a39e4ebd3ae609be0a2962bc6 /ui/app/components/pages/authenticated.js
parent339eb7d1a687f141e822c745c568063783d44f15 (diff)
downloadtangerine-wallet-browser-e226b10a89d87af07c7c35ff1251a8264f3bb1b8.tar.gz
tangerine-wallet-browser-e226b10a89d87af07c7c35ff1251a8264f3bb1b8.tar.zst
tangerine-wallet-browser-e226b10a89d87af07c7c35ff1251a8264f3bb1b8.zip
Add react-router to allow use of the browser back button
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)