diff --git a/react/src/actions/actionCreators.js b/react/src/actions/actionCreators.js index 56f1015..635788f 100644 --- a/react/src/actions/actionCreators.js +++ b/react/src/actions/actionCreators.js @@ -65,6 +65,7 @@ export * from './actions/dexCoins'; export * from './actions/fullTxHistory'; export * from './actions/basiliskTxHistory'; export * from './actions/iguanaHelpers'; +export * from './actions/cli'; export let Config; diff --git a/react/src/actions/actions/cli.js b/react/src/actions/actions/cli.js new file mode 100644 index 0000000..4ac228a --- /dev/null +++ b/react/src/actions/actions/cli.js @@ -0,0 +1,64 @@ +import { + triggerToaster, + Config +} from '../actionCreators'; +import { CLI } from '../storeType'; +import { + logGuiHttp, + guiLogState +} from './log'; + +export function shepherdCliPromise(mode, chain, cmd) { + const _payload = { + mode, + chain, + cmd + }; + + return new Promise((resolve, reject) => { + fetch(`http://127.0.0.1:${Config.agamaPort}/shepherd/cli`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ 'payload': _payload }), + }) + .catch(function(error) { + console.log(error); + dispatch(triggerToaster(true, 'shepherdCli', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => resolve(json)) + }); +} + +export function shepherdCli(mode, chain, cmd) { + const _payload = { + mode, + chain, + cmd + }; + + return dispatch => { + return fetch(`http://127.0.0.1:${Config.agamaPort}/shepherd/cli`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ 'payload': _payload }), + }) + .catch(function(error) { + console.log(error); + dispatch(triggerToaster(true, 'shepherdCli', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => dispatch(cliResponseState(json))) + } +} + +export function cliResponseState(json) { + return { + type: CLI, + data: json, + } +} \ No newline at end of file diff --git a/react/src/actions/storeType.js b/react/src/actions/storeType.js index dff833c..1b0527e 100644 --- a/react/src/actions/storeType.js +++ b/react/src/actions/storeType.js @@ -41,4 +41,5 @@ export const SAVE_APP_CONFIG = 'SAVE_APP_CONFIG'; export const SERVICE_ERROR = 'SERVICE_ERROR'; export const DASHBOARD_ACTIVE_ADDRESS = 'DASHBOARD_ACTIVE_ADDRESS'; export const LOAD_APP_INFO = 'LOAD_APP_INFO'; -export const LOG_GUI_HTTP = 'LOG_GUI_HTTP'; \ No newline at end of file +export const LOG_GUI_HTTP = 'LOG_GUI_HTTP'; +export const CLI = 'CLI'; \ No newline at end of file diff --git a/react/src/components/dashboard/settings.js b/react/src/components/dashboard/settings.js index 323d060..452b96b 100644 --- a/react/src/components/dashboard/settings.js +++ b/react/src/components/dashboard/settings.js @@ -10,7 +10,8 @@ import { addPeerNode, getAppConfig, saveAppConfig, - getAppInfo + getAppInfo, + shepherdCli } from '../../actions/actionCreators'; import Store from '../../store'; import AddCoinOptionsCrypto from '../addcoin/addcoinOptionsCrypto'; @@ -35,6 +36,9 @@ class Settings extends React.Component { activeTabHeight: '0', appSettings: {}, tabElId: null, + cliCmdString: null, + cliCoin: null, + cliResponse: null, }; this.exportWifKeys = this.exportWifKeys.bind(this); this.updateInput = this.updateInput.bind(this); @@ -66,6 +70,10 @@ class Settings extends React.Component { } } + execCliCmd() { + Store.dispatch(shepherdCli('passthru', this.state.cliCoin, this.state.cliCmd)); + } + openTab(elemId, tab) { setTimeout(() => { const _height = document.querySelector(`#${elemId} .panel-collapse .panel-body`).offsetHeight; @@ -340,6 +348,64 @@ class Settings extends React.Component { ); } + renderCliResponse() { + const _cliResponse = this.props.Settings.cli; + + if (_cliResponse) { + let _cliResponseParsed; + + try { + _cliResponseParsed = JSON.parse(_cliResponse.result) + } catch(e) { + _cliResponseParsed = _cliResponse.result; + } + + return ( +
+
+ CLI response: +
+ { JSON.stringify(_cliResponseParsed, null, '\t') } +
+ ); + } else { + return null; + } + } + + 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( + + ); + }); + }); + } else { + allCoins[mode].map(function(coin) { + items.push( + + ); + }); + } + + return items; + } else { + return null; + } + } + render() { return (
@@ -676,7 +742,9 @@ class Settings extends React.Component { onClick={ this.readDebugLog }>{ translate('INDEX.LOAD_DEBUG_LOG') }
-
{ this.renderDebugLogData() }
+
+ { this.renderDebugLogData() } +
@@ -716,6 +784,68 @@ class Settings extends React.Component { { this.renderAppInfoTab() } + +
this.openTab('Cli', 9) }> +
+ + CLI + +
+
+
+

Select a coin and type in CLI compatible command

+
+
+
+ + +
+
+ + +
+
+ +
+
+
+ { this.renderCliResponse() } +
+
+
+
+
+
diff --git a/react/src/reducers/settings.js b/react/src/reducers/settings.js index 2799e3d..133cd96 100644 --- a/react/src/reducers/settings.js +++ b/react/src/reducers/settings.js @@ -3,7 +3,8 @@ import { GET_PEERS_LIST, GET_DEBUG_LOG, LOAD_APP_CONFIG, - LOAD_APP_INFO + LOAD_APP_INFO, + CLI } from '../actions/storeType'; export function Settings(state = { @@ -12,6 +13,7 @@ export function Settings(state = { debugLog: null, appSettings: null, appInfo: null, + cli: null, }, action) { switch (action.type) { case GET_WIF_KEY: @@ -36,6 +38,10 @@ export function Settings(state = { return Object.assign({}, state, { appInfo: action.info, }); + case CLI: + return Object.assign({}, state, { + cli: action.data, + }); default: return state; } diff --git a/react/src/util/cacheFormat.js b/react/src/util/cacheFormat.js index 792d405..dd02e4f 100644 --- a/react/src/util/cacheFormat.js +++ b/react/src/util/cacheFormat.js @@ -5,23 +5,20 @@ export function edexGetTxIDList(getTxData) { getTxidList.push(getTxData[i].txid); } - console.log(getTxidList); - return getTxidList; } export function edexRemoveTXID(_obj, address, txidArray) { let txidToStr = ':' + txidArray.join(':') + ':'; - console.log(txidToStr); - if (_obj, _obj.basilisk) { if (Object.keys(_obj.basilisk).length === 0) { console.log('no coin nodes to parse'); } else { for (let key in _obj.basilisk) { for (let coinAddr in _obj.basilisk[key]) { - if (_obj.basilisk[key][coinAddr] !== 'addresses' && coinAddr === address) { + if (_obj.basilisk[key][coinAddr] !== 'addresses' && + coinAddr === address) { if (_obj.basilisk[key][coinAddr].refresh && _obj.basilisk[key][coinAddr].refresh.data && _obj.basilisk[key][coinAddr].refresh.data.length > 0) {