You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
407 lines
10 KiB
407 lines
10 KiB
8 years ago
|
import React from 'react';
|
||
8 years ago
|
import { translate } from '../../../translate/translate';
|
||
8 years ago
|
import {
|
||
|
iguanaActiveHandle,
|
||
|
encryptWallet,
|
||
|
settingsWifkeyState,
|
||
|
importPrivKey,
|
||
|
getDebugLog,
|
||
|
getPeersList,
|
||
8 years ago
|
addPeerNode,
|
||
8 years ago
|
getAppConfig,
|
||
|
saveAppConfig,
|
||
8 years ago
|
getAppInfo,
|
||
|
shepherdCli
|
||
8 years ago
|
} from '../../../actions/actionCreators';
|
||
|
import Store from '../../../store';
|
||
8 years ago
|
|
||
|
import {
|
||
|
AppInfoTabRender,
|
||
|
SettingsRender
|
||
|
} from './settings.render';
|
||
8 years ago
|
|
||
8 years ago
|
/*
|
||
|
TODO:
|
||
|
1) pre-select active coin in add node tab
|
||
8 years ago
|
2) add fiat section
|
||
|
3) kickstart section
|
||
8 years ago
|
4) batch export/import wallet addresses
|
||
8 years ago
|
*/
|
||
8 years ago
|
class Settings extends React.Component {
|
||
|
constructor(props) {
|
||
|
super(props);
|
||
|
this.state = {
|
||
|
activeTab: 0,
|
||
8 years ago
|
debugLinesCount: 10,
|
||
|
debugTarget: 'iguana',
|
||
8 years ago
|
activeTabHeight: '0',
|
||
8 years ago
|
appSettings: {},
|
||
8 years ago
|
tabElId: null,
|
||
8 years ago
|
cliCmdString: null,
|
||
|
cliCoin: null,
|
||
|
cliResponse: null,
|
||
8 years ago
|
exportWifKeysRaw: false,
|
||
8 years ago
|
seedInputVisibility: false,
|
||
8 years ago
|
};
|
||
8 years ago
|
this.exportWifKeys = this.exportWifKeys.bind(this);
|
||
8 years ago
|
this.updateInput = this.updateInput.bind(this);
|
||
8 years ago
|
this.updateInputSettings = this.updateInputSettings.bind(this);
|
||
8 years ago
|
this.importWifKey = this.importWifKey.bind(this);
|
||
|
this.readDebugLog = this.readDebugLog.bind(this);
|
||
|
this.checkNodes = this.checkNodes.bind(this);
|
||
|
this.addNode = this.addNode.bind(this);
|
||
|
this.renderPeersList = this.renderPeersList.bind(this);
|
||
|
this.renderSNPeersList = this.renderSNPeersList.bind(this);
|
||
8 years ago
|
this._saveAppConfig = this._saveAppConfig.bind(this);
|
||
8 years ago
|
this.exportWifKeysRaw = this.exportWifKeysRaw.bind(this);
|
||
8 years ago
|
this.toggleSeedInputVisibility = this.toggleSeedInputVisibility.bind(this);
|
||
8 years ago
|
}
|
||
|
|
||
|
componentDidMount() {
|
||
|
Store.dispatch(iguanaActiveHandle());
|
||
8 years ago
|
Store.dispatch(getAppConfig());
|
||
8 years ago
|
Store.dispatch(getAppInfo());
|
||
|
}
|
||
|
|
||
8 years ago
|
componentWillReceiveProps(props) {
|
||
|
if (this.state.tabElId) {
|
||
|
const _height = document.querySelector(`#${this.state.tabElId} .panel-collapse .panel-body`).offsetHeight;
|
||
|
|
||
|
this.setState(Object.assign({}, this.state, {
|
||
|
activeTab: this.state.activeTab,
|
||
|
activeTabHeight: _height,
|
||
|
tabElId: this.state.tabElId,
|
||
|
}));
|
||
|
}
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
toggleSeedInputVisibility() {
|
||
|
this.setState({
|
||
|
seedInputVisibility: !this.state.seedInputVisibility,
|
||
|
});
|
||
|
}
|
||
|
|
||
8 years ago
|
execCliCmd() {
|
||
8 years ago
|
Store.dispatch(shepherdCli('passthru', this.state.cliCoin, this.state.cliCmd));
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
8 years ago
|
openTab(elemId, tab) {
|
||
|
setTimeout(() => {
|
||
|
const _height = document.querySelector(`#${elemId} .panel-collapse .panel-body`).offsetHeight;
|
||
|
|
||
|
this.setState(Object.assign({}, this.state, {
|
||
|
activeTab: tab,
|
||
|
activeTabHeight: _height,
|
||
|
tabElId: elemId,
|
||
|
}));
|
||
|
}, 100);
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
exportWifKeys() {
|
||
8 years ago
|
Store.dispatch(encryptWallet(this.state.wifkeysPassphrase, settingsWifkeyState, this.props.ActiveCoin.coin));
|
||
|
}
|
||
|
|
||
8 years ago
|
importWifKey() {
|
||
|
Store.dispatch(importPrivKey(this.state.importWifKey));
|
||
|
}
|
||
|
|
||
|
readDebugLog() {
|
||
|
Store.dispatch(getDebugLog(this.state.debugTarget, this.state.debugLinesCount));
|
||
|
}
|
||
|
|
||
|
checkNodes() {
|
||
|
if (this.state.getPeersCoin) {
|
||
|
Store.dispatch(getPeersList(this.state.getPeersCoin.split('|')[0]));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
addNode() {
|
||
|
if (this.state.addNodeCoin) {
|
||
|
Store.dispatch(addPeerNode(this.state.addNodeCoin.split('|')[0], this.state.addPeerIP));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
renderPeersList() {
|
||
|
if (this.state.getPeersCoin) {
|
||
8 years ago
|
const _getPeersCoin = this.state.getPeersCoin;
|
||
|
const _rawPeers = this.props.Settings.rawPeers;
|
||
|
const coin = _getPeersCoin.split('|')[0];
|
||
|
|
||
|
if (_rawPeers &&
|
||
|
_getPeersCoin &&
|
||
|
_rawPeers[coin]) {
|
||
|
return _rawPeers[coin].map((ip) =>
|
||
8 years ago
|
<div key={ ip }>{ ip }</div>
|
||
|
);
|
||
8 years ago
|
} else {
|
||
|
return null;
|
||
|
}
|
||
|
} else {
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
|
||
8 years ago
|
renderAppInfoTab() {
|
||
|
const releaseInfo = this.props.Settings.appInfo && this.props.Settings.appInfo.releaseInfo;
|
||
|
|
||
|
if (releaseInfo) {
|
||
8 years ago
|
return AppInfoTabRender.call(this);
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
|
return null;
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
renderSNPeersList() {
|
||
|
if (this.state.getPeersCoin) {
|
||
8 years ago
|
const _getPeersCoin = this.state.getPeersCoin;
|
||
|
const _supernetPeers = this.props.Settings.supernetPeers;
|
||
|
const coin = _getPeersCoin.split('|')[0];
|
||
|
|
||
|
if (_supernetPeers &&
|
||
|
_getPeersCoin &&
|
||
|
_supernetPeers[coin]) {
|
||
|
return _supernetPeers[coin].map((ip) =>
|
||
8 years ago
|
<div key={ ip }>{ ip }</div>
|
||
|
);
|
||
8 years ago
|
} else {
|
||
|
return null;
|
||
|
}
|
||
|
} else {
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
|
||
8 years ago
|
updateInputSettings(e) {
|
||
|
let _appSettings = this.state.appSettings;
|
||
|
_appSettings[e.target.name] = e.target.value;
|
||
|
|
||
|
this.setState({
|
||
|
appSettings: _appSettings,
|
||
|
});
|
||
|
}
|
||
|
|
||
|
_saveAppConfig() {
|
||
|
const _appSettings = this.state.appSettings;
|
||
|
let _appSettingsPristine = Object.assign({}, this.props.Settings.appSettings);
|
||
|
|
||
|
for (let key in _appSettings) {
|
||
|
if (key.indexOf('__') === -1) {
|
||
|
_appSettingsPristine[key] = _appSettings[key];
|
||
|
} else {
|
||
|
const _nestedKey = key.split('__');
|
||
|
_appSettingsPristine[_nestedKey[0]][_nestedKey[1]] = _appSettings[key];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Store.dispatch(saveAppConfig(_appSettingsPristine));
|
||
|
}
|
||
|
|
||
8 years ago
|
renderConfigEditForm() {
|
||
|
let items = [];
|
||
|
const _appConfig = this.props.Settings.appSettings;
|
||
|
|
||
8 years ago
|
for (let key in _appConfig) {
|
||
|
if (typeof _appConfig[key] === 'object') {
|
||
8 years ago
|
items.push(
|
||
8 years ago
|
<tr key={ `app-settings-${key}` }>
|
||
8 years ago
|
<td className="padding-15">
|
||
8 years ago
|
{ key }
|
||
8 years ago
|
</td>
|
||
8 years ago
|
<td className="padding-15"></td>
|
||
8 years ago
|
</tr>
|
||
|
);
|
||
|
|
||
8 years ago
|
for (let _key in _appConfig[key]) {
|
||
8 years ago
|
items.push(
|
||
8 years ago
|
<tr key={ `app-settings-${key}-${_key}` }>
|
||
8 years ago
|
<td className="padding-15 padding-left-30">
|
||
8 years ago
|
{ _key }
|
||
8 years ago
|
</td>
|
||
8 years ago
|
<td className="padding-15">
|
||
8 years ago
|
<input
|
||
|
type="text"
|
||
|
name={ `${key}__${_key}` }
|
||
|
defaultValue={ _appConfig[key][_key] }
|
||
|
onChange={ this.updateInputSettings } />
|
||
8 years ago
|
</td>
|
||
|
</tr>
|
||
|
);
|
||
|
}
|
||
|
} else {
|
||
|
items.push(
|
||
8 years ago
|
<tr key={ `app-settings-${key}` }>
|
||
8 years ago
|
<td className="padding-15">
|
||
8 years ago
|
{ key }
|
||
8 years ago
|
</td>
|
||
8 years ago
|
<td className="padding-15">
|
||
8 years ago
|
<input
|
||
|
type="text"
|
||
|
name={ `${key}` }
|
||
|
defaultValue={ _appConfig[key] }
|
||
|
onChange={ this.updateInputSettings } />
|
||
8 years ago
|
</td>
|
||
|
</tr>
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return items;
|
||
|
}
|
||
|
|
||
8 years ago
|
updateInput(e) {
|
||
8 years ago
|
this.setState({
|
||
|
[e.target.name]: e.target.value,
|
||
|
});
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
renderDebugLogData() {
|
||
|
if (this.props.Settings.debugLog) {
|
||
|
const _debugLogDataRows = this.props.Settings.debugLog.split('\n');
|
||
|
|
||
|
if (_debugLogDataRows &&
|
||
|
_debugLogDataRows.length) {
|
||
|
return _debugLogDataRows.map((_row) =>
|
||
|
<div
|
||
|
key={ `settings-debuglog-${Math.random(0, 9) * 10}` }
|
||
|
className="padding-bottom-5">{ _row }</div>
|
||
|
);
|
||
|
} else {
|
||
|
return (
|
||
|
<span>{ translate('INDEX.EMPTY_DEBUG_LOG') }</span>
|
||
|
);
|
||
|
}
|
||
|
} else {
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
|
||
8 years ago
|
renderLB(_translationID) {
|
||
|
const _translationComponents = translate(_translationID).split('<br>');
|
||
|
|
||
|
return _translationComponents.map((_translation) =>
|
||
8 years ago
|
<span key={ `settings-label-${Math.random(0, 9) * 10}` }>
|
||
8 years ago
|
{ _translation }
|
||
8 years ago
|
<br />
|
||
|
</span>
|
||
|
);
|
||
|
}
|
||
|
|
||
8 years ago
|
renderCliResponse() {
|
||
8 years ago
|
const _cliResponse = this.props.Settings.cli;
|
||
|
|
||
|
if (_cliResponse) {
|
||
|
let _cliResponseParsed;
|
||
|
|
||
|
try {
|
||
|
_cliResponseParsed = JSON.parse(_cliResponse.result)
|
||
|
} catch(e) {
|
||
|
_cliResponseParsed = _cliResponse.result;
|
||
|
}
|
||
|
|
||
8 years ago
|
return (
|
||
8 years ago
|
<div>
|
||
|
<div>
|
||
|
<strong>CLI response:</strong>
|
||
|
</div>
|
||
|
{ JSON.stringify(_cliResponseParsed, null, '\t') }
|
||
|
</div>
|
||
8 years ago
|
);
|
||
|
} else {
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
|
||
8 years ago
|
renderActiveCoinsList(mode) {
|
||
|
const modes = [
|
||
|
'native',
|
||
|
'basilisk',
|
||
|
'full'
|
||
|
];
|
||
|
|
||
|
const allCoins = this.props.Main.coins;
|
||
|
let items = [];
|
||
|
|
||
|
if (allCoins) {
|
||
|
if (mode === 'all') {
|
||
|
modes.map(function(mode) {
|
||
|
allCoins[mode].map(function(coin) {
|
||
|
items.push(
|
||
|
<option value={ coin } key={ coin }>{ coin } ({ mode })</option>
|
||
|
);
|
||
|
});
|
||
|
});
|
||
|
} else {
|
||
|
allCoins[mode].map(function(coin) {
|
||
|
items.push(
|
||
|
<option value={ coin } key={ coin }>{ coin } ({ mode })</option>
|
||
|
);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
return items;
|
||
|
} else {
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
|
||
8 years ago
|
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;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
renderWifKeys() {
|
||
|
let items = [];
|
||
|
|
||
|
if (this.props.Settings.wifkey) {
|
||
|
const _wifKeys = this.props.Settings.wifkey;
|
||
|
|
||
|
for (let i = 0; i < 2; i++) {
|
||
|
items.push(
|
||
|
<tr key={ `wif-export-table-header-${i}` }>
|
||
|
<td className="padding-bottom-10 padding-top-10">
|
||
|
<strong>{ i === 0 ? 'Address list' : 'Wif key list' }</strong>
|
||
|
</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>{ _key }</td>
|
||
|
<td className="padding-left-15">{ _wifKeys[_key] }</td>
|
||
|
</tr>
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return items;
|
||
|
} else {
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
exportWifKeysRaw() {
|
||
|
this.setState(Object.assign({}, this.state, {
|
||
|
exportWifKeysRaw: !this.state.exportWifKeysRaw,
|
||
|
}));
|
||
|
}
|
||
|
|
||
8 years ago
|
render() {
|
||
8 years ago
|
return SettingsRender.call(this);
|
||
8 years ago
|
}
|
||
|
}
|
||
|
|
||
|
export default Settings;
|