diff --git a/react/change.log b/react/change.log index fd505ef..b78afb8 100644 --- a/react/change.log +++ b/react/change.log @@ -12,6 +12,10 @@ front: - sort http stack history desc - 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 6efd174..af2c2fe 100644 --- a/react/src/actions/actions/addressBalance.js +++ b/react/src/actions/actions/addressBalance.js @@ -106,20 +106,46 @@ export function getKMDAddressesNative(coin, mode, currentAddress) { } }) } else { + if (Config.cli.default && + mode === 'native') { + payload = { + mode: null, + chain: coin, + cmd: payload.function, + params: [""] + }; + } + const _timestamp = Date.now(); dispatch(logGuiHttp({ 'timestamp': _timestamp, 'function': 'getKMDAddressesNative', '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 && + mode === 'native') { + _fetchConfig = { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ 'payload': payload }), + }; + } + + fetch( + Config.cli.default && mode === 'native' ? `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({ @@ -142,7 +168,7 @@ export function getKMDAddressesNative(coin, mode, currentAddress) { 'status': 'success', 'response': json, })); - resolve(json); + resolve(Config.cli.default && mode === 'native' ? json.result : json); }) } }); @@ -227,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] = []; @@ -260,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) => { @@ -286,16 +323,40 @@ export function getKMDAddressesNative(coin, mode, currentAddress) { 'timestamp': _timestamp, 'function': 'getKMDAddressesNative+ZBalance', '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 && + mode === 'native') { + payload = { + mode: null, + chain: coin, + cmd: 'z_getbalance', + params: [ + _address + ] + }; + + _fetchConfig = { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ 'payload': payload }), + }; + } + + fetch( + Config.cli.default && mode === 'native' ? `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({ @@ -329,6 +390,10 @@ export function getKMDAddressesNative(coin, mode, currentAddress) { ) ); } else { + if (Config.cli.default && + mode === 'native') { + json = json.result; + } resolve(json); newAddressArray[1][index] = { address: _address, @@ -449,10 +514,33 @@ export function getKMDAddressesNative(coin, mode, currentAddress) { 'status': 'pending', })); - fetch(`http://127.0.0.1:${(Config.useBasiliskInstance && mode === 'basilisk' ? Config.iguanaCorePort + 1 : Config.iguanaCorePort)}`, { + let _fetchConfig = { method: 'POST', body: JSON.stringify(payload), - }) + }; + + if (Config.cli.default && + mode === 'native') { + payload = { + mode: null, + chain: coin, + cmd: payload.function, + params: payload.params + }; + + _fetchConfig = { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ 'payload': payload }), + }; + } + + fetch( + Config.cli.default && mode === 'native' ? `http://127.0.0.1:${Config.agamaPort}/shepherd/cli` : `http://127.0.0.1:${(Config.useBasiliskInstance && mode === 'basilisk' ? Config.iguanaCorePort + 1 : Config.iguanaCorePort)}`, + _fetchConfig + ) .catch(function(error) { console.log(error); dispatch(logGuiHttp({ @@ -470,6 +558,10 @@ export function getKMDAddressesNative(coin, mode, currentAddress) { }) .then(response => response.json()) .then(function(json) { + if (Config.cli.default && + mode === 'native') { + json = json.result; + } dispatch(logGuiHttp({ 'timestamp': _timestamp, 'status': 'success', diff --git a/react/src/actions/actions/iguanaHelpers.js b/react/src/actions/actions/iguanaHelpers.js index f989c3b..8c5abf2 100644 --- a/react/src/actions/actions/iguanaHelpers.js +++ b/react/src/actions/actions/iguanaHelpers.js @@ -28,44 +28,49 @@ export function iguanaHashHex(data, dispatch) { }; return new Promise((resolve, reject) => { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'iguanaHashHex', - 'type': 'post', - 'url': `http://127.0.0.1:${Config.iguanaCorePort}`, - 'payload': payload, - 'status': 'pending', - })); - - fetch(`http://127.0.0.1:${Config.iguanaCorePort}`, { - method: 'POST', - body: JSON.stringify(payload), - }) - .catch(function(error) { - console.log(error); + // skip iguana hashing in cli mode + if (Config.cli.default) { + resolve(true); + } else { + const _timestamp = Date.now(); dispatch(logGuiHttp({ 'timestamp': _timestamp, - 'status': 'error', - 'response': error, + 'function': 'iguanaHashHex', + 'type': 'post', + 'url': `http://127.0.0.1:${Config.iguanaCorePort}`, + 'payload': payload, + 'status': 'pending', })); - dispatch( - triggerToaster( - 'iguanaHashHex', - 'Error', - 'error' - ) - ); - }) - .then(response => response.json()) - .then(json => { - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - resolve(json.hex); - }) + + 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( + 'iguanaHashHex', + 'Error', + 'error' + ) + ); + }) + .then(response => response.json()) + .then(json => { + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + resolve(json.hex); + }) + } }) } diff --git a/react/src/actions/actions/nativeBalance.js b/react/src/actions/actions/nativeBalance.js index 05dfe32..fc2612c 100644 --- a/react/src/actions/actions/nativeBalance.js +++ b/react/src/actions/actions/nativeBalance.js @@ -32,21 +32,44 @@ export function getKMDBalanceTotal(coin) { }; } + if (Config.cli.default) { + payload = { + mode: null, + chain: coin, + cmd: 'z_gettotalbalance' + }; + } + return dispatch => { const _timestamp = Date.now(); dispatch(logGuiHttp({ 'timestamp': _timestamp, 'function': 'getKMDBalanceTotal', '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) { + _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({ @@ -80,6 +103,6 @@ export function getKMDBalanceTotal(coin) { export function getNativeBalancesState(json) { return { type: DASHBOARD_ACTIVE_COIN_NATIVE_BALANCE, - balance: json && !json.error ? 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 898b15e..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({ @@ -77,7 +112,7 @@ export function sendNativeTx(coin, _payload) { }) .then(function(response) { const _response = response.text().then(function(text) { return text; }); - return response.json(); + return _response; }) .then(function(json) { dispatch(logGuiHttp({ @@ -86,15 +121,29 @@ export function sendNativeTx(coin, _payload) { 'response': json, })); - if (json.error && - json.error.toString().indexOf('code:') > -1) { + if (json.indexOf('"code":') > -1) { + const _message = json.substring(json.indexOf('"message":"') + 11, json.indexOf('"},"id":"jl777"')); + dispatch( triggerToaster( - 'Send failed', + true, + _message, translate('TOASTR.WALLET_NOTIFICATION'), 'error' ) ); + + if (json.indexOf('"code":-4') > -1) { + dispatch( + triggerToaster( + true, + translate('TOASTR.WALLET_NOTIFICATION'), + 'Your wallet.dat is not matching the blockchain. Please resync from the scratch.', + 'info', + false + ) + ); + } } else { dispatch( triggerToaster( @@ -160,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({ @@ -186,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 5459798..ee307ed 100644 --- a/react/src/actions/actions/nativeSyncInfo.js +++ b/react/src/actions/actions/nativeSyncInfo.js @@ -67,13 +67,13 @@ function getSyncInfoNativeState(json, coin, skipDebug) { } else { return { type: SYNCING_NATIVE_MODE, - progress: json, + progress: Config.cli.default ? json.result : json, } } } export function getSyncInfoNative(coin, skipDebug) { - const payload = { + let payload = { 'userpass': `tmpIgRPCUser@${sessionStorage.getItem('IguanaRPCAuth')}`, 'agent': getPassthruAgent(coin), 'method': 'passthru', @@ -82,21 +82,43 @@ export function getSyncInfoNative(coin, skipDebug) { 'hex': '', }; + if (Config.cli.default) { + payload = { + mode: null, + chain: coin, + cmd: 'getinfo' + }; + } + return dispatch => { const _timestamp = Date.now(); dispatch(logGuiHttp({ 'timestamp': _timestamp, 'function': 'getSyncInfo', '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) { + _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({ diff --git a/react/src/actions/actions/nativeTxHistory.js b/react/src/actions/actions/nativeTxHistory.js index 61896b0..c35c447 100644 --- a/react/src/actions/actions/nativeTxHistory.js +++ b/react/src/actions/actions/nativeTxHistory.js @@ -37,15 +37,36 @@ export function getNativeTxHistory(coin) { 'timestamp': _timestamp, 'function': 'getNativeTxHistory', '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: 'listtransactions' + }; + + _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({ diff --git a/react/src/components/dashboard/settings/settings.js b/react/src/components/dashboard/settings/settings.js index a15f9cc..44bea31 100644 --- a/react/src/components/dashboard/settings/settings.js +++ b/react/src/components/dashboard/settings/settings.js @@ -315,7 +315,7 @@ class Settings extends React.Component { let _cliResponseParsed; try { - _cliResponseParsed = JSON.parse(_cliResponse.result) + _cliResponseParsed = JSON.parse(_cliResponse.result); } catch(e) { _cliResponseParsed = _cliResponse.result; } 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() } - - + +