on 58b8e51 help sign in
bridge/src/Root.js
102 lines 2.6 kB history raw
1import 'babel-polyfill' // required for @ledgerhq/hw-transport-u2f
3import React from 'react'
4import _ from 'lodash'
6import Bridge from './bridge/Bridge'
7import Walletgen from './walletgen/Walletgen'
8import { AppNavigation } from './common/components/AppNavigation'
10import './common/style/index.css'
11import './bridge/style/index.css'
12import './walletgen/style/index.css'
14class Root extends React.Component {
15 constructor(props) {
16 super(props)
18 this.state = {
19 appView: "bridge"
20 }
22 this.setView = this.setView.bind(this)
23 }
25 /*
26 Style switching:
28 To switch between walletgen and bridge styles without them clobbering each
29 other, we need a way to identify which app the stylesheet belongs to.
31 So we include a "walletgen" or "bridge" style as the first rule of any
32 stylesheet. If this directive is included, we can disable the appropriate
33 sheet when the user switches applications
35 A bit hacky, but does the job for now. These styles should probably be
36 fully merged at some point.
37 */
39 isWalletgenStyle(styleSheet) {
40 return _.get(styleSheet, 'cssRules[0].selectorText', null) === "walletgen"
41 }
43 isBridgeStyle(styleSheet) {
44 return _.get(styleSheet, 'cssRules[0].selectorText', null) === "bridge"
45 }
47 disableStylesheets(appView) {
48 for (var i = 0; i < document.styleSheets.length; i++) {
49 let styleSheet = document.styleSheets[i]
51 if (appView === "bridge") {
52 if (this.isWalletgenStyle(styleSheet)) styleSheet.disabled = true
53 if (this.isBridgeStyle(styleSheet)) styleSheet.disabled = false
54 } else if (appView === "walletgen") {
55 if (this.isWalletgenStyle(styleSheet)) styleSheet.disabled = false
56 if (this.isBridgeStyle(styleSheet)) styleSheet.disabled = true
57 }
58 }
59 }
61 componentDidMount() {
62 this.disableStylesheets(this.state.appView)
63 }
65 setView(appView) {
66 this.disableStylesheets(appView)
68 this.setState({
69 appView
70 })
71 }
73 render() {
74 let appComponent = null;
76 if (this.state.appView === "walletgen") {
77 appComponent = <Walletgen
78 appView={this.state.appView}
79 setView={this.setView} />
80 }
82 if (this.state.appView === "bridge") {
83 appComponent = <Bridge
84 appView={this.state.appView}
85 setView={this.setView} />
86 }
88 return (
89 <React.Fragment>
90 {appComponent}
91 <AppNavigation
92 setView={this.setView}
93 appView={this.state.appView}
94 />
95 </React.Fragment>
96 )
97 }
100export {
101 Root