on 181f4f7 help sign in
bridge/src/Root.js
92 lines 2.3 kB history raw
1import 'babel-polyfill' // required for @ledgerhq/hw-transport-u2f
3import React from 'react'
4import { get } from 'lodash'
6import Bridge from './bridge/Bridge'
7import Walletgen from './walletgen/Walletgen'
8// import { AppNavigation } from './common/components/AppNavigation'
10import './common/style/index.css'
11import './bridge/style/index.css'
13class Root extends React.Component {
14 constructor(props) {
15 super(props)
17 this.state = {
18 appView: "bridge"
19 }
21 this.setView = this.setView.bind(this)
22 }
24 /*
25 Style switching:
27 To switch between walletgen and bridge styles without them clobbering each
28 other, we need a way to identify which app the stylesheet belongs to.
30 So we include a "walletgen" or "bridge" style as the first rule of any
31 stylesheet. If this directive is included, we can disable the appropriate
32 sheet when the user switches applications
34 A bit hacky, but does the job for now. These styles should probably be
35 fully merged at some point.
36 */
38 isWalletgenStyle(styleSheet) {
39 return get(styleSheet, 'cssRules[0].selectorText', null) === "walletgen"
40 }
42 isBridgeStyle(styleSheet) {
43 return get(styleSheet, 'cssRules[0].selectorText', null) === "bridge"
44 }
46 disableStylesheets(appView) {
47 for (var i = 0; i < document.styleSheets.length; i++) {
48 let styleSheet = document.styleSheets[i]
50 if (appView === "bridge") {
51 if (this.isWalletgenStyle(styleSheet)) styleSheet.disabled = true
52 if (this.isBridgeStyle(styleSheet)) styleSheet.disabled = false
53 } else if (appView === "walletgen") {
54 if (this.isWalletgenStyle(styleSheet)) styleSheet.disabled = false
55 if (this.isBridgeStyle(styleSheet)) styleSheet.disabled = true
56 }
57 }
58 }
60 componentDidMount() {
61 this.disableStylesheets(this.state.appView)
62 }
64 setView(appView) {
65 this.disableStylesheets(appView)
67 this.setState({
68 appView
69 })
70 }
72 render() {
73 const { appView } = this.state;
75 switch (appView) {
76 case "walletgen":
77 return <Walletgen
78 appView={appView}
79 setView={this.setView} />
80 case "bridge":
81 return <Bridge
82 appView={appView}
83 setView={this.setView} />
84 default:
85 throw new Error(`Unknown appView ${appView}`)
86 }
87 }
90export {
91 Root