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 agama config section 3) add fiat section 4) kickstart section */ 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.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); } componentDidMount() { Store.dispatch(iguanaActiveHandle()); Store.dispatch(getAppConfig()); Store.dispatch(getAppInfo()); } _saveAppConfig() { Store.dispatch(saveAppConfig); } openTab(elemId, tab) { const _height = document.querySelector('#' + elemId + ' .panel-collapse .panel-body').clientHeight; 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)}> App Info
App Release
Name: {this.props.Settings.appInfo.releaseInfo.name}
Version: {this.props.Settings.appInfo.releaseInfo.version}
System Info
Architecture: {this.props.Settings.appInfo.sysInfo.arch}
OS Type: {this.props.Settings.appInfo.sysInfo.os_type}
OS Platfrom: {this.props.Settings.appInfo.sysInfo.platform}
OS Release: {this.props.Settings.appInfo.sysInfo.os_release}
CPU: {this.props.Settings.appInfo.sysInfo.cpu}
CPU Cores: {this.props.Settings.appInfo.sysInfo.cpu_cores}
Memory: {this.props.Settings.appInfo.sysInfo.totalmem_readable}
Locations
Cache: {this.props.Settings.appInfo.dirs.cacheLocation}
Config: {this.props.Settings.appInfo.dirs.configLocation}
Iguana Bin: {this.props.Settings.appInfo.dirs.iguanaBin}
Iguana Dir: {this.props.Settings.appInfo.dirs.iguanaDir}
Komodo Bin: {this.props.Settings.appInfo.dirs.komododBin}
Komodo 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; } } renderConfigEditForm() { console.log(this.props.Settings.appSettings); let items = []; const _appConfig = this.props.Settings.appSettings; for (let key in this.props.Settings.appSettings) { if (Object.keys(this.props.Settings.appSettings[key]).length && key !== 'host') { items.push( {key} ); for (let _key in this.props.Settings.appSettings[key]) { items.push( {_key} ); } } else { items.push( {key} ); } } return items; } updateInput(e) { this.setState({ [e.target.name]: e.target.value, }); } 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')}

{translate('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}
this.openTab('AppSettings', 7)}> App Config (config.json)

Manage app config

Most changes to app config require wallet restart!

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