Browse Source

added atomic explorer logic

all-modes
pbca26 8 years ago
parent
commit
7a37401130
  1. 27
      react/src/actions/actionCreators.js
  2. 1
      react/src/components/app/app.js
  3. 349
      react/src/components/dashboard/atomic.js
  4. 16
      react/src/reducers/atomic.js
  5. 2
      react/src/reducers/index.js

27
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({

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

349
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 {
<div className="panel-body">
<div className="col-sm-4 col-xs-12">
<div className="form-group">
<select className="form-control form-material" id="atomic_explorer_select_coin_options">
<select className="form-control form-material" id="atomic_explorer_select_coin_options" onChange={this.updateSelectedCoin}>
<option value="-">{translate('INDEX.SELECT_COIN')}</option>
<AddCoinOptionsCrypto />
<AddCoinOptionsAC />
@ -33,7 +368,7 @@ class Atomic extends React.Component {
</div>
</div>
<div className="col-sm-4 col-xs-12" style={{textAlign: 'center'}}>
<select className="form-control form-material" id="atomic_explorer_select_command_options">
<select className="form-control form-material" id="atomic_explorer_select_command_options" onChange={this.updateSelectedAPI}>
<option value="">-Select Command-</option>
<option value="history">Address History</option>
<option value="getbalance">Get Balance</option>
@ -68,10 +403,10 @@ class Atomic extends React.Component {
</select>
</div>
<div className="col-sm-4 col-xs-12" style={{textAlign: 'center'}}>
<input type="text" className="form-control" id="atomic_explorer_input_data" name="atomic_explorer_input_data" placeholder="addr, txid, blockash etc." />
<input type="text" className="form-control" id="atomic_explorer_input_data" name="atomic_explorer_input_data" placeholder="addr, txid, blockash etc." onChange={this.updateInput} />
</div>
<div className="col-sm-12 col-xs-12" style={{textAlign: 'center'}}>
<button type="button" className="btn btn-primary waves-effect waves-light" data-toggle="modal" data-dismiss="modal" id="atomic_explorer_getcoinpeers_btn">Submit</button>
<button type="button" className="btn btn-primary waves-effect waves-light" data-toggle="modal" data-dismiss="modal" id="atomic_explorer_getcoinpeers_btn" onClick={this.getAtomicData}>Submit</button>
</div>
</div>
</div>
@ -83,7 +418,7 @@ class Atomic extends React.Component {
</div>
<div className="panel-body">
<div className="tab-content">
<pre id="atomic-explorer-commands-output"></pre>
<pre id="atomic-explorer-commands-output">{this.state.output}</pre>
</div>
</div>
</div>

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

2
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,
});

Loading…
Cancel
Save