on 791d63a help sign in
bridge/src/Root.js
84 lines 2.3 kB history raw
1import React from 'react';
2import { get } from 'lodash';
4import Bridge from './bridge/Bridge';
5import Walletgen from './walletgen/Walletgen';
6// import { AppNavigation } from './common/components/AppNavigation'
8import './common/style/index.css';
9import './bridge/style/index.css';
11class Root extends React.Component {
12 constructor(props) {
13 super(props);
15 this.state = {
16 appView: 'bridge',
17 };
19 this.setView = this.setView.bind(this);
20 }
22 /*
23 Style switching:
25 To switch between walletgen and bridge styles without them clobbering each
26 other, we need a way to identify which app the stylesheet belongs to.
28 So we include a "walletgen" or "bridge" style as the first rule of any
29 stylesheet. If this directive is included, we can disable the appropriate
30 sheet when the user switches applications
32 A bit hacky, but does the job for now. These styles should probably be
33 fully merged at some point.
34 */
36 isWalletgenStyle(styleSheet) {
37 return get(styleSheet, 'cssRules[0].selectorText', null) === 'walletgen';
38 }
40 isBridgeStyle(styleSheet) {
41 return get(styleSheet, 'cssRules[0].selectorText', null) === 'bridge';
42 }
44 disableStylesheets(appView) {
45 for (var i = 0; i < document.styleSheets.length; i++) {
46 let styleSheet = document.styleSheets[i];
48 if (appView === 'bridge') {
49 if (this.isWalletgenStyle(styleSheet)) styleSheet.disabled = true;
50 if (this.isBridgeStyle(styleSheet)) styleSheet.disabled = false;
51 } else if (appView === 'walletgen') {
52 if (this.isWalletgenStyle(styleSheet)) styleSheet.disabled = false;
53 if (this.isBridgeStyle(styleSheet)) styleSheet.disabled = true;
54 }
55 }
56 }
58 componentDidMount() {
59 this.disableStylesheets(this.state.appView);
60 }
62 setView(appView) {
63 this.disableStylesheets(appView);
65 this.setState({
66 appView,
67 });
68 }
70 render() {
71 const { appView } = this.state;
73 switch (appView) {
74 case 'walletgen':
75 return <Walletgen appView={appView} setView={this.setView} />;
76 case 'bridge':
77 return <Bridge appView={appView} setView={this.setView} />;
78 default:
79 throw new Error(`Unknown appView ${appView}`);
80 }
81 }
84export { Root };