Browse Source

sockets fetching update (wip)

all-modes
pbca26 8 years ago
parent
commit
d6cea26d30
  1. 2
      react/package.json
  2. 42
      react/src/actions/actionCreators.js
  3. 14
      react/src/components/dashboard/receiveCoin.js
  4. 27
      react/src/components/dashboard/walletsData.js

2
react/package.json

@ -48,6 +48,7 @@
"redux": "^3.6.0",
"redux-logger": "^2.8.2",
"redux-thunk": "^2.2.0",
"socket.io-react": "^1.1.2",
"url-loader": "^0.5.7",
"whatwg-fetch": "^2.0.3"
},
@ -89,6 +90,7 @@
"react-test-renderer": "^15.4.2",
"redux-devtools": "^3.3.2",
"sass-loader": "^5.0.1",
"socket.io-client": "^1.7.3",
"style-loader": "^0.13.0",
"url-loader": "^0.5.7",
"webpack": "^2.2.1",

42
react/src/actions/actionCreators.js

@ -1392,7 +1392,7 @@ export function getNativeTxHistoryState(json) {
json = json.result;
} else if (!json.length) {
json = 'no data';
}
}
return {
type: DASHBOARD_ACTIVE_COIN_NATIVE_TXHISTORY,
@ -1663,6 +1663,46 @@ export function checkAddressBasilisk(coin, address) {
}
}
function validateAddressBasiliskHandle(json) {
return dispatch => {
if (json.iswatchonly === true) {
dispatch(triggerToaster(true, translate('TOASTR.VALIDATION_SUCCESS'), translate('TOASTR.BASILISK_NOTIFICATION'), 'error'));
}
if (json.iswatchonly === false) {
dispatch(triggerToaster(true, translate('TOASTR.ADDR_ISNT_REG'), translate('TOASTR.BASILISK_NOTIFICATION'), 'error'));
}
if (json.iswatchonly === undefined) {
dispatch(triggerToaster(true, translate('TOASTR.INVALID_QUERY_ALT'), translate('TOASTR.BASILISK_NOTIFICATION'), 'error'));
}
if (json.error === 'less than required responses') {
dispatch(triggerToaster(true, translate('TOASTR.LESS_RESPONSES_REQ'), translate('TOASTR.BASILISK_NOTIFICATION'), 'error'));
}
}
}
export function validateAddressBasilisk(coin, address) {
const payload = {
'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'),
'agent': 'dex',
'method': 'validateaddress',
'address': address,
'symbol': coin
};
return dispatch => {
return fetch('http://127.0.0.1:' + Config.iguanaCorePort, {
method: 'POST',
body: JSON.stringify(payload),
})
.catch(function(error) {
console.log(error);
dispatch(triggerToaster(true, 'validateAddressBasilisk', 'Error', 'error'));
})
.then(response => response.json())
.then(json => dispatch(validateAddressBasiliskHandle(json)))
}
}
/*function Shepherd_SendPendValue() {
Shepherd_SysInfo().then(function(result){
var ram_data = formatBytes(result.totalmem_bytes)

14
react/src/components/dashboard/receiveCoin.js

@ -1,10 +1,9 @@
import React from 'react';
import { translate } from '../../translate/translate';
import { checkAddressBasilisk, importAddressBasilisk } from '../../actions/actionCreators';
import { checkAddressBasilisk, importAddressBasilisk, validateAddressBasilisk } from '../../actions/actionCreators';
import Store from '../../store';
// TODO: implement sorting
// TODO: add import address ui in basilisk
// TODO: fallback to localstorage/stores data in case iguana is taking too long to respond
class ReceiveCoin extends React.Component {
@ -12,10 +11,14 @@ class ReceiveCoin extends React.Component {
super(props);
}
checkAddressBasilisk(address) {
_checkAddressBasilisk(address) {
Store.dispatch(checkAddressBasilisk(this.props.coin, address));
}
_validateAddressBasilisk(address) {
Store.dispatch(validateAddressBasilisk(this.props.coin, address));
}
/*importAddressBasilisk(address) {
Store.dispatch(importAddressBasilisk(this.props.coin, address));
}
@ -30,9 +33,12 @@ class ReceiveCoin extends React.Component {
<span className="label label-default">
<i className="icon fa-eye"></i> {translate('IAPI.PUBLIC_SM')}
</span>
<span className="label label-default margin-left-10 action" title="Check" onClick={() => this.checkAddressBasilisk(address)}>
<span className="label label-default margin-left-10 action" title="Check" onClick={() => this._checkAddressBasilisk(address)}>
<i className="icon fa-database"></i>
</span>
<span className="label label-default margin-left-10 action" title="Import" onClick={() => this._validateAddressBasilisk(address)}>
<i className="icon fa-info-circle"></i>
</span>
</td>
);
} else {

27
react/src/components/dashboard/walletsData.js

@ -11,6 +11,11 @@ import {
} from '../../actions/actionCreators';
import Store from '../../store';
import { SocketProvider } from 'socket.io-react';
import io from 'socket.io-client';
const socket = io.connect('http://localhost:17777');
class WalletsData extends React.Component {
constructor(props) {
super(props);
@ -21,6 +26,8 @@ class WalletsData extends React.Component {
itemsList: null,
currentAddress: null,
addressSelectorOpen: false,
currentStackLength: 0,
totalStackLength: 0,
};
this.updateInput = this.updateInput.bind(this);
this.toggleBasiliskActionsMenu = this.toggleBasiliskActionsMenu.bind(this);
@ -29,6 +36,25 @@ class WalletsData extends React.Component {
this.getDexNotariesAction = this.getDexNotariesAction.bind(this);
this.openDropMenu = this.openDropMenu.bind(this);
this.refreshTxList = this.refreshTxList.bind(this);
socket.on('messages', msg => this.updateSocketsData(msg));
}
updateSocketsData(data) {
console.log(data);
if (data && data.message && data.message.shepherd.iguanaAPI && data.message.shepherd.iguanaAPI.totalStackLength) {
this.setState(Object.assign({}, this.state, {
totalStackLength: data.message.shepherd.iguanaAPI.totalStackLength,
}));
}
if (data && data.message && data.message.shepherd.iguanaAPI && data.message.shepherd.iguanaAPI.currentStackLength) {
this.setState(Object.assign({}, this.state, {
currentStackLength: data.message.shepherd.iguanaAPI.currentStackLength,
}));
}
if (data && data.message && data.message.shepherd.method && data.message.shepherd.method === 'cache-one' && data.message.shepherd.status === 'done') {
//_totalStackLength = _currentStackLength = 0;
}
}
toggleBasiliskActionsMenu() {
@ -304,6 +330,7 @@ class WalletsData extends React.Component {
<div className="col-xlg-12 col-lg-12 col-sm-12 col-xs-12 edexcoin_dashoard_section_main_div">
<div id="edexcoin_txhistory" className="panel">
<header className="panel-heading" style={{zIndex: '10'}}>
Sockets: {this.state.currentStackLength} / {this.state.totalStackLength}
<div className={this.props.ActiveCoin.mode === 'basilisk' ? 'panel-actions' : 'panel-actions hide'}>
<a href="javascript:void(0)" className="dropdown-toggle white btn-xs btn-info btn_refresh_edexcoin_dashboard" data-edexcoin="COIN" aria-expanded="false" role="button" onClick={this.refreshTxList}>
<i className="icon fa-refresh margin-right-10" aria-hidden="true"></i> {translate('INDEX.REFRESH')}

Loading…
Cancel
Save