From 4ba4d6be0e82182055e6490a97d8eef446f5825b Mon Sep 17 00:00:00 2001 From: pbca26 Date: Fri, 14 Apr 2017 20:57:34 +0300 Subject: [PATCH] get both private and public native addr --- react/src/actions/actionCreators.js | 187 ++++++++++-------- .../src/components/dashboard/coinTileItem.js | 2 +- .../dashboard/walletsNativeReceive.js | 10 +- .../components/dashboard/walletsNativeSend.js | 44 ++++- .../dashboard/walletsNativeTxHistory.js | 1 + 5 files changed, 154 insertions(+), 90 deletions(-) diff --git a/react/src/actions/actionCreators.js b/react/src/actions/actionCreators.js index 6f030a3..da2be7e 100644 --- a/react/src/actions/actionCreators.js +++ b/react/src/actions/actionCreators.js @@ -48,8 +48,6 @@ export function toggleDashboardActiveSection(name) { } export function toggleDashboardTxInfoModal(display, txIndex) { - console.log('toggleTxInfoModal', txIndex); - return { type: DASHBOARD_ACTIVE_TXINFO_MODAL, showTransactionInfo: display, @@ -811,89 +809,65 @@ function getKMDAddressesNativeState(json) { } } -export function getKMDAddressesNative(coin, pubpriv) { - var payload, - ajax_data_to_hex = '', - ajax_function_input = '', - tmplistaddr_hex_input = '', - passthru_agent = getPassthruAgent(coin), - tmpIguanaRPCAuth = 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'); - - if ( pubpriv === 'public' ) { - ajax_function_input = 'getaddressesbyaccount'; - tmplistaddr_hex_input = '222200'; - } - if ( pubpriv === 'private' ) { - ajax_function_input = 'z_listaddresses'; - tmplistaddr_hex_input = ''; - } - - if (passthru_agent === 'iguana') { - payload = { - 'userpass': tmpIguanaRPCAuth, - 'agent': passthru_agent, - 'method': 'passthru', - 'asset': coin, - 'function': ajax_function_input, - 'hex': tmplistaddr_hex_input - }; - } else { - payload = { - 'userpass': tmpIguanaRPCAuth, - 'agent': passthru_agent, - 'method': 'passthru', - 'function': ajax_function_input, - 'hex': tmplistaddr_hex_input - }; - } +export function getKMDAddressesNative(coin) { + const type = ['public', 'private']; 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, 'getKMDAddressesNative', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => dispatch(getKMDAddressesNativeState(json, dispatch))) + Promise.all(type.map((_type, index) => { + return new Promise((resolve, reject) => { + var payload, + ajax_data_to_hex = '', + ajax_function_input = '', + tmplistaddr_hex_input = '', + passthru_agent = getPassthruAgent(coin), + tmpIguanaRPCAuth = 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'); + + if ( _type === 'public' ) { + ajax_function_input = 'getaddressesbyaccount'; + tmplistaddr_hex_input = '222200'; + } + if ( _type === 'private' ) { + ajax_function_input = 'z_listaddresses'; + tmplistaddr_hex_input = ''; + } + + if (passthru_agent === 'iguana') { + payload = { + 'userpass': tmpIguanaRPCAuth, + 'agent': passthru_agent, + 'method': 'passthru', + 'asset': coin, + 'function': ajax_function_input, + 'hex': tmplistaddr_hex_input + }; + } else { + payload = { + 'userpass': tmpIguanaRPCAuth, + 'agent': passthru_agent, + 'method': 'passthru', + 'function': ajax_function_input, + 'hex': tmplistaddr_hex_input + }; + } + + fetch('http://127.0.0.1:' + Config.iguanaCorePort, { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(triggerToaster(true, 'getKMDAddressesNative', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => resolve(json)) + }); + })) + .then(result => { + dispatch(getKMDAddressesNativeState(result[0].concat(result[1]))); + }); } } -/*function KMDListAddresses(pubpriv) { - NProgress.done(true); - NProgress.configure({ - template: templates.nprogressBar - }); - NProgress.start(); - - - - $.ajax({ - async: false, - type: 'POST', - data: JSON.stringify(ajax_data), - url: 'http://127.0.0.1:' + config.iguanaPort, - success: function(data, textStatus, jqXHR) { - var AjaxOutputData = JSON.parse(data); // Ajax output gets the whole list of unspent coin with addresses - result = AjaxOutputData; - }, - error: function(xhr, textStatus, error) { - console.log('failed getting Coin History.'); - console.log(xhr.statusText); - if ( xhr.readyState == 0 ) { - Iguana_ServiceUnavailable(); - } - console.log(textStatus); - console.log(error); - } - }); - - NProgress.done(); - return result; -}*/ - function getDebugLogState(json) { const _data = json.result.replace('\n', '\r\n'); @@ -1175,6 +1149,59 @@ export function getNativeTxHistoryState(json) { } } +function handleGetNewKMDAddresses(pubpriv, coin, dispatch) { + dispatch(triggerToaster(true, translate('KMD_NATIVE.NEW_ADDR_GENERATED'), translate('TOASTR.WALLET_NOTIFICATION'), 'success')); + dispatch(getKMDAddressesNative(coin)); + return {}; +} + +export function getNewKMDAddresses(coin, pubpriv) { + var payload, + ajax_function_input = ''; + + if ( pubpriv === 'public' ) { + ajax_function_input = 'getnewaddress'; + } + if ( pubpriv === 'private' ) { + ajax_function_input = 'z_getnewaddress'; + } + + if (getPassthruAgent(coin) === 'iguana') { + payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': getPassthruAgent(coin), + 'method': 'passthru', + 'asset': coin, + 'function': ajax_function_input, + 'hex': '' + }; + } else { + payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': coin, + 'method': 'passthru', + 'function': ajax_function_input, + 'hex': '' + }; + } + + 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, 'getNewKMDAddresses', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => dispatch(handleGetNewKMDAddresses(pubpriv, coin, dispatch))) + .catch(function(ex) { + dispatch(handleGetNewKMDAddresses(pubpriv, coin, dispatch)) + }) + } +} + /*function Shepherd_SendPendValue() { Shepherd_SysInfo().then(function(result){ var ram_data = formatBytes(result.totalmem_bytes) diff --git a/react/src/components/dashboard/coinTileItem.js b/react/src/components/dashboard/coinTileItem.js index 3130125..9e22621 100644 --- a/react/src/components/dashboard/coinTileItem.js +++ b/react/src/components/dashboard/coinTileItem.js @@ -38,7 +38,7 @@ class CoinTileItem extends React.Component { Store.dispatch(getSyncInfoNative(coin)); Store.dispatch(getKMDBalanceTotal(coin)); Store.dispatch(getNativeTxHistory(coin)); - Store.dispatch(getKMDAddressesNative(coin, 'public')); + Store.dispatch(getKMDAddressesNative(coin)); }, coin === 'KMD' ? 15000 : 3000); Store.dispatch(startInterval('sync', _iguanaActiveHandle)); } else { diff --git a/react/src/components/dashboard/walletsNativeReceive.js b/react/src/components/dashboard/walletsNativeReceive.js index 7649309..ead95f5 100644 --- a/react/src/components/dashboard/walletsNativeReceive.js +++ b/react/src/components/dashboard/walletsNativeReceive.js @@ -1,5 +1,7 @@ import React from 'react'; import { translate } from '../../translate/translate'; +import { getNewKMDAddresses } from '../../actions/actionCreators'; +import Store from '../../store'; class WalletsNativeReceive extends React.Component { constructor(props) { @@ -35,6 +37,10 @@ class WalletsNativeReceive extends React.Component { } } + getNewAddress(type) { + Store.dispatch(getNewKMDAddresses(this.props.ActiveCoin.coin, type)); + } + render() { if (this.props && this.props.ActiveCoin && this.props.ActiveCoin.nativeActiveSection === 'receive') { return ( @@ -52,12 +58,12 @@ class WalletsNativeReceive extends React.Component {