From 72684f289824bc6d45b121f574622e1105848444 Mon Sep 17 00:00:00 2001 From: pbca26 Date: Thu, 16 Nov 2017 18:06:54 +0300 Subject: [PATCH] settings native wallet.dat fetch panel --- react/src/actions/actions/settings.js | 29 ++- .../settings/settings.daemonStdoutPanel.js | 2 +- .../settings.nativeWalletDatKeysPanel.js | 188 ++++++++++++++++++ .../dashboard/settings/settings.render.js | 10 + react/src/util/coinHelper.js | 27 +++ 5 files changed, 254 insertions(+), 2 deletions(-) create mode 100644 react/src/components/dashboard/settings/settings.nativeWalletDatKeysPanel.js diff --git a/react/src/actions/actions/settings.js b/react/src/actions/actions/settings.js index e7dc7fa..4532c12 100644 --- a/react/src/actions/actions/settings.js +++ b/react/src/actions/actions/settings.js @@ -396,7 +396,7 @@ export function coindGetStdout(chain) { method: 'GET', headers: { 'Content-Type': 'application/json', - } + }, }) .catch((error) => { console.log(error); @@ -414,3 +414,30 @@ export function coindGetStdout(chain) { }); }); } + +export function getWalletDatKeys(chain, keyMatchPattern) { + const _chain = chain === 'KMD' ? null : chain; + + return new Promise((resolve, reject) => { + fetch(keyMatchPattern ? `http://127.0.0.1:${Config.agamaPort}/shepherd/coindwalletkeys?chain=${_chain}&search=${keyMatchPattern}` : `http://127.0.0.1:${Config.agamaPort}/shepherd/coindwalletkeys?chain=${_chain}`, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + }) + .catch((error) => { + console.log(error); + dispatch( + triggerToaster( + 'getWalletDatKeys', + 'Error', + 'error' + ) + ); + }) + .then(response => response.json()) + .then(json => { + resolve(json); + }); + }); +} \ No newline at end of file diff --git a/react/src/components/dashboard/settings/settings.daemonStdoutPanel.js b/react/src/components/dashboard/settings/settings.daemonStdoutPanel.js index 3521a4c..3fbad63 100644 --- a/react/src/components/dashboard/settings/settings.daemonStdoutPanel.js +++ b/react/src/components/dashboard/settings/settings.daemonStdoutPanel.js @@ -51,7 +51,7 @@ class DaemonStdoutPanel extends React.Component { for (let i = 0; i < _nativeCoins.length; i++) { _items.push( ); } diff --git a/react/src/components/dashboard/settings/settings.nativeWalletDatKeysPanel.js b/react/src/components/dashboard/settings/settings.nativeWalletDatKeysPanel.js new file mode 100644 index 0000000..61de2f9 --- /dev/null +++ b/react/src/components/dashboard/settings/settings.nativeWalletDatKeysPanel.js @@ -0,0 +1,188 @@ +import React from 'react'; +import { translate } from '../../../translate/translate'; +import { connect } from 'react-redux'; +import { getWalletDatKeys } from '../../../actions/actionCreators'; +import { coindList } from '../../../util/coinHelper'; +import Store from '../../../store'; + +class NativeWalletDatKeysPanel extends React.Component { + constructor() { + super(); + this.state = { + coin: 'none', + keys: null, + keyMatchPattern: '', + loading: false, + }; + this._getWalletDatKeys = this._getWalletDatKeys.bind(this); + this.updateInput = this.updateInput.bind(this); + } + + componentWillReceiveProps(props) { + if (props.Dashboard && + props.Dashboard.activeSection !== 'settings') { + this.setState(Object.assign({}, this.state, { + keys: null, + keyMatchPattern: null, + })); + } + } + + _getWalletDatKeys() { + const _coin = this.state.coin; + + this.setState({ + loading: true, + keys: null, + }); + + setTimeout(() => { + getWalletDatKeys(_coin, this.state.keyMatchPattern.length ? this.state.keyMatchPattern : null) + .then((res) => { + this.setState({ + keys: res, + loading: false, + }); + + if (res.msg === 'success' && + res.result.length > 0) { + setTimeout(() => { + document.querySelector('#coind-keys-textarea-left').style.height = '1px'; + document.querySelector('#coind-keys-textarea-left').style.height = `${(15 + document.querySelector('#coind-keys-textarea-left').scrollHeight)}px`; + document.querySelector('#coind-keys-textarea-right').style.height = `${(15 + document.querySelector('#coind-keys-textarea-right').scrollHeight)}px`; + }, 100); + } + }); + }, 100); + } + + updateInput(e) { + this.setState({ + [e.target.name]: e.target.value, + }); + } + + renderCoinListSelectorOptions() { + let _items = []; + let _nativeCoins = coindList(); + + _items.push( + + ); + for (let i = 0; i < _nativeCoins.length; i++) { + _items.push( + + ); + } + + return _items; + } + + renderKeys() { + let _items = []; + + const _keys = this.state.keys; + + if (_keys.msg === 'error') { + return ( +
{ _keys.result }
+ ); + } else { + let _addresses = ''; + let _wifs = ''; + + for (let i = 0; i < _keys.result.length; i++) { + _addresses += _keys.result[i].pub + '\n'; + _wifs += _keys.result[i].priv + '\n'; + } + + return ( +
+
+ Found { _keys.result.length } keys +
+ { _keys.result.length > 0 && +
+
+ Address +
+ +
+ } + { _keys.result.length > 0 && +
+
+ WIF +
+ +
+ } +
+ ); + } + } + + render() { + return ( +
+
+
+
+
+ + + +
+
+
+ { this.state.keys && +
+
+
+ { this.renderKeys() } +
+
+ } +
+
+ ); + }; +} + +const mapStateToProps = (state) => { + return { + Dashboard: state.Dashboard, + }; +}; + +export default connect(mapStateToProps)(NativeWalletDatKeysPanel); \ No newline at end of file diff --git a/react/src/components/dashboard/settings/settings.render.js b/react/src/components/dashboard/settings/settings.render.js index 373bdae..eba640c 100644 --- a/react/src/components/dashboard/settings/settings.render.js +++ b/react/src/components/dashboard/settings/settings.render.js @@ -15,6 +15,7 @@ import ExportKeysPanel from './settings.exportKeysPanel'; import SupportPanel from './settings.supportPanel'; import SPVServersPanel from './settings.spvServersPanel'; import DaemonStdoutPanel from './settings.daemonStdoutPanel'; +import NativeWalletDatKeysPanel from './settings.nativeWalletDatKeysPanel'; // import WalletInfoPanel from './settings.walletInfoPanel'; // import WalletBackupPanel from './settings.walletBackupPanel'; @@ -104,6 +105,15 @@ export const SettingsRender = function() { } + { this.props.Main.coins && + this.props.Main.coins.native && + Object.keys(this.props.Main.coins.native).length > 0 && + + + + } { this.props.Main.coins && this.props.Main.coins.spv && Object.keys(this.props.Main.coins.spv).length && diff --git a/react/src/util/coinHelper.js b/react/src/util/coinHelper.js index 06f96c4..9b0d206 100644 --- a/react/src/util/coinHelper.js +++ b/react/src/util/coinHelper.js @@ -402,4 +402,31 @@ export function getModeInfo(mode) { tip: modetip, color: modecolor, }; +} + +export function coindList() { + const _coins = [ + 'KMD', + 'CHIPS', + 'BET', + 'BOTS', + 'CEAL', + 'COQUI', + 'CRYPTO', + 'HODL', + 'DEX', + 'JUMBLR', + 'KV', + 'MGW', + 'MVP', + 'MNZ', + 'PANGEA', + 'REVS', + 'SHARK', + 'MESH', + 'SUPERNET', + 'WLC', + ]; + + return _coins; } \ No newline at end of file