From 7a37401130e1d2f6a274ded8886ebc7327ac28fc Mon Sep 17 00:00:00 2001 From: pbca26 Date: Thu, 6 Apr 2017 20:17:32 +0300 Subject: [PATCH] added atomic explorer logic --- react/src/actions/actionCreators.js | 27 +- react/src/components/app/app.js | 1 + react/src/components/dashboard/atomic.js | 349 ++++++++++++++++++++++- react/src/reducers/atomic.js | 16 ++ react/src/reducers/index.js | 2 + 5 files changed, 386 insertions(+), 9 deletions(-) create mode 100644 react/src/reducers/atomic.js diff --git a/react/src/actions/actionCreators.js b/react/src/actions/actionCreators.js index 61706bb..997e12d 100644 --- a/react/src/actions/actionCreators.js +++ b/react/src/actions/actionCreators.js @@ -15,6 +15,14 @@ export const DASHBOARD_ACTIVE_COIN_BALANCE = 'DASHBOARD_ACTIVE_COIN_BALANCE'; export const DASHBOARD_ACTIVE_COIN_SEND_FORM = 'DASHBOARD_ACTIVE_COIN_SEND_FORM'; export const DASHBOARD_ACTIVE_COIN_RECEIVE_FORM = 'DASHBOARD_ACTIVE_COIN_RECEIVE_FORM'; export const DASHBOARD_ACTIVE_COIN_RESET_FORMS = 'DASHBOARD_ACTIVE_COIN_RESET_FORMS'; +export const ATOMIC = 'ATOMIC'; + +function atomicState(json) { + return { + type: ATOMIC, + response: json, + } +} function toggleSendCoinFormState(display) { return { @@ -25,8 +33,8 @@ function toggleSendCoinFormState(display) { function toggleReceiveCoinFormState(display) { return { - type: DASHBOARD_ACTIVE_COIN_SEND_FORM, - send: display, + type: DASHBOARD_ACTIVE_COIN_RECEIVE_FORM, + receive: display, } } @@ -405,6 +413,21 @@ export function iguanaEdexBalance(coin) { } } +export function atomic(payload) { + return dispatch => { + return fetch('http://127.0.0.1:7778', { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(triggerToaster(true, payload.method, 'Atomic explorer error', 'error')) + }) + .then(response => response.json()) + .then(json => dispatch(atomicState(json))); + } +} + /*function Shepherd_SysInfo() { return new Promise((resolve) => { $.ajax({ diff --git a/react/src/components/app/app.js b/react/src/components/app/app.js index 27dff68..d011c8d 100644 --- a/react/src/components/app/app.js +++ b/react/src/components/app/app.js @@ -10,6 +10,7 @@ function mapStateToProps(state) { Main: state.Main, Dashboard: state.Dashboard, ActiveCoin: state.ActiveCoin, + Atomic: state.Atomic, }; } diff --git a/react/src/components/dashboard/atomic.js b/react/src/components/dashboard/atomic.js index d87d7e1..88aa7e8 100644 --- a/react/src/components/dashboard/atomic.js +++ b/react/src/components/dashboard/atomic.js @@ -1,7 +1,7 @@ import React from 'react'; import { translate } from '../../translate/translate'; -/*import { dashboardChangeSection, toggleAddcoinModal, logout } from '../../actions/actionCreators'; -import Store from '../../store';*/ +import { atomic } from '../../actions/actionCreators'; +import Store from '../../store'; import AddCoinOptionsCrypto from '../addcoin/addcoinOptionsCrypto'; import AddCoinOptionsAC from '../addcoin/addcoinOptionsAC'; import AddCoinOptionsACFiat from '../addcoin/addcoinOptionsACFiat'; @@ -10,7 +10,342 @@ class Atomic extends React.Component { constructor(props) { super(props); this.state = { + output: null, + api: null, + coin: null, + input: null, }; + this.updateSelectedAPI = this.updateSelectedAPI.bind(this); + this.updateSelectedCoin = this.updateSelectedCoin.bind(this); + this.updateInput = this.updateInput.bind(this); + this.getAtomicData = this.getAtomicData.bind(this); + } + + updateSelectedAPI(e) { + this.setState(Object.assign({}, this.state, { + 'api': e.target.value, + })); + console.log('this', this.state); + } + + updateSelectedCoin(e) { + this.setState(Object.assign({}, this.state, { + 'coin': e.target.value.split('|')[0], + })); + console.log('this', this.state); + } + + updateInput(e) { + this.setState(Object.assign({}, this.state, { + 'input': e.target.value, + })); + console.log('this', this.state); + } + + getAtomicData() { + const tmpIguanaRPCAuth = 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'); + var ExplorerInputData; + + switch (this.state.api) { + case 'history': + ExplorerInputData = { + 'userpass': tmpIguanaRPCAuth, + 'timeout': 20000, + 'agent': 'basilisk', + 'method': 'history', + 'vals': { + 'coin': this.state.coin, + 'addresses': [ this.state.input ] + } + }; + break; + case 'getbalance': + ExplorerInputData = { + 'userpass': tmpIguanaRPCAuth, + 'coin': this.state.coin, + 'method': 'getbalance', + 'params': [ this.state.input ] + }; + break; + case 'listunspent': + ExplorerInputData = { + 'userpass': tmpIguanaRPCAuth, + 'coin': this.state.coin, + 'method': 'listunspent', + 'params': [ + 1, + 9999999, + [ this.state.input ] + ] + }; + break; + case 'txid': + ExplorerInputData = { + 'userpass': tmpIguanaRPCAuth, + 'coin': this.state.coin, + 'method': 'getrawtransaction', + 'params': [ this.state.input ] + }; + break; + case 'blockash': + ExplorerInputData = { + 'userpass': tmpIguanaRPCAuth, + 'coin': this.state.coin, + 'agent': 'bitcoinrpc', + 'method': 'getblockhash', + 'height': this.state.input + }; + break; + case 'chaintip': + ExplorerInputData = { + 'userpass': tmpIguanaRPCAuth, + 'coin': this.state.coin, + 'agent': 'bitcoinrpc', + 'method': 'getbestblockhash' + }; + break; + case 'activehandle': + ExplorerInputData = { + 'userpass': tmpIguanaRPCAuth, + 'agent': 'SuperNET', + 'method': 'activehandle' + }; + break; + case 'gettransaction': + ExplorerInputData = { + 'userpass': tmpIguanaRPCAuth, + 'coin': this.state.coin, + 'agent': 'bitcoinrpc', + 'method': 'gettransaction', + 'txid': this.state.input + }; + break; + case 'dex_getinfo': + ExplorerInputData = { + 'userpass': tmpIguanaRPCAuth, + 'agent': 'dex', + 'method': 'getinfo', + 'symbol': this.state.coin + }; + break; + case 'dex_getnotaries': + ExplorerInputData = { + 'userpass': tmpIguanaRPCAuth, + 'agent': 'dex', + 'method': 'getnotaries', + 'symbol': this.state.coin + }; + break; + case 'dex_alladdresses': + ExplorerInputData = { + 'userpass': tmpIguanaRPCAuth, + 'agent': 'dex', + 'method': 'alladdresses', + 'symbol': this.state.coin + }; + break; + case 'dex_importaddress': + ExplorerInputData = { + 'userpass': tmpIguanaRPCAuth, + 'agent': 'dex', + 'method': 'importaddress', + 'address': this.state.input, + 'symbol': this.state.coin + }; + break; + case 'dex_checkaddress': + ExplorerInputData = { + 'userpass': tmpIguanaRPCAuth, + 'agent': 'dex', + 'method': 'checkaddress', + 'ddress': this.state.input, + 'symbol': this.state.coin + }; + break; + case 'dex_validateaddress': + ExplorerInputData = { + 'userpass': tmpIguanaRPCAuth, + 'agent': 'dex', + 'method': 'validateaddress', + 'address': this.state.input, + 'symbol': this.state.coin + }; + break; + case 'dex_getbestblockhash': + ExplorerInputData = { + 'userpass': tmpIguanaRPCAuth, + 'agent': 'dex', + 'method': 'getbestblockhash', + 'symbol': this.state.coin + }; + break; + case 'dex_listtransactions': + ExplorerInputData = { + 'userpass': tmpIguanaRPCAuth, + 'agent': 'dex', + 'method': 'listtransactions', + 'address': this.state.input, + 'count': 100, + 'skip': 0, + 'symbol': this.state.coin + }; + break; + case 'dex_listtransactions2': + ExplorerInputData = { + 'userpass': tmpIguanaRPCAuth, + 'agent': 'dex', + 'method': 'listtransactions2', + 'address': this.state.input, + 'count': 100, + 'skip': 0, + 'symbol': this.state.coin + }; + break; + case 'dex_listunspent': + ExplorerInputData = { + 'userpass': tmpIguanaRPCAuth, + 'agent': 'dex', + 'method': 'listunspent', + 'address': this.state.input, + 'symbol': this.state.coin + }; + break; + case 'dex_listspent': + ExplorerInputData = { + 'userpass': tmpIguanaRPCAuth, + 'agent': 'dex', + 'method': 'listspent', + 'address': this.state.input, + 'symbol': this.state.coin + }; + break; + case 'dex_listunspent2': + ExplorerInputData = { + 'userpass': tmpIguanaRPCAuth, + 'agent': 'dex', + 'method': 'listunspent2', + 'address': this.state.input, + 'symbol': this.state.coin + }; + break; + case 'dex_getblockhash': + ExplorerInputData = { + 'userpass': tmpIguanaRPCAuth, + 'agent': 'dex', + 'method': 'getblockhash', + 'height': 100, + 'symbol': this.state.coin + }; + break; + case 'dex_getblock': + ExplorerInputData = { + 'userpass': tmpIguanaRPCAuth, + 'agent': 'dex', + 'method': 'getblock', + 'hash': this.state.input, + 'symbol': this.state.coin + }; + break; + case 'dex_gettxin': + ExplorerInputData = { + 'userpass': tmpIguanaRPCAuth, + 'agent': 'dex', + 'method': 'gettxin', + 'vout': 0, + 'txid': this.state.input, + 'symbol': this.state.coin + }; + break; + case 'dex_gettxout': + ExplorerInputData = { + 'userpass': tmpIguanaRPCAuth, + 'agent': 'dex', + 'method': 'gettxout', + 'vout': 0, + 'txid': this.state.input, + 'symbol': this.state.coin + }; + break; + case 'dex_gettransaction': + ExplorerInputData = { + 'userpass': tmpIguanaRPCAuth, + 'agent': 'dex', + 'method': 'gettransaction', + 'txid': this.state.input, + 'symbol': this.state.coin + }; + break; + case 'dex_getbalance': + ExplorerInputData = { + 'userpass': tmpIguanaRPCAuth, + 'agent': 'dex', + 'method': 'getbalance', + 'address': this.state.input, + 'symbol': this.state.coin + }; + break; + case 'dex_getsupply': + ExplorerInputData = { + 'userpass': tmpIguanaRPCAuth, + 'agent': 'dex', + 'method': 'getbalance', + 'address': '*', + 'symbol': this.state.coin, + 'timeout': 600000 + }; + break; + case 'dex_sendrawtransaction': + ExplorerInputData = { + 'userpass': tmpIguanaRPCAuth, + 'agent': 'dex', + 'method': 'sendrawtransaction', + 'signedtx': this.state.input, + 'symbol': this.state.coin + }; + break; + case 'basilisk_refresh': + ExplorerInputData = { + 'userpass': tmpIguanaRPCAuth, + 'agent': 'basilisk', + 'method': 'refresh', + 'address': this.state.input, + 'symbol': this.state.coin, + 'timeout': 600000 + }; + break; + case 'jumblr_status': + ExplorerInputData = { + 'userpass': tmpIguanaRPCAuth, + 'agent': 'jumblr', + 'method': 'status' + }; + break; + } + + Store.dispatch(atomic(ExplorerInputData)); + } + + componentWillReceiveProps(props) { + console.log('atomicprops', props.Atomic.response); + if (props && props.Atomic.response) { + if (this.state.api === 'txid' || + this.state.api === 'dex_getbestblockhash' || + this.state.api === 'dex_sendrawtransaction' || + this.state.api === 'dex_getblockhash') { + this.setState(Object.assign({}, this.state, { + 'output': props.Atomic.response, + })); + } else { + this.setState(Object.assign({}, this.state, { + 'output': JSON.stringify(props.Atomic.response, null, '\t'), + })); + } + + if (props.Atomic.response.error === 'less than required responses') { + console.log('error'); + //toastr.error(_lang[defaultLang].DASHBOARD.LESS_RESPONSES_REQ, _lang[defaultLang].DASHBOARD.BASILISC_NOTIFICATION) + } + } } render() { @@ -24,7 +359,7 @@ class Atomic extends React.Component {
- @@ -33,7 +368,7 @@ class Atomic extends React.Component {
- @@ -68,10 +403,10 @@ class Atomic extends React.Component {
- +
- +
@@ -83,7 +418,7 @@ class Atomic extends React.Component {
-

+                    
{this.state.output}
diff --git a/react/src/reducers/atomic.js b/react/src/reducers/atomic.js new file mode 100644 index 0000000..d352d36 --- /dev/null +++ b/react/src/reducers/atomic.js @@ -0,0 +1,16 @@ +import { ATOMIC } from '../actions/actionCreators' + +export function Atomic(state = { + response: null, +}, action) { + switch (action.type) { + case ATOMIC: + return Object.assign({}, state, { + response: action.response, + }); + default: + return state; + } +} + +export default Atomic; diff --git a/react/src/reducers/index.js b/react/src/reducers/index.js index 0379dfe..ca753aa 100644 --- a/react/src/reducers/index.js +++ b/react/src/reducers/index.js @@ -6,6 +6,7 @@ import { toaster } from './toaster'; import { Main } from './main'; import { Dashboard } from './dashboard'; import { ActiveCoin } from './activeCoin'; +import { Atomic } from './atomic'; const rootReducer = combineReducers({ AddCoin, @@ -13,6 +14,7 @@ const rootReducer = combineReducers({ Main, Dashboard, ActiveCoin, + Atomic, routing: routerReducer, });