From 96ad1336c15e8fb1d4a0ba25884954227e3edf39 Mon Sep 17 00:00:00 2001 From: pbca26 Date: Wed, 19 Apr 2017 20:52:42 +0300 Subject: [PATCH] basilisk main addr listtransactions --- react/src/actions/actionCreators.js | 155 ++++-------------- .../src/components/dashboard/coinTileItem.js | 15 +- .../src/components/dashboard/walletsTxInfo.js | 4 +- 3 files changed, 46 insertions(+), 128 deletions(-) diff --git a/react/src/actions/actionCreators.js b/react/src/actions/actionCreators.js index 6e5cf77..f922aa8 100644 --- a/react/src/actions/actionCreators.js +++ b/react/src/actions/actionCreators.js @@ -888,7 +888,7 @@ function getKMDAddressesNativeState(json) { } } -export function getKMDAddressesNative(coin, mode) { +export function getKMDAddressesNative(coin, mode, currentAddress) { const type = ['public', 'private']; if (mode !== 'native') { @@ -993,133 +993,17 @@ export function getKMDAddressesNative(coin, mode) { } // if api cache option is off -/*function Shepherd_GetBasiliskCache() { - return new Promise((resolve) => { - var parse_session_data = sessionStorage.getItem('IguanaActiveAccount'); - parse_session_data = JSON.parse(JSON.parse(parse_session_data)); - - var session_pubkey = parse_session_data.pubkey, - ajax_data = { 'pubkey': session_pubkey }; - - $.ajax({ - type: 'GET', - data: ajax_data, - url: 'http://127.0.0.1:17777/shepherd/cache', - contentType: 'application/json' // send as JSON - }) - .done(function(data) { - resolve(data); - data = JSON.parse(data); - - if (data.result === 'JSON parse error') { - Shepherd_GroomData_Delete() - .then(function(result) { - console.log('error reading cache, flushing...'); - }); - } - }); - }); -}*/ - if (mode === 'basilisk') { payload = { 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), 'agent': 'dex', 'method': 'listunspent', - 'address': 'RDbGxL8QYdEp8sMULaVZS2E6XThcTKT9Jd', + 'address': currentAddress, 'symbol': coin }; } - if (mode === 'basilisk') { - const _addressArray = mode === 'basilisk' ? result[0].result : result; - - Promise.all(_addressArray.map((_address, index) => { - console.log('addrlength', _addressArray.length); - return new Promise((resolve, reject) => { - console.log(_address); - resolve(_address); - }); - })) - .then(result => { - console.log('addrres', result); - - fetch('http://127.0.0.1:' + Config.iguanaCorePort, { - method: 'POST', - body: JSON.stringify(payload), - }) - .catch(function(error) { - console.log(error); - dispatch(triggerToaster(true, 'getKMDAddressesNative+Balance', 'Error', 'error')); - }) - .then(response => response.json()) - .then(function(json) { - console.log('getaddrjson', result[0]); - if (mode === 'full' || mode === 'basilisk') { - result[0] = result[0].result; - } - - if (mode !== 'basilisk') { - const allAddrArray = json.map(res => res.address).filter((x, i, a) => a.indexOf(x) == i); - for (let a=0; a < allAddrArray.length; a++) { - const filteredArray = json.filter(res => res.address === allAddrArray[a]).map(res => res.amount); - - let isNewAddr = true; - for (let x=0; x < result.length && isNewAddr; x++) { - for (let y=0; y < result[x].length && isNewAddr; y++) { - if (allAddrArray[a] === result[x][y]) { - isNewAddr = false; - } - } - } - - if (isNewAddr) { - if (allAddrArray[a].substring(0, 2) === 'zc' || allAddrArray[a].substring(0, 2) === 'zt') { - result[1][result[1].length] = allAddrArray[a]; - } else { - result[0][result[0].length] = allAddrArray[a]; - } - console.log('new addr ' + allAddrArray[a] + ' | ' + allAddrArray[a].substring(0, 2)); - } - } - } - - let newAddressArray = []; - - for (let a=0; a < result.length; a++) { - newAddressArray[a] = []; - - for (let b=0; b < result[a].length; b++) { - var filteredArray; - - if (mode === 'basilisk') { - filteredArray = json.map(res => res.amount); - } else { - filteredArray = json.filter(res => res.address === result[a][b]).map(res => res.amount); - } - - let sum = 0; - - for (let i=0; i < filteredArray.length; i++) { - sum += filteredArray[i]; - } - - newAddressArray[a][b] = { - address: result[a][b], - amount: sum, - }; - } - } - - dispatch(getKMDAddressesNativeState({ - 'public': newAddressArray[0], - 'private': newAddressArray[1] - })); - }) - }); - } - - /*fetch('http://127.0.0.1:' + Config.iguanaCorePort, { + fetch('http://127.0.0.1:' + Config.iguanaCorePort, { method: 'POST', body: JSON.stringify(payload), }) @@ -1129,7 +1013,6 @@ export function getKMDAddressesNative(coin, mode) { }) .then(response => response.json()) .then(function(json) { - console.log('getaddrjson', result[0]); if (mode === 'full' || mode === 'basilisk') { result[0] = result[0].result; } @@ -1181,7 +1064,7 @@ export function getKMDAddressesNative(coin, mode) { newAddressArray[a][b] = { address: result[a][b], - amount: sum, + amount: currentAddress === result[a][b] ? sum : 'N/A', }; } } @@ -1190,11 +1073,39 @@ export function getKMDAddressesNative(coin, mode) { 'public': newAddressArray[0], 'private': newAddressArray[1] })); - })*/ + }) }) } } +/*function Shepherd_GetBasiliskCache() { + return new Promise((resolve) => { + var parse_session_data = sessionStorage.getItem('IguanaActiveAccount'); + parse_session_data = JSON.parse(JSON.parse(parse_session_data)); + + var session_pubkey = parse_session_data.pubkey, + ajax_data = { 'pubkey': session_pubkey }; + + $.ajax({ + type: 'GET', + data: ajax_data, + url: 'http://127.0.0.1:17777/shepherd/cache', + contentType: 'application/json' // send as JSON + }) + .done(function(data) { + resolve(data); + data = JSON.parse(data); + + if (data.result === 'JSON parse error') { + Shepherd_GroomData_Delete() + .then(function(result) { + console.log('error reading cache, flushing...'); + }); + } + }); + }); +}*/ + function getDebugLogState(json) { const _data = json.result.replace('\n', '\r\n'); diff --git a/react/src/components/dashboard/coinTileItem.js b/react/src/components/dashboard/coinTileItem.js index 3a5f957..eb2b9e1 100644 --- a/react/src/components/dashboard/coinTileItem.js +++ b/react/src/components/dashboard/coinTileItem.js @@ -25,6 +25,11 @@ class CoinTileItem extends React.Component { }; } + // TODO: 1) cache native/full node data to file + // 2) limit amount of req per update e.g. list of addresses don't change too often + // 3) limit req in basilisk as much as possible incl. activehandle + // 4) add pending requests store + dashboardChangeActiveCoin(coin, mode) { if (coin !== this.props.ActiveCoin.coin) { Store.dispatch(stopInterval('sync', this.props.Interval.interval)); @@ -34,7 +39,7 @@ class CoinTileItem extends React.Component { var _iguanaActiveHandle = setInterval(function() { Store.dispatch(getSyncInfo(coin)); Store.dispatch(iguanaEdexBalance(coin, mode)); - Store.dispatch(getKMDAddressesNative(coin, mode));//getAddressesByAccount(coin)); + Store.dispatch(getKMDAddressesNative(coin, mode)); //getAddressesByAccount(coin)); Store.dispatch(getFullTransactionsList(coin)); }, 3000); Store.dispatch(startInterval('sync', _iguanaActiveHandle)); @@ -52,10 +57,12 @@ class CoinTileItem extends React.Component { } if (mode === 'basilisk') { var _iguanaActiveHandle = setInterval(function() { - Store.dispatch(getBasiliskTransactionsList(coin, 'RDbGxL8QYdEp8sMULaVZS2E6XThcTKT9Jd')); + if (this.props && this.props.Dashboard && this.props.Dashboard.activeHandle && this.props.Dashboard.activeHandle[coin]) { + Store.dispatch(getBasiliskTransactionsList(coin, this.props.Dashboard.activeHandle[coin])); + Store.dispatch(getKMDAddressesNative(coin, mode, this.props.Dashboard.activeHandle[coin])); + } Store.dispatch(iguanaEdexBalance(coin, mode)); - Store.dispatch(getKMDAddressesNative(coin, mode)); - }, 3000); + }.bind(this), 3000); Store.dispatch(startInterval('sync', _iguanaActiveHandle)); // basilisk } diff --git a/react/src/components/dashboard/walletsTxInfo.js b/react/src/components/dashboard/walletsTxInfo.js index 5ee6e53..28bf157 100644 --- a/react/src/components/dashboard/walletsTxInfo.js +++ b/react/src/components/dashboard/walletsTxInfo.js @@ -66,7 +66,7 @@ class WalletsTxInfo extends React.Component { category - {txInfo.category} + {txInfo.category || txInfo.type} @@ -84,7 +84,7 @@ class WalletsTxInfo extends React.Component { blocktime - {secondsToString(txInfo.blocktime)} + {secondsToString(txInfo.blocktime || txInfo.timestamp)}