import React from 'react'; import { translate } from '../../translate/translate'; import { iguanaActiveHandle, encryptWallet, settingsWifkeyState, importPrivKey, getDebugLog, getPeersList, addPeerNode, getAppConfig, saveAppConfig, getAppInfo } from '../../actions/actionCreators'; import Store from '../../store'; import AddCoinOptionsCrypto from '../addcoin/addcoinOptionsCrypto'; import AddCoinOptionsAC from '../addcoin/addcoinOptionsAC'; import AddCoinOptionsACFiat from '../addcoin/addcoinOptionsACFiat'; /* TODO: 1) pre-select active coin in add node tab 2) add fiat section 3) kickstart section 4) batch export/import wallet addresses */ class Settings extends React.Component { constructor(props) { super(props); this.state = { activeTab: 0, debugLinesCount: 10, debugTarget: 'iguana', activeTabHeight: '10px', appSettings: {}, }; this.exportWifKeys = this.exportWifKeys.bind(this); this.updateInput = this.updateInput.bind(this); this.updateInputSettings = this.updateInputSettings.bind(this); 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); this._saveAppConfig = this._saveAppConfig.bind(this); } componentDidMount() { Store.dispatch(iguanaActiveHandle()); Store.dispatch(getAppConfig()); Store.dispatch(getAppInfo()); } openTab(elemId, tab) { const _height = document.querySelector('#' + elemId + ' .panel-collapse .panel-body').offsetHeight; this.setState(Object.assign({}, this.state, { activeTab: tab, activeTabHeight: _height, })); } exportWifKeys() { Store.dispatch(encryptWallet(this.state.wifkeysPassphrase, settingsWifkeyState, this.props.ActiveCoin.coin)); } 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) { const coin = this.state.getPeersCoin.split('|')[0]; if (this.props.Settings.rawPeers && this.state.getPeersCoin && this.props.Settings.rawPeers[coin]) { return this.props.Settings.rawPeers[coin].map((ip) =>
{ ip }
); } else { return null; } } else { return null; } } renderAppInfoTab() { const releaseInfo = this.props.Settings.appInfo && this.props.Settings.appInfo.releaseInfo; if (releaseInfo) { return (
this.openTab('AppInfo', 8) }> { translate('SETTINGS.APP_INFO') }
{ translate('SETTINGS.APP_RELEASE') }
{ translate('SETTINGS.NAME') }: { this.props.Settings.appInfo.releaseInfo.name }
{ translate('SETTINGS.VERSION') }: { this.props.Settings.appInfo.releaseInfo.version }
{ translate('SETTINGS.APP_SESSION') }: { this.props.Settings.appInfo.appSession }
{ translate('SETTINGS.SYS_INFO') }
{ translate('SETTINGS.ARCH') }: { this.props.Settings.appInfo.sysInfo.arch }
{ translate('SETTINGS.OS_TYPE') }: { this.props.Settings.appInfo.sysInfo.os_type }
{ translate('SETTINGS.OS_PLATFORM') }: { this.props.Settings.appInfo.sysInfo.platform }
{ translate('SETTINGS.OS_RELEASE') }: { this.props.Settings.appInfo.sysInfo.os_release }
{ translate('SETTINGS.CPU') }: { this.props.Settings.appInfo.sysInfo.cpu }
{ translate('SETTINGS.CPU_CORES') }: { this.props.Settings.appInfo.sysInfo.cpu_cores }
{ translate('SETTINGS.MEM') }: { this.props.Settings.appInfo.sysInfo.totalmem_readable }
{ translate('SETTINGS.LOCATIONS') }
{ translate('SETTINGS.CACHE') }: { this.props.Settings.appInfo.dirs.cacheLocation }
{ translate('SETTINGS.CONFIG') }: { this.props.Settings.appInfo.dirs.configLocation }
Iguana { translate('SETTINGS.BIN') }: { this.props.Settings.appInfo.dirs.iguanaBin }
Iguana { translate('SETTINGS.DIR') }: { this.props.Settings.appInfo.dirs.iguanaDir }
Komodo { translate('SETTINGS.BIN') }: { this.props.Settings.appInfo.dirs.komododBin }
Komodo { translate('SETTINGS.DIR') }: { this.props.Settings.appInfo.dirs.komodoDir }
); } else { return null; } } renderSNPeersList() { if (this.state.getPeersCoin) { const coin = this.state.getPeersCoin.split('|')[0]; if (this.props.Settings.supernetPeers && this.state.getPeersCoin && this.props.Settings.supernetPeers[coin]) { return this.props.Settings.supernetPeers[coin].map((ip) =>
{ ip }
); } else { return null; } } else { return null; } } updateInputSettings(e) { let _appSettings = this.state.appSettings; _appSettings[e.target.name] = e.target.value; this.setState({ appSettings: _appSettings, }); console.log(this.state.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)); } renderConfigEditForm() { let items = []; const _appConfig = this.props.Settings.appSettings; for (let key in _appConfig) { if (typeof _appConfig[key] === 'object') { items.push( { key } ); for (let _key in _appConfig[key]) { items.push( { _key } ); } } else { items.push( { key } ); } } return items; } updateInput(e) { this.setState({ [e.target.name]: e.target.value, }); } renderLB(_translationID) { const _translationComponents = translate(_translationID).split('
'); return _translationComponents.map((_translation) => { _translation }
); } render() { return (

{ translate('INDEX.WALLET_SETTINGS') }

this.openTab('WalletInfo', 0) }> { translate('INDEX.WALLET_INFO') }
{ translate('INDEX.KEY') } { translate('INDEX.VALUE') }
pubkey
{ this.props.Main.activeHandle.pubkey }
btcpubkey
{ this.props.Main.activeHandle.btcpubkey }
rmd160
{ this.props.Main.activeHandle.rmd160 }
NXT
{ this.props.Main.activeHandle.NXT }
notary
{ this.props.Main.activeHandle.notary }
status
{ this.props.Main.activeHandle.status }
this.openTab('AddNodeforCoin', 1) }> { translate('INDEX.ADD_NODE') }

