Browse Source

settings spv server selection

v0.25
pbca26 8 years ago
parent
commit
51f4a2344d
  1. BIN
      assets/mainWindow/img/fa-flash.png
  2. 10
      react/src/components/dashboard/settings/settings.debugLogPanel.js
  3. 136
      react/src/components/dashboard/settings/settings.exportKeysPanel.js
  4. 18
      react/src/components/dashboard/settings/settings.js
  5. 11
      react/src/components/dashboard/settings/settings.panel.js
  6. 42
      react/src/components/dashboard/settings/settings.render.js
  7. 150
      react/src/components/dashboard/settings/settings.spvServersPanel.js

BIN
assets/mainWindow/img/fa-flash.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

10
react/src/components/dashboard/settings/settings.debugLogPanel.js

@ -100,11 +100,15 @@ class DebugLogPanel extends React.Component {
});
}
// TODO: extend to include asset chains
render() {
return (
<div className="row">
<div className="col-sm-12">
<p>{ translate('INDEX.DEBUG_LOG_DESC') }</p>
{ this.props.Main.coins && this.props.Main.coins.native && Object.keys(this.props.Main.coins.native).length > 0 &&
<p>{ translate('INDEX.DEBUG_LOG_DESC') }</p>
}
<div className="margin-top-30">
<span className="pointer toggle">
<label className="switch">
@ -122,7 +126,7 @@ class DebugLogPanel extends React.Component {
onClick={ this.toggleAppRuntimeLog }>Show app runtime log</span>
</span>
</div>
{ !this.state.toggleAppRuntimeLog &&
{ !this.state.toggleAppRuntimeLog && this.props.Main.coins && this.props.Main.coins.native && Object.keys(this.props.Main.coins.native).length > 0 &&
<form
className="read-debug-log-import-form"
method="post"
@ -146,7 +150,6 @@ class DebugLogPanel extends React.Component {
name="debugTarget"
id="settingsDelectDebugLogOptions"
onChange={ this.updateInput }>
<option value="iguana" className={ this.state.nativeOnly ? 'hide' : '' }>Iguana</option>
<option value="komodo">Komodo</option>
</select>
<label
@ -178,6 +181,7 @@ class DebugLogPanel extends React.Component {
const mapStateToProps = (state) => {
return {
Settings: state.Settings,
Main: state.Main,
};
};

136
react/src/components/dashboard/settings/settings.exportKeysPanel.js

@ -2,9 +2,9 @@ import React from 'react';
import { translate } from '../../../translate/translate';
import { connect } from 'react-redux';
import {
encryptWallet,
settingsWifkeyState,
copyCoinAddress,
shepherdElectrumKeys,
triggerToaster,
} from '../../../actions/actionCreators';
import Store from '../../../store';
@ -12,32 +12,44 @@ class ExportKeysPanel extends React.Component {
constructor() {
super();
this.state = {
exportWifKeysRaw: false,
seedInputVisibility: false,
trimPassphraseTimer: null,
wifkeysPassphrase: '',
keys: null,
};
this.exportWifKeys = this.exportWifKeys.bind(this);
this.exportWifKeysRaw = this.exportWifKeysRaw.bind(this);
this.toggleSeedInputVisibility = this.toggleSeedInputVisibility.bind(this);
this._copyCoinAddress = this._copyCoinAddress.bind(this);
this.updateInput = this.updateInput.bind(this);
}
exportWifKeys() {
Store.dispatch(
encryptWallet(
this.state.wifkeysPassphrase,
settingsWifkeyState,
this.props.ActiveCoin.coin
)
);
componentWillReceiveProps(props) {
if (props.Dashboard &&
props.Dashboard.activeSection !== 'settings') {
this.setState(Object.assign({}, this.state, {
keys: null,
}));
}
}
exportWifKeysRaw() {
this.setState(Object.assign({}, this.state, {
exportWifKeysRaw: !this.state.exportWifKeysRaw,
}));
exportWifKeys() {
shepherdElectrumKeys(this.state.wifkeysPassphrase)
.then((keys) => {
if (keys === 'error') {
Store.dispatch(
triggerToaster(
'Wrong passphrase!',
translate('TOASTR.WALLET_NOTIFICATION'),
'error'
)
);
} else {
this.setState(Object.assign({}, this.state, {
keys: keys.result,
}));
console.warn(keys);
}
})
}
toggleSeedInputVisibility() {
@ -46,21 +58,6 @@ class ExportKeysPanel extends React.Component {
});
}
renderExportWifKeysRaw() {
const _wifKeysResponse = this.props.Settings.wifkey;
if (_wifKeysResponse &&
this.state.exportWifKeysRaw) {
return (
<div className="padding-bottom-30 padding-top-30">
{ JSON.stringify(_wifKeysResponse, null, '\t') }
</div>
);
} else {
return null;
}
}
_copyCoinAddress(address) {
Store.dispatch(copyCoinAddress(address));
}
@ -68,38 +65,32 @@ class ExportKeysPanel extends React.Component {
renderWifKeys() {
let items = [];
if (this.props.Settings.wifkey) {
const _wifKeys = this.props.Settings.wifkey;
if (this.state.keys) {
const _wifKeys = this.state.keys;
for (let i = 0; i < 2; i++) {
for (let _key in _wifKeys) {
items.push(
<tr key={ `wif-export-table-header-${i}` }>
<td className="padding-bottom-10 padding-top-10">
<strong>{ i === 0 ? translate('SETTINGS.ADDRESS_LIST') : translate('SETTINGS.WIF_KEY_LIST') }</strong>
<tr key={ _key }>
<td className="padding-bottom-30">
<strong className="padding-right-20">{_key}</strong>{ _wifKeys[_key].pub }
<button
className="btn btn-default btn-xs clipboard-edexaddr margin-left-10"
title={ translate('INDEX.COPY_TO_CLIPBOARD') }
onClick={ () => this._copyCoinAddress(_wifKeys[_key].pub) }>
<i className="icon wb-copy"></i> { translate('INDEX.COPY') }
</button>
</td>
<td className="padding-bottom-30 padding-left-15">
{ _wifKeys[_key].priv }
<button
className="btn btn-default btn-xs clipboard-edexaddr margin-left-10"
title={ translate('INDEX.COPY_TO_CLIPBOARD') }
onClick={ () => this._copyCoinAddress(_wifKeys[_key].priv) }>
<i className="icon wb-copy"></i> { translate('INDEX.COPY') }
</button>
</td>
<td className="padding-bottom-10 padding-top-10"></td>
</tr>
);
for (let _key in _wifKeys) {
if ((i === 0 && _key.length === 3 && _key !== 'tag') ||
(i === 1 && _key.indexOf('wif') > -1)) {
items.push(
<tr key={ _key }>
<td className="padding-bottom-20">{ _key.replace('wif', ' WIF') }</td>
<td className="padding-bottom-20 padding-left-15">
{ _wifKeys[_key] }
<button
className="btn btn-default btn-xs clipboard-edexaddr margin-left-10"
title={ translate('INDEX.COPY_TO_CLIPBOARD') }
onClick={ () => this._copyCoinAddress(_wifKeys[_key]) }>
<i className="icon wb-copy"></i> { translate('INDEX.COPY') }
</button>
</td>
</tr>
);
}
}
}
return items;
@ -206,22 +197,23 @@ class ExportKeysPanel extends React.Component {
</form>
</div>
</div>
<div className="row">
<div className="col-sm-12 padding-top-15">
<table className="table">
{ this.renderWifKeys() }
</table>
<div className={ this.props.wifkey ? 'col-sm-12 col-xs-12 text-align-center' : 'hide' }>
<button
type="button"
className="btn btn-primary waves-effect waves-light"
onClick={ this.exportWifKeysRaw }>{ this.state.exportWifKeysRaw ? 'Hide' : 'Show' } raw data</button>
</div>
<div className={ this.state.exportWifKeysRaw ? 'col-sm-12 col-xs-12 text-align-center' : 'hide' }>
{ this.renderExportWifKeysRaw() }
{ this.state.keys &&
<div className="row">
<div className="col-sm-12 padding-top-15">
<table className="table">
<tr key={ `wif-export-table-header-pub` }>
<td className="padding-bottom-20 padding-top-20">
<strong>{ translate('SETTINGS.ADDRESS_LIST') }</strong>
</td>
<td className="padding-bottom-20 padding-top-20">
<strong>{ translate('SETTINGS.WIF_KEY_LIST') }</strong>
</td>
</tr>
{ this.renderWifKeys() }
</table>
</div>
</div>
</div>
}
</div>
);
};

18
react/src/components/dashboard/settings/settings.js

@ -21,6 +21,19 @@ import {
class Settings extends React.Component {
constructor(props) {
super(props);
this.displaySPVServerListTab = this.displaySPVServerListTab.bind(this);
}
displaySPVServerListTab() {
if (this.props.Main &&
this.props.Main.coins &&
this.props.Main.coins.spv) {
for (let i = 0; this.props.Main.coins.spv.length; i++) {
if (this.props.Dashboard.electrumCoins[this.props.Main.coins.spv[i]].serverList) {
return true;
}
}
}
}
componentDidMount(props) {
@ -37,9 +50,8 @@ class Settings extends React.Component {
const mapStateToProps = (state) => {
return {
Main: {
coins: state.Main.coins,
},
Main: state.Main,
Dashboard: state.Dashboard,
};
};

11
react/src/components/dashboard/settings/settings.panel.js

@ -19,7 +19,8 @@ class Panel extends React.Component {
singleOpen,
openByDefault,
uniqId,
children } = this.props;
children
} = this.props;
const settings = {
singleOpen,
@ -37,9 +38,8 @@ class Panel extends React.Component {
children,
} = this.props;
const kids = React.Children.map(children, (child, i) => {
if(child) {
const _children = React.Children.map(children, (child, i) => {
if (child) {
const unqId = `panel-sec-${i}`;
return React.cloneElement(child, {
toggle: (acId) => this.toggleSection(acId),
@ -49,9 +49,8 @@ class Panel extends React.Component {
});
}
});
return kids;
return _children;
}
toggleSection(sectionId) {

42
react/src/components/dashboard/settings/settings.render.js

@ -10,9 +10,10 @@ import AppSettingsPanel from './settings.appSettingsPanel';
import CliPanel from './settings.cliPanel';
import DebugLogPanel from './settings.debugLogPanel';
// import FiatCurrencyPanel from './settings.fiatCurrencyPanel';
// import ExportKeysPanel from './settings.exportKeysPanel';
import ExportKeysPanel from './settings.exportKeysPanel';
// import ImportKeysPanel from './settings.importKeysPanel';
import SupportPanel from './settings.supportPanel';
import SPVServersPanel from './settings.spvServersPanel';
// import WalletInfoPanel from './settings.walletInfoPanel';
// import WalletBackupPanel from './settings.walletBackupPanel';
@ -46,13 +47,6 @@ import SupportPanel from './settings.supportPanel';
<FiatCurrencyPanel />
</PanelSection>
}
{ !this.props.disableWalletSpecificUI &&
<PanelSection
title={ translate('INDEX.EXPORT_KEYS') }
icon="icon md-key">
<ExportKeysPanel />
</PanelSection>
}
{ !this.props.disableWalletSpecificUI &&
<PanelSection
title={ translate('INDEX.IMPORT_KEYS') }
@ -80,20 +74,36 @@ export const SettingsRender = function() {
<DebugLogPanel />
</PanelSection>
<PanelSection
title={ translate('SETTINGS.APP_CONFIG') + ' (config.json)' }
icon="icon fa-bug">
<AppSettingsPanel />
title={ translate('SETTINGS.APP_CONFIG') + ' (config.json)' }
icon="icon fa-bug">
<AppSettingsPanel />
</PanelSection>
<PanelSection
title={ translate('SETTINGS.APP_INFO') }
icon="icon md-info">
<AppInfoPanel />
</PanelSection>
<PanelSection
title="CLI"
icon="icon fa-code">
<CliPanel />
</PanelSection>
{ this.props.Main.coins && this.props.Main.coins.spv && Object.keys(this.props.Main.coins.spv).length && this.props.Main.isLoggedIn &&
<PanelSection
title={ translate('INDEX.EXPORT_KEYS') }
icon="icon md-key">
<ExportKeysPanel />
</PanelSection>
}
{ this.props.Main.coins && this.props.Main.coins.spv && Object.keys(this.props.Main.coins.spv).length && this.displaySPVServerListTab() &&
<PanelSection
title={ translate('SETTINGS.SPV_SERVERS') }
icon="icon fa-server">
<SPVServersPanel />
</PanelSection>
}
{ this.props.Main.coins && this.props.Main.coins.native && Object.keys(this.props.Main.coins.native).length > 0 &&
<PanelSection
title="CLI"
icon="icon fa-code">
<CliPanel />
</PanelSection>
}
<PanelSection
title={ translate('INDEX.UPDATE') }
icon="icon fa fa-cloud-download">

150
react/src/components/dashboard/settings/settings.spvServersPanel.js

@ -0,0 +1,150 @@
import React from 'react';
import { translate } from '../../../translate/translate';
import { connect } from 'react-redux';
import {
shepherdElectrumCheckServerConnection,
shepherdElectrumSetServer,
shepherdElectrumCoins,
triggerToaster,
} from '../../../actions/actionCreators';
import Store from '../../../store';
class SPVServersPanel extends React.Component {
constructor() {
super();
this.updateInput = this.updateInput.bind(this);
}
componentWillReceiveProps(props) {
if (props.Dashboard &&
props.Dashboard.activeSection !== 'settings') {
this.setState(Object.assign({}, this.state, {
keys: null,
}));
}
}
setElectrumServer(coin) {
let _server = [
this.props.Dashboard.electrumCoins[coin].server.ip,
this.props.Dashboard.electrumCoins[coin].server.port
];
if (this.state &&
this.state[coin]) {
_server = this.state[coin].split(':');
}
shepherdElectrumCheckServerConnection(_server[0], _server[1])
.then((res) => {
if (res.result) {
shepherdElectrumSetServer(coin, _server[0], _server[1])
.then((serverSetRes) => {
Store.dispatch(
triggerToaster(
`${coin} SPV server set to ${_server[0]}:${_server[1]}`,
translate('TOASTR.WALLET_NOTIFICATION'),
'success'
)
);
Store.dispatch(shepherdElectrumCoins());
});
} else {
Store.dispatch(
triggerToaster(
`${coin} SPV server ${_server[0]}:${_server[1]} is unreachable!`,
translate('TOASTR.WALLET_NOTIFICATION'),
'error'
)
);
}
})
}
updateInput(e) {
this.setState({
[e.target.name]: e.target.value,
});
}
renderServerListSelectorOptions(coin) {
let _items = [];
let _spvServers = this.props.Dashboard.electrumCoins[coin].serverList;
for (let i = 0; i < _spvServers.length; i++) {
_items.push(
<option
key={ `spv-server-list-${ coin }-${i}` }
value={ `${_spvServers[i]}` }>{ `${_spvServers[i]}` }</option>
);
}
return _items;
}
renderServerList() {
let _items = [];
let _spvCoins = this.props.Main.coins.spv;
for (let i = 0; i < _spvCoins.length; i++) {
if (this.props.Dashboard.electrumCoins[_spvCoins[i]] &&
this.props.Dashboard.electrumCoins[_spvCoins[i]].serverList &&
this.props.Dashboard.electrumCoins[_spvCoins[i]].serverList !== 'none') {
_items.push(
<div
className={ 'row' + (_spvCoins.length > 1 ? ' padding-bottom-30' : '') }
key={ `spv-server-list-${ _spvCoins[i] }` }>
<div className="col-sm-12">
<strong className="col-sm-1">{ _spvCoins[i] }</strong>
<div className="col-sm-3">
<select
className="form-control form-material"
name={ _spvCoins[i] }
value={ (this.state && this.state[_spvCoins[i]]) || this.props.Dashboard.electrumCoins[_spvCoins[i]].server.ip + ':' + this.props.Dashboard.electrumCoins[_spvCoins[i]].server.port }
onChange={ (event) => this.updateInput(event) }
autoFocus>
{ this.renderServerListSelectorOptions(_spvCoins[i]) }
</select>
</div>
<div className="col-sm-1">
<button
type="button"
className="btn btn-primary"
onClick={ () => this.setElectrumServer(_spvCoins[i]) }>
OK
</button>
</div>
</div>
</div>
);
}
}
return _items;
}
render() {
return (
<div>
<div className="row">
<div className="col-sm-12 padding-bottom-30">
<p>{ translate('SETTINGS.SPV_SERVER_LIST_DESC') }</p>
</div>
</div>
{ this.renderServerList() }
</div>
);
};
}
const mapStateToProps = (state) => {
return {
ActiveCoin: {
coin: state.ActiveCoin.coin,
},
Dashboard: state.Dashboard,
Main: state.Main,
};
};
export default connect(mapStateToProps)(SPVServersPanel);
Loading…
Cancel
Save