From a3dcbcc3065f9cb83e935ff6064a29504fcd7403 Mon Sep 17 00:00:00 2001 From: Petr Balashov Date: Tue, 6 Jun 2017 18:35:24 +0200 Subject: [PATCH] missing cli.js --- react/src/actions/actions/cli.js | 65 ++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 react/src/actions/actions/cli.js diff --git a/react/src/actions/actions/cli.js b/react/src/actions/actions/cli.js new file mode 100644 index 0000000..7cfe477 --- /dev/null +++ b/react/src/actions/actions/cli.js @@ -0,0 +1,65 @@ +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 => cliResponseState(json)) + } +} + +export function cliResponseState(json) { + console.log('cliResponseState', json); + return { + type: CLI, + data: json, + } +} \ No newline at end of file