From 0108e81c3933ab4adb14e73af176ef150021890c Mon Sep 17 00:00:00 2001 From: pbca26 Date: Mon, 5 Jun 2017 15:17:53 +0300 Subject: [PATCH] zaddr balance fix --- react/src/actions/actions/addressBalance.js | 85 +++++++++++++++++-- .../dashboard/walletsNativeBalance.js | 2 +- 2 files changed, 80 insertions(+), 7 deletions(-) diff --git a/react/src/actions/actions/addressBalance.js b/react/src/actions/actions/addressBalance.js index 3713e34..4a551c5 100644 --- a/react/src/actions/actions/addressBalance.js +++ b/react/src/actions/actions/addressBalance.js @@ -5,7 +5,8 @@ import { triggerToaster, Config, shepherdGroomPost, - getPassthruAgent + getPassthruAgent, + iguanaHashHex } from '../actionCreators'; import { logGuiHttp, @@ -171,7 +172,6 @@ export function getKMDAddressesNative(coin, mode, currentAddress) { }; } - // if api cache option is off if (mode === 'basilisk') { payload = { 'userpass': `tmpIgRPCUser@${sessionStorage.getItem('IguanaRPCAuth')}`, @@ -235,17 +235,90 @@ export function getKMDAddressesNative(coin, mode, currentAddress) { sum += filteredArray[i]; } + if (sum === 0 && + a === 1) { + + } + newAddressArray[a][b] = { address: result[a][b], amount: currentAddress === result[a][b] || mode === 'native' ? sum : 'N/A', + type: a === 0 ? 'public': 'private', }; } } - dispatch(getKMDAddressesNativeState({ - 'public': newAddressArray[0], - 'private': newAddressArray[1] - })); + // get zaddr balance + if (result[1] && + result[1].length) { + Promise.all(result[1].map((_address, index) => { + return new Promise((resolve, reject) => { + const _timestamp = Date.now(); + let ajaxDataToHex = `["${_address}"]`; + + iguanaHashHex(ajaxDataToHex, dispatch).then((hashHexJson) => { + if (getPassthruAgent(coin) === 'iguana') { + payload = { + 'userpass': `tmpIgRPCUser@${sessionStorage.getItem('IguanaRPCAuth')}`, + 'agent': getPassthruAgent(coin), + 'method': 'passthru', + 'asset': coin, + 'function': 'z_getbalance', + 'hex': hashHexJson, + }; + } else { + payload = { + 'userpass': `tmpIgRPCUser@${sessionStorage.getItem('IguanaRPCAuth')}`, + 'agent': getPassthruAgent(coin), + 'method': 'passthru', + 'function': 'z_getbalance', + 'hex': hashHexJson, + }; + } + + fetch(`http://127.0.0.1:${Config.iguanaCorePort}`, + { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(triggerToaster(true, 'getKMDAddressesNative+ZBalance', 'Error', 'error')); + }) + .then(response => response.json()) + .then(function(json) { + resolve(json); + newAddressArray[1][index] = { + address: _address, + amount: json, + type: 'private', + }; + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + }); + }); + }); + })) + .then(zresult => { + dispatch(getKMDAddressesNativeState({ + 'public': newAddressArray[0], + 'private': newAddressArray[1] + })); + }); + } else { + dispatch(getKMDAddressesNativeState({ + 'public': newAddressArray[0], + 'private': newAddressArray[1] + })); + } } if (mode === 'basilisk') { diff --git a/react/src/components/dashboard/walletsNativeBalance.js b/react/src/components/dashboard/walletsNativeBalance.js index cfaf44d..30d10f2 100644 --- a/react/src/components/dashboard/walletsNativeBalance.js +++ b/react/src/components/dashboard/walletsNativeBalance.js @@ -45,7 +45,7 @@ class WalletsNativeBalance extends React.Component {
{ translate('INDEX.INTEREST_EARNED') }
- { this.props.Dashboard.progress.interest ? this.props.Dashboard.progress.interest : '-' } + { this.props.Dashboard.progress && this.props.Dashboard.progress.interest ? this.props.Dashboard.progress.interest : '-' }