on cb4ec11 help sign in
bridge/src/Root.js
97 lines 2.5 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'
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 let appComponent = null;
75 if (this.state.appView === "walletgen") {
76 appComponent = <Walletgen
77 appView={this.state.appView}
78 setView={this.setView} />
79 }
81 if (this.state.appView === "bridge") {
82 appComponent = <Bridge
83 appView={this.state.appView}
84 setView={this.setView} />
85 }
87 return (
88 <React.Fragment>
89 {appComponent}
90 </React.Fragment>
91 )
92 }
95export {
96 Root