From 458ee4cbadd27777c07eccd43b4bdf18e9b8ff9c Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Sat, 5 Nov 2016 12:08:14 +0100 Subject: [PATCH] Parity configuration settings, i.e. mode (#3212) * Add initial page * Add parity icon * opacity for parity icon * Mode selector * Actually set mode when value changes --- js/src/index.js | 3 +- js/src/views/Settings/Parity/index.js | 17 ++++ js/src/views/Settings/Parity/parity.js | 116 +++++++++++++++++++++++++ js/src/views/Settings/index.js | 2 + js/src/views/Settings/settings.css | 10 +++ js/src/views/Settings/settings.js | 59 +++++-------- js/src/views/index.js | 3 +- 7 files changed, 171 insertions(+), 39 deletions(-) create mode 100644 js/src/views/Settings/Parity/index.js create mode 100644 js/src/views/Settings/Parity/parity.js diff --git a/js/src/index.js b/js/src/index.js index a4b5d5c59..a8cb8ac96 100644 --- a/js/src/index.js +++ b/js/src/index.js @@ -31,7 +31,7 @@ import ContractInstances from './contracts'; import { initStore } from './redux'; import { ContextProvider, muiTheme } from './ui'; -import { Accounts, Account, Addresses, Address, Application, Contract, Contracts, Dapp, Dapps, Settings, SettingsBackground, SettingsProxy, SettingsViews, Signer, Status } from './views'; +import { Accounts, Account, Addresses, Address, Application, Contract, Contracts, Dapp, Dapps, Settings, SettingsBackground, SettingsParity, SettingsProxy, SettingsViews, Signer, Status } from './views'; import { setApi } from './redux/providers/apiActions'; @@ -81,6 +81,7 @@ ReactDOM.render( + diff --git a/js/src/views/Settings/Parity/index.js b/js/src/views/Settings/Parity/index.js new file mode 100644 index 000000000..38f08f725 --- /dev/null +++ b/js/src/views/Settings/Parity/index.js @@ -0,0 +1,17 @@ +// Copyright 2015, 2016 Ethcore (UK) Ltd. +// This file is part of Parity. + +// Parity is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity. If not, see . + +export default from './parity'; diff --git a/js/src/views/Settings/Parity/parity.js b/js/src/views/Settings/Parity/parity.js new file mode 100644 index 000000000..6a3ba631f --- /dev/null +++ b/js/src/views/Settings/Parity/parity.js @@ -0,0 +1,116 @@ +// Copyright 2015, 2016 Ethcore (UK) Ltd. +// This file is part of Parity. + +// Parity is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity. If not, see . + +import React, { Component, PropTypes } from 'react'; +import { MenuItem } from 'material-ui'; + +import { Select, Container, ContainerTitle } from '../../../ui'; + +import layout from '../layout.css'; + +const MODES = { + 'active': 'Parity continuously syncs the chain', + 'passive': 'Parity syncs initially, then sleeps and wakes regularly to resync', + 'dark': 'Parity syncs only when the RPC is active', + 'offline': 'Parity doesn\'t sync' +}; + +export default class Parity extends Component { + static contextTypes = { + api: PropTypes.object.isRequired + } + + state = { + mode: 'active' + } + + componentWillMount () { + this.loadMode(); + } + + render () { + return ( + + +
+
+
Control the Parity node settings and mode of operation via this interface.
+
+
+ { this.renderModes() } +
+
+
+ ); + } + + renderModes () { + const modes = Object + .keys(MODES) + .map((mode) => { + const description = MODES[mode]; + + return ( + + { description } + + ); + }); + + const { mode } = this.state; + + return ( + + ); + } + + onChangeMode = (event, index, mode) => { + const { api } = this.context; + + api.ethcore + .setMode(mode) + .then((result) => { + if (result) { + this.setState({ mode }); + } + }) + .catch((error) => { + console.warn('onChangeMode', error); + }); + } + + loadMode () { + const { api } = this.context; + + api.ethcore + .mode() + .then((mode) => { + this.setState({ mode }); + }) + .catch((error) => { + console.warn('loadMode', error); + }); + } +} diff --git a/js/src/views/Settings/index.js b/js/src/views/Settings/index.js index 6971db224..4c5414f71 100644 --- a/js/src/views/Settings/index.js +++ b/js/src/views/Settings/index.js @@ -17,6 +17,7 @@ import settingsReducer from './reducers'; import { toggleView, updateBackground } from './actions'; import SettingsBackground from './Background'; +import SettingsParity from './Parity'; import SettingsProxy from './Proxy'; import SettingsViews, { defaultViews } from './Views'; @@ -24,6 +25,7 @@ export default from './settings'; export { SettingsBackground, + SettingsParity, SettingsProxy, SettingsViews, defaultViews, diff --git a/js/src/views/Settings/settings.css b/js/src/views/Settings/settings.css index ebd7b4ec0..91138db68 100644 --- a/js/src/views/Settings/settings.css +++ b/js/src/views/Settings/settings.css @@ -61,3 +61,13 @@ vertical-align: top; display: inline-block; } + +.imageIcon { + height: 20px; + margin: 2px 0.5em 2px 0 !important; + opacity: 0.5; +} + +.tabactive .imageIcon { + opacity: 1; +} diff --git a/js/src/views/Settings/settings.js b/js/src/views/Settings/settings.js index 2b9579993..4b38b1ccf 100644 --- a/js/src/views/Settings/settings.js +++ b/js/src/views/Settings/settings.js @@ -14,8 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -// 0xecf69634885f27a8f78161e530f15a8d3b57d39e755c222c92cf297b6e25aaaa - import React, { Component, PropTypes } from 'react'; import { Tab, Tabs } from 'material-ui'; import ActionSettingsEthernet from 'material-ui/svg-icons/action/settings-ethernet'; @@ -23,6 +21,7 @@ import ImageBlurOn from 'material-ui/svg-icons/image/blur-on'; import ImageRemoveRedEye from 'material-ui/svg-icons/image/remove-red-eye'; import { Actionbar, Page } from '../../ui'; +import imagesEthcoreBlock from '../../../assets/images/parity-logo-white-no-text.svg'; import styles from './settings.css'; @@ -37,11 +36,23 @@ export default class Settings extends Component { render () { const { children } = this.props; + const hash = (window.location.hash || '').split('?')[0].split('/')[2]; + const isProxied = window.location.hostname.indexOf('.parity') !== -1; + let proxy = null; + + if (!isProxied) { + proxy = this.renderTab(hash, 'proxy', ); + } return (
- { this.renderTabs() } + + { this.renderTab(hash, 'views', ) } + { this.renderTab(hash, 'background', ) } + { proxy } + { this.renderTab(hash, 'parity', ) } + { children } @@ -50,41 +61,15 @@ export default class Settings extends Component { ); } - renderTabs () { - const hash = (window.location.hash || '').split('?')[0].split('/')[2]; - const isProxied = window.location.hostname.indexOf('.parity') !== -1; - let proxy = null; - - if (!isProxied) { - proxy = ( - } - label={
proxy
} - onActive={ this.onActivate('proxy') } /> - ); - } - + renderTab (hash, section, icon) { return ( - - } - label={
views
} - onActive={ this.onActivate('views') } /> - } - label={
background
} - onActive={ this.onActivate('background') } /> - { proxy } -
+ { section }
} + onActive={ this.onActivate(section) } /> ); } diff --git a/js/src/views/index.js b/js/src/views/index.js index c40219c49..b102d389a 100644 --- a/js/src/views/index.js +++ b/js/src/views/index.js @@ -24,7 +24,7 @@ import Contracts from './Contracts'; import Dapp from './Dapp'; import Dapps from './Dapps'; import ParityBar from './ParityBar'; -import Settings, { SettingsBackground, SettingsProxy, SettingsViews } from './Settings'; +import Settings, { SettingsBackground, SettingsParity, SettingsProxy, SettingsViews } from './Settings'; import Signer from './Signer'; import Status from './Status'; @@ -41,6 +41,7 @@ export { ParityBar, Settings, SettingsBackground, + SettingsParity, SettingsProxy, SettingsViews, Signer,