Browse Source

Merge pull request #128 from SuperNETorg/cli

Settings CLI
all-modes
pbca26 7 years ago
committed by GitHub
parent
commit
59534c27f3
  1. 1
      react/src/actions/actionCreators.js
  2. 64
      react/src/actions/actions/cli.js
  3. 3
      react/src/actions/storeType.js
  4. 134
      react/src/components/dashboard/settings.js
  5. 8
      react/src/reducers/settings.js
  6. 7
      react/src/util/cacheFormat.js

1
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;

64
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,
}
}

3
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';
export const LOG_GUI_HTTP = 'LOG_GUI_HTTP';
export const CLI = 'CLI';

134
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 (
<div>
<div>
<strong>CLI response:</strong>
</div>
{ JSON.stringify(_cliResponseParsed, null, '\t') }
</div>
);
} 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(
<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;
}
}
render() {
return (
<div className="margin-left-0">
@ -676,7 +742,9 @@ class Settings extends React.Component {
onClick={ this.readDebugLog }>{ translate('INDEX.LOAD_DEBUG_LOG') }</button>
</div>
<div className="col-sm-12 col-xs-12 text-align-left">
<div className="padding-top-40 padding-bottom-20 horizontal-padding-0">{ this.renderDebugLogData() }</div>
<div className="padding-top-40 padding-bottom-20 horizontal-padding-0">
{ this.renderDebugLogData() }
</div>
</div>
</form>
</div>
@ -716,6 +784,68 @@ class Settings extends React.Component {
</div>
</div>
{ this.renderAppInfoTab() }
<div
className="panel"
id="Cli"
onClick={ () => this.openTab('Cli', 9) }>
<div className="panel-heading">
<a className={ this.state.activeTab === 9 ? 'panel-title' : 'panel-title collapsed' }>
<i className="icon fa-code"></i> CLI
</a>
</div>
<div
className={ this.state.activeTab === 9 ? 'panel-collapse collapse in' : 'panel-collapse collapse' }
style={{ height: this.state.activeTab === 9 ? this.state.activeTabHeight + 'px' : '0' }}>
<div className="panel-body">
<p>Select a coin and type in CLI compatible command</p>
<div className="col-sm-12"></div>
<form
className="execute-cli-cmd-form"
method="post"
action="javascript:"
autoComplete="off">
<div className="form-group form-material floating">
<select
className="form-control form-material"
name="cliCoin"
id="settingsCliOptions"
onChange={ this.updateInput }>
<option value="">Select coin</option>
{ this.renderActiveCoinsList('native') }
</select>
<label
className="floating-label"
htmlFor="settingsDelectDebugLogOptions">Coin</label>
</div>
<div className="form-group form-material floating">
<textarea
type="text"
className="form-control"
name="cliCmd"
id="cliCmd"
value={ this.state.cliCmdString }
onChange={ this.updateInput }></textarea>
<label
className="floating-label"
htmlFor="readDebugLogLines">Type in CLI compatible cmd</label>
</div>
<div className="col-sm-12 col-xs-12 text-align-center">
<button
type="button"
className="btn btn-primary waves-effect waves-light"
disabled={ !this.state.cliCoin || !this.state.cliCmd }
onClick={ () => this.execCliCmd() }>Execute</button>
</div>
<div className="col-sm-12 col-xs-12 text-align-left">
<div className="padding-top-40 padding-bottom-20 horizontal-padding-0">
{ this.renderCliResponse() }
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>

8
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;
}

7
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) {

Loading…
Cancel
Save