{ translate('INDEX.USE_THIS_SECTION') }

SuperNET Peers:

{ this.renderSNPeersList() }

Raw Peers:

{ this.renderPeersList() }

{ translate('INDEX.USE_THIS_SECTION_PEER') }

this.openTab('DumpWallet', 2) }> { translate('INDEX.WALLET_BACKUP') }
Wallet Backup section to be updated soon.
this.openTab('FiatCurrencySettings', 3) }> { translate('INDEX.FIAT_CURRENCY') }
Fiat currency settings section to be updated soon.
this.openTab('ExportKeys', 4) }> { translate('INDEX.EXPORT_KEYS') }

{ this.renderLB('INDEX.ONLY_ACTIVE_WIF_KEYS') }

{ translate('INDEX.PLEASE_KEEP_KEYS_SAFE') }

{ this.props.ActiveCoin.coin } { this.props.Settings.address }
{ this.props.ActiveCoin.coin }Wif { this.props.Settings.wifkey }
this.openTab('ImportKeys', 5) }> { translate('INDEX.IMPORT_KEYS') }

{ translate('INDEX.IMPORT_KEYS_DESC_P1') }

{ translate('INDEX.IMPORT_KEYS_DESC_P2') }

{ translate('INDEX.IMPORT_KEYS_DESC_P3') }

{ translate('INDEX.PLEASE_KEEP_KEYS_SAFE') }

this.openTab('DebugLog', 6) }> { translate('INDEX.DEBUG_LOG') }

{ translate('INDEX.DEBUG_LOG_DESC') }

{ this.props.Settings.debugLog }

{ translate('SETTINGS.CONFIG_RESTART_REQUIRED') }

{ this.renderConfigEditForm() }
{ this.renderAppInfoTab() }
); } } export default Settings;