diff --git a/react/build.zip b/react/build.zip index 9246340..b145788 100644 Binary files a/react/build.zip and b/react/build.zip differ diff --git a/react/src/actions/actionCreators.js b/react/src/actions/actionCreators.js index 6f030a3..f30361e 100644 --- a/react/src/actions/actionCreators.js +++ b/react/src/actions/actionCreators.js @@ -39,6 +39,7 @@ export const DASHBOARD_ACTIVE_SECTION = 'DASHBOARD_ACTIVE_SECTION'; export const DASHBOARD_ACTIVE_TXINFO_MODAL = 'DASHBOARD_ACTIVE_TXINFO_MODAL'; export const DASHBOARD_ACTIVE_COIN_NATIVE_BALANCE = 'DASHBOARD_ACTIVE_COIN_NATIVE_BALANCE'; export const DASHBOARD_ACTIVE_COIN_NATIVE_TXHISTORY = 'DASHBOARD_ACTIVE_COIN_NATIVE_TXHISTORY'; +export const DASHBOARD_ACTIVE_COIN_NATIVE_OPIDS = 'DASHBOARD_ACTIVE_COIN_NATIVE_OPIDS'; export function toggleDashboardActiveSection(name) { return { @@ -48,8 +49,6 @@ export function toggleDashboardActiveSection(name) { } export function toggleDashboardTxInfoModal(display, txIndex) { - console.log('toggleTxInfoModal', txIndex); - return { type: DASHBOARD_ACTIVE_TXINFO_MODAL, showTransactionInfo: display, @@ -811,89 +810,146 @@ 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')); + 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 => { + // TODO: split into 2 functions + const passthru_agent = getPassthruAgent(coin), + tmpIguanaRPCAuth = 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'); + var payload; + + if (passthru_agent == 'iguana') { + payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': passthru_agent, + 'method': 'passthru', + 'asset': coin, + 'function': 'listunspent', + 'hex': '' + }; + } else { + payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': passthru_agent, + 'method': 'passthru', + 'function': 'listunspent', + 'hex': '' + }; + } + + 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) { + 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 < 2 && 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 < 2; a++) { + newAddressArray[a] = []; + + for (let b=0; b < result[a].length; b++) { + const 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] + })); + }) }) - .then(response => response.json()) - .then(json => dispatch(getKMDAddressesNativeState(json, dispatch))) } } -/*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 +1231,186 @@ 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)) + }) + } +} + +export function iguanaHashHex(data) { + const payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': 'hash', + 'method': 'hex', + 'message': data + }; + + return new Promise((resolve, reject) => { + fetch('http://127.0.0.1:' + Config.iguanaCorePort, { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(triggerToaster(true, 'iguanaHashHex', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => resolve(json.hex)) + }) +} + +export function sendNativeTx(coin, _payload) { + const ajax_data_to_hex = '["' + _payload.sendFrom + '",[{"address":"' + _payload.sendTo + '","amount":' + (Number(_payload.amount) - Number(_payload.fee)) + '}]]'; + var payload; + + return dispatch => { + return iguanaHashHex(ajax_data_to_hex).then((hashHexJson) => { + console.log('sendNativeTx', hashHexJson); + + if (getPassthruAgent(coin) == 'iguana') { + payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': getPassthruAgent(coin), + 'method': 'passthru', + 'asset': coin, + 'function': 'z_sendmany', + 'hex': hashHexJson + }; + } else { + payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': getPassthruAgent(coin), + 'method': 'passthru', + 'function': 'z_sendmany', + 'hex': hashHexJson + }; + } + + fetch('http://127.0.0.1:' + Config.iguanaCorePort, { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(triggerToaster(true, 'sendNativeTx', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => dispatch(triggerToaster(true, translate('TOASTR.TX_SENT_ALT'), translate('TOASTR.WALLET_NOTIFICATION'), 'success'))) + .catch(function(ex) { + dispatch(triggerToaster(true, translate('TOASTR.TX_SENT_ALT'), translate('TOASTR.WALLET_NOTIFICATION'), 'success')); + console.log('parsing failed', ex); + }) + }); + } +} + +export function getKMDOPIDState(json) { + return { + type: DASHBOARD_ACTIVE_COIN_NATIVE_OPIDS, + opids: json, + } +} + +export function getKMDOPID(opid, coin) { + var tmpopid_output = '', + ajax_data_to_hex; + + if ( opid === undefined ) { + ajax_data_to_hex = null; + } else { + ajax_data_to_hex = '["' + opid + '"]'; + } + + return dispatch => { + return iguanaHashHex(ajax_data_to_hex).then((hashHexJson) => { + if (hashHexJson === '5b226e756c6c225d00') { + hashHexJson = ''; + } + + var payload, + passthru_agent = getPassthruAgent(coin), + tmpIguanaRPCAuth = 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'); + + if (passthru_agent == 'iguana') { + payload = { + 'userpass': tmpIguanaRPCAuth, + 'agent': passthru_agent, + 'method': 'passthru', + 'asset': coin, + 'function': 'z_getoperationstatus', + 'hex': hashHexJson + }; + } else { + payload = { + 'userpass': tmpIguanaRPCAuth, + 'agent': passthru_agent, + 'method': 'passthru', + 'function': 'z_getoperationstatus', + 'hex': hashHexJson + }; + } + + fetch('http://127.0.0.1:' + Config.iguanaCorePort, { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(triggerToaster(true, 'getKMDOPID', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => dispatch(getKMDOPIDState(json))) + }) + } +} + /*function Shepherd_SendPendValue() { Shepherd_SysInfo().then(function(result){ var ram_data = formatBytes(result.totalmem_bytes) diff --git a/react/src/assets/images/cryptologo/GAME.png b/react/src/assets/images/cryptologo/GAME.png new file mode 100644 index 0000000..17ddaf4 Binary files /dev/null and b/react/src/assets/images/cryptologo/GAME.png differ diff --git a/react/src/components/dashboard/coinTileItem.js b/react/src/components/dashboard/coinTileItem.js index 3130125..2da45c3 100644 --- a/react/src/components/dashboard/coinTileItem.js +++ b/react/src/components/dashboard/coinTileItem.js @@ -11,7 +11,8 @@ import { getSyncInfoNative, getKMDBalanceTotal, getNativeTxHistory, - getKMDAddressesNative + getKMDAddressesNative, + getKMDOPID } from '../../actions/actionCreators'; import Store from '../../store'; @@ -38,7 +39,8 @@ 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)); + Store.dispatch(getKMDOPID(null, coin)); }, coin === 'KMD' ? 15000 : 3000); Store.dispatch(startInterval('sync', _iguanaActiveHandle)); } else { @@ -66,7 +68,7 @@ class CoinTileItem extends React.Component { {item.coinname} {item.modecode} -
{item.coinname} ({item.coinlogo})
+
{item.coinname} ({item.coinlogo.toUpperCase()})
diff --git a/react/src/components/dashboard/walletsNativeReceive.js b/react/src/components/dashboard/walletsNativeReceive.js index 7649309..0dc76c9 100644 --- a/react/src/components/dashboard/walletsNativeReceive.js +++ b/react/src/components/dashboard/walletsNativeReceive.js @@ -1,5 +1,9 @@ import React from 'react'; import { translate } from '../../translate/translate'; +import { getNewKMDAddresses, copyCoinAddress } from '../../actions/actionCreators'; +import Store from '../../store'; + +// TODO: add addr balance class WalletsNativeReceive extends React.Component { constructor(props) { @@ -16,17 +20,24 @@ class WalletsNativeReceive extends React.Component { })); } - renderAddressList() { - if (this.props.ActiveCoin.addresses && this.props.ActiveCoin.addresses.length) { - return this.props.ActiveCoin.addresses.map((address) => - + copyZAddress(address) { + Store.dispatch(copyCoinAddress(address)); + } + + renderAddressList(type) { + console.log(this.props.ActiveCoin.addresses[type]); + if (this.props.ActiveCoin.addresses[type] && this.props.ActiveCoin.addresses[type].length) { + return this.props.ActiveCoin.addresses[type].map((address) => + - - {translate('IAPI.PUBLIC_SM')} + + {type === 'public' ? translate('IAPI.PUBLIC_SM') : translate('KMD_NATIVE.PRIVATE')} +    + - {address} - + {type === 'public' ? address.address : address.address.substring(0, 34) + '...'} + {address.amount} ); @@ -35,6 +46,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 +67,12 @@ class WalletsNativeReceive extends React.Component {