From e9b967882c85674385b501a0d2e8b3e0e76bd429 Mon Sep 17 00:00:00 2001 From: pbca26 Date: Sun, 18 Jun 2017 16:05:43 +0300 Subject: [PATCH] send, get new addr rpc --- react/change.log | 5 +- react/src/actions/actions/addressBalance.js | 21 +++-- react/src/actions/actions/iguanaHelpers.js | 1 + react/src/actions/actions/nativeBalance.js | 6 +- react/src/actions/actions/nativeNewAddress.js | 47 ++++++++++-- react/src/actions/actions/nativeSend.js | 76 +++++++++++++++++-- react/src/actions/actions/nativeSyncInfo.js | 6 +- react/src/actions/actions/nativeTxHistory.js | 16 ++-- .../walletsNativeSend/walletsNativeSend.js | 4 +- .../walletsNativeSend.render.js | 44 ++++++----- 10 files changed, 168 insertions(+), 58 deletions(-) diff --git a/react/change.log b/react/change.log index 929b2c3..b78afb8 100644 --- a/react/change.log +++ b/react/change.log @@ -13,6 +13,9 @@ front: - swapped gettotalbalance interest with getinfo interest - extended settings / export keys ui - added error message if coin is already running in another mode +- added explicit "new address generated" message +- added cli / rpc passphru back: -- added cli route \ No newline at end of file +- added cli route +- rpc passphru \ No newline at end of file diff --git a/react/src/actions/actions/addressBalance.js b/react/src/actions/actions/addressBalance.js index 36205de..af2c2fe 100644 --- a/react/src/actions/actions/addressBalance.js +++ b/react/src/actions/actions/addressBalance.js @@ -131,7 +131,7 @@ export function getKMDAddressesNative(coin, mode, currentAddress) { body: JSON.stringify(payload), }; - if (Config.cli.default === true && + if (Config.cli.default && mode === 'native') { _fetchConfig = { method: 'POST', @@ -253,8 +253,19 @@ export function getKMDAddressesNative(coin, mode, currentAddress) { } } - let newAddressArray = []; + // remove addr duplicates + if (result[0]) { + result[0] = result[0].filter(function(elem, pos) { + return result[0].indexOf(elem) === pos; + }); + } + if (result[1]) { + result[1] = result[1].filter(function(elem, pos) { + return result[1].indexOf(elem) === pos; + }); + } + let newAddressArray = []; for (let a = 0; a < result.length; a++) { newAddressArray[a] = []; @@ -286,7 +297,7 @@ export function getKMDAddressesNative(coin, mode, currentAddress) { Promise.all(result[1].map((_address, index) => { return new Promise((resolve, reject) => { const _timestamp = Date.now(); - let ajaxDataToHex = `["${_address}"]`; + let ajaxDataToHex = `[\"${_address}\"]`; iguanaHashHex(ajaxDataToHex, dispatch) .then((hashHexJson) => { @@ -322,7 +333,7 @@ export function getKMDAddressesNative(coin, mode, currentAddress) { body: JSON.stringify(payload), }; - if (Config.cli.default === true && + if (Config.cli.default && mode === 'native') { payload = { mode: null, @@ -508,7 +519,7 @@ export function getKMDAddressesNative(coin, mode, currentAddress) { body: JSON.stringify(payload), }; - if (Config.cli.default === true && + if (Config.cli.default && mode === 'native') { payload = { mode: null, diff --git a/react/src/actions/actions/iguanaHelpers.js b/react/src/actions/actions/iguanaHelpers.js index 11179e3..8c5abf2 100644 --- a/react/src/actions/actions/iguanaHelpers.js +++ b/react/src/actions/actions/iguanaHelpers.js @@ -28,6 +28,7 @@ export function iguanaHashHex(data, dispatch) { }; return new Promise((resolve, reject) => { + // skip iguana hashing in cli mode if (Config.cli.default) { resolve(true); } else { diff --git a/react/src/actions/actions/nativeBalance.js b/react/src/actions/actions/nativeBalance.js index 56f604b..fc2612c 100644 --- a/react/src/actions/actions/nativeBalance.js +++ b/react/src/actions/actions/nativeBalance.js @@ -32,7 +32,7 @@ export function getKMDBalanceTotal(coin) { }; } - if (Config.cli.default === true) { + if (Config.cli.default) { payload = { mode: null, chain: coin, @@ -56,7 +56,7 @@ export function getKMDBalanceTotal(coin) { body: JSON.stringify(payload), }; - if (Config.cli.default === true) { + if (Config.cli.default) { _fetchConfig = { method: 'POST', headers: { @@ -103,6 +103,6 @@ export function getKMDBalanceTotal(coin) { export function getNativeBalancesState(json) { return { type: DASHBOARD_ACTIVE_COIN_NATIVE_BALANCE, - balance: json && !json.error ? (Config.cli.default === true ? json.result : json) : 0, + balance: json && !json.error ? (Config.cli.default ? json.result : json) : 0, } } \ No newline at end of file diff --git a/react/src/actions/actions/nativeNewAddress.js b/react/src/actions/actions/nativeNewAddress.js index c6ff35a..7bac1a8 100644 --- a/react/src/actions/actions/nativeNewAddress.js +++ b/react/src/actions/actions/nativeNewAddress.js @@ -10,13 +10,21 @@ import { guiLogState } from './log'; -function handleGetNewKMDAddresses(pubpriv, coin, dispatch) { - dispatch( +function handleGetNewKMDAddresses(pubpriv, coin, dispatch, json) { + /*dispatch( triggerToaster( translate('KMD_NATIVE.NEW_ADDR_GENERATED'), translate('TOASTR.WALLET_NOTIFICATION'), 'success' ) + );*/ + dispatch( + triggerToaster( + json.result ? json.result : json, + translate('KMD_NATIVE.NEW_ADDR_GENERATED'), + 'info', + false + ) ); dispatch(getKMDAddressesNative(coin)); @@ -45,7 +53,7 @@ export function getNewKMDAddresses(coin, pubpriv) { }; } else { payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'userpass': `tmpIgRPCUser@${sessionStorage.getItem('IguanaRPCAuth')}`, 'agent': coin, 'method': 'passthru', 'function': ajaxFunctionInput, @@ -59,15 +67,36 @@ export function getNewKMDAddresses(coin, pubpriv) { 'timestamp': _timestamp, 'function': 'getNewKMDAddresses', 'type': 'post', - 'url': `http://127.0.0.1:${Config.iguanaCorePort}`, + 'url': Config.cli.default ? `http://127.0.0.1:${Config.agamaPort}/shepherd/cli` : `http://127.0.0.1:${Config.iguanaCorePort}`, 'payload': payload, 'status': 'pending', })); - return fetch(`http://127.0.0.1:${Config.iguanaCorePort}`, { + let _fetchConfig = { method: 'POST', body: JSON.stringify(payload), - }) + }; + + if (Config.cli.default) { + payload = { + mode: null, + chain: coin, + cmd: payload.function + }; + + _fetchConfig = { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ 'payload': payload }), + }; + } + + return fetch( + Config.cli.default ? `http://127.0.0.1:${Config.agamaPort}/shepherd/cli` : `http://127.0.0.1:${Config.iguanaCorePort}`, + _fetchConfig + ) .catch(function(error) { console.log(error); dispatch(logGuiHttp({ @@ -85,6 +114,9 @@ export function getNewKMDAddresses(coin, pubpriv) { }) .then(response => response.json()) .then(json => { + if (Config.cli.default) { + json = json.result; + } dispatch(logGuiHttp({ 'timestamp': _timestamp, 'status': 'success', @@ -94,7 +126,8 @@ export function getNewKMDAddresses(coin, pubpriv) { handleGetNewKMDAddresses( pubpriv, coin, - dispatch + dispatch, + json ) ); }) diff --git a/react/src/actions/actions/nativeSend.js b/react/src/actions/actions/nativeSend.js index a0f0488..4e78805 100644 --- a/react/src/actions/actions/nativeSend.js +++ b/react/src/actions/actions/nativeSend.js @@ -51,15 +51,50 @@ export function sendNativeTx(coin, _payload) { 'timestamp': _timestamp, 'function': 'sendNativeTx', 'type': 'post', - 'url': `http://127.0.0.1:${Config.iguanaCorePort}`, + 'url': Config.cli.default ? `http://127.0.0.1:${Config.agamaPort}/shepherd/cli` : `http://127.0.0.1:${Config.iguanaCorePort}`, 'payload': payload, 'status': 'pending', })); - fetch(`http://127.0.0.1:${Config.iguanaCorePort}`, { + let _fetchConfig = { method: 'POST', body: JSON.stringify(payload), - }) + }; + + if (Config.cli.default) { + payload = { + mode: null, + chain: coin, + cmd: payload.function, + params: + _payload.addressType === 'public' && _payload.sendTo.length !== 95 ? + [ + _payload.sendTo, + _payload.amount + ] + : + [ + _payload.sendFrom, + [{ + address: _payload.sendTo, + amount: _payload.amount + }] + ] + }; + + _fetchConfig = { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ 'payload': payload }), + }; + } + + fetch( + Config.cli.default ? `http://127.0.0.1:${Config.agamaPort}/shepherd/cli` : `http://127.0.0.1:${Config.iguanaCorePort}`, + _fetchConfig + ) .catch(function(error) { console.log(error); dispatch(logGuiHttp({ @@ -102,9 +137,10 @@ export function sendNativeTx(coin, _payload) { dispatch( triggerToaster( true, - 'Your wallet.dat is not matching the blockchain. Please resync from the scratch.', translate('TOASTR.WALLET_NOTIFICATION'), - 'info' + 'Your wallet.dat is not matching the blockchain. Please resync from the scratch.', + 'info', + false ) ); } @@ -173,15 +209,36 @@ export function getKMDOPID(opid, coin) { 'timestamp': _timestamp, 'function': 'getKMDOPID', 'type': 'post', - 'url': `http://127.0.0.1:${Config.iguanaCorePort}`, + 'url': Config.cli.default ? `http://127.0.0.1:${Config.agamaPort}/shepherd/cli` : `http://127.0.0.1:${Config.iguanaCorePort}`, 'payload': payload, 'status': 'pending', })); - fetch(`http://127.0.0.1:${Config.iguanaCorePort}`, { + let _fetchConfig = { method: 'POST', body: JSON.stringify(payload), - }) + }; + + if (Config.cli.default) { + payload = { + mode: null, + chain: coin, + cmd: 'z_getoperationstatus' + }; + + _fetchConfig = { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ 'payload': payload }), + }; + } + + fetch( + Config.cli.default ? `http://127.0.0.1:${Config.agamaPort}/shepherd/cli` : `http://127.0.0.1:${Config.iguanaCorePort}`, + _fetchConfig + ) .catch(function(error) { console.log(error); dispatch(logGuiHttp({ @@ -199,6 +256,9 @@ export function getKMDOPID(opid, coin) { }) .then(response => response.json()) .then(json => { + if (Config.cli.default) { + json = json.result; + } dispatch(logGuiHttp({ 'timestamp': _timestamp, 'status': 'success', diff --git a/react/src/actions/actions/nativeSyncInfo.js b/react/src/actions/actions/nativeSyncInfo.js index 8065158..ee307ed 100644 --- a/react/src/actions/actions/nativeSyncInfo.js +++ b/react/src/actions/actions/nativeSyncInfo.js @@ -67,7 +67,7 @@ function getSyncInfoNativeState(json, coin, skipDebug) { } else { return { type: SYNCING_NATIVE_MODE, - progress: Config.cli.default === true ? json.result : json, + progress: Config.cli.default ? json.result : json, } } } @@ -82,7 +82,7 @@ export function getSyncInfoNative(coin, skipDebug) { 'hex': '', }; - if (Config.cli.default === true) { + if (Config.cli.default) { payload = { mode: null, chain: coin, @@ -105,7 +105,7 @@ export function getSyncInfoNative(coin, skipDebug) { body: JSON.stringify(payload), }; - if (Config.cli.default === true) { + if (Config.cli.default) { _fetchConfig = { method: 'POST', headers: { diff --git a/react/src/actions/actions/nativeTxHistory.js b/react/src/actions/actions/nativeTxHistory.js index cc585cd..c35c447 100644 --- a/react/src/actions/actions/nativeTxHistory.js +++ b/react/src/actions/actions/nativeTxHistory.js @@ -31,14 +31,6 @@ export function getNativeTxHistory(coin) { }; } - if (Config.cli.default === true) { - payload = { - mode: null, - chain: coin, - cmd: 'listtransactions' - }; - } - return dispatch => { const _timestamp = Date.now(); dispatch(logGuiHttp({ @@ -55,7 +47,13 @@ export function getNativeTxHistory(coin) { body: JSON.stringify(payload), }; - if (Config.cli.default === true) { + if (Config.cli.default) { + payload = { + mode: null, + chain: coin, + cmd: 'listtransactions' + }; + _fetchConfig = { method: 'POST', headers: { diff --git a/react/src/components/dashboard/walletsNativeSend/walletsNativeSend.js b/react/src/components/dashboard/walletsNativeSend/walletsNativeSend.js index db3080b..df08fb4 100644 --- a/react/src/components/dashboard/walletsNativeSend/walletsNativeSend.js +++ b/react/src/components/dashboard/walletsNativeSend/walletsNativeSend.js @@ -79,7 +79,7 @@ class WalletsNativeSend extends React.Component { if (this.state.sendFrom) { return ( - + [ { this.state.sendFromAmount } { this.props.ActiveCoin.coin } ]   { this.state.sendFrom } @@ -119,7 +119,7 @@ class WalletsNativeSend extends React.Component { return ( - +   { translate(`KMD_NATIVE.${_satatusDef[opid.status].label}`) } ); diff --git a/react/src/components/dashboard/walletsNativeSend/walletsNativeSend.render.js b/react/src/components/dashboard/walletsNativeSend/walletsNativeSend.render.js index c7a146e..de006e7 100644 --- a/react/src/components/dashboard/walletsNativeSend/walletsNativeSend.render.js +++ b/react/src/components/dashboard/walletsNativeSend/walletsNativeSend.render.js @@ -11,8 +11,8 @@ export const AddressListRender = function() { onClick={ this.openDropMenu }> { this.renderSelectorCurrentLabel() } - - + +
    @@ -115,7 +115,9 @@ export const WalletsNativeSendRender = function() {
    + htmlFor="kmdWalletFee"> + { translate('INDEX.FEE') } +
    - { translate('INDEX.TOTAL') }: - { this.state.amount } - { this.state.fee }/kb = { Number(this.state.amount) - Number(this.state.fee) } + { translate('INDEX.TOTAL') }: + { this.state.amount } - { this.state.fee }/kb = { Number(this.state.amount) - Number(this.state.fee) } { this.props.ActiveCoin.coin }
    @@ -155,30 +157,32 @@ export const WalletsNativeSendRender = function() {
    -

    { translate('INDEX.OPERATIONS_STATUSES') }

    +

    + { translate('INDEX.OPERATIONS_STATUSES') } +

    - - - - - - - + + + + + + + - { this.renderOPIDList() } + { this.renderOPIDList() } - - - - - - + + + + + +
    { translate('INDEX.STATUS') }ID{ translate('INDEX.TIME') }{ translate('INDEX.RESULT') }
    { translate('INDEX.STATUS') }ID{ translate('INDEX.TIME') }{ translate('INDEX.RESULT') }
    { translate('INDEX.STATUS') }ID{ translate('INDEX.TIME') }{ translate('INDEX.RESULT') }
    { translate('INDEX.STATUS') }ID{ translate('INDEX.TIME') }{ translate('INDEX.RESULT') }