From 6a9fdae00b44fa4813c059ec796a67cb85fa6458 Mon Sep 17 00:00:00 2001 From: Petr Balashov Date: Tue, 2 May 2017 15:16:42 +0200 Subject: [PATCH] dex send raw tx --- react/src/actions/actionCreators.js | 55 +++++++++++++++---- react/src/components/addcoin/addcoin.js | 13 +---- react/src/components/dashboard/sendCoin.js | 42 ++++++++++---- .../components/dashboard/walletsBalance.js | 15 +++-- 4 files changed, 88 insertions(+), 37 deletions(-) diff --git a/react/src/actions/actionCreators.js b/react/src/actions/actionCreators.js index d2c7991..279f957 100644 --- a/react/src/actions/actionCreators.js +++ b/react/src/actions/actionCreators.js @@ -306,7 +306,7 @@ export function dismissToasterMessage() { } export function addCoin(coin, mode, syncOnly) { - console.log('coin, mode', coin + ' ' + mode); + console.log('coin, mode, syncOnly', coin + ' ' + mode + ' ' + syncOnly); /*startIguanaInstance(mode, coin) .then(function(json) { console.log('addCoin+startIguanaInstance', json); @@ -317,27 +317,36 @@ export function addCoin(coin, mode, syncOnly) { } } else { if (checkCoinType(coin) === 'currency_ac') { - var _acData = startCurrencyAssetChain('', coin, mode); + const _acData = startCurrencyAssetChain('', coin, mode); + return dispatch => { dispatch(iguanaAddCoin(coin, mode, _acData)); } } if (checkCoinType(coin) === 'ac') { - var _acData = startAssetChain('', coin, mode); + const _acData = startAssetChain('', coin, mode); + return dispatch => { dispatch(iguanaAddCoin(coin, mode, _acData)); } } if (checkCoinType(coin) === 'crypto') { - var _acData = startCrypto('', coin, mode); + const _acData = startCrypto('', coin, mode); + if (syncOnly) { - startIguanaInstance(mode + '/sync', coin) - .then(function(json) { - console.log('started ' + coin + ' / ' mode + ' fork', json); - return dispatch => { + const modeToValue = { + '1': 'full', + '0': 'basilisk', + '-1': 'native' + }; + + return dispatch => { + startIguanaInstance(modeToValue[mode] + '/sync', coin) + .then(function(json) { + console.log('started ' + coin + ' / ' + modeToValue[mode] + ' fork', json); dispatch(iguanaAddCoin(coin, mode, _acData)); - } - }); + }); + } } else { return dispatch => { dispatch(iguanaAddCoin(coin, mode, _acData)); @@ -1133,8 +1142,9 @@ export function getKMDAddressesNative(coin, mode, currentAddress) { //console.log('calc result', result); //console.log('calc json', json); - if (mode !== 'basilisk') { + if (mode !== 'basilisk' && json && json.length) { 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); @@ -2323,6 +2333,29 @@ export function iguanaUTXORawTX(data) { }); } +export function dexSendRawTX(data) { + const payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': 'dex', + 'method': 'sendrawtransaction', + 'signedtx': data.signedtx, + 'symbol': data.coin + }; + + 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, 'dexSendRawTX', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => resolve(json)) + }); +} + /*function Shepherd_SendPendValue() { Shepherd_SysInfo().then(function(result){ var ram_data = formatBytes(result.totalmem_bytes) diff --git a/react/src/components/addcoin/addcoin.js b/react/src/components/addcoin/addcoin.js index c3de459..763d6ba 100644 --- a/react/src/components/addcoin/addcoin.js +++ b/react/src/components/addcoin/addcoin.js @@ -39,7 +39,7 @@ class AddCoin extends React.Component { toggleSyncOnlyMode() { this.setState(Object.assign({}, this.state, { - syncOnly: this.state.syncOnly, + syncOnly: !this.state.syncOnly, })); } @@ -108,17 +108,8 @@ class AddCoin extends React.Component { this.updateSelectedMode('1'); } - /*handleForm(e) { - e.preventDefault(); - e.target.reset(); - this.setState({ - mode: '', - selectedCoin: null, - }); - }*/ - activateCoin() { - Store.dispatch(addCoin(this.state.selectedCoin.split('|')[0], this.state.mode, syncOnly)); + Store.dispatch(addCoin(this.state.selectedCoin.split('|')[0], this.state.mode, this.state.syncOnly)); } dismiss() { diff --git a/react/src/components/dashboard/sendCoin.js b/react/src/components/dashboard/sendCoin.js index 94b27cb..4b26e35 100644 --- a/react/src/components/dashboard/sendCoin.js +++ b/react/src/components/dashboard/sendCoin.js @@ -10,7 +10,8 @@ import { triggerToaster, iguanaUTXORawTX, clearLastSendToResponseState, - sendToAddressStateAlt + sendToAddressStateAlt, + dexSendRawTX } from '../../actions/actionCreators'; import Store from '../../store'; @@ -41,7 +42,9 @@ class SendCoin extends React.Component { } renderAddressAmount(address) { - if (this.props.ActiveCoin.addresses && this.props.ActiveCoin.addresses['public'] && this.props.ActiveCoin.addresses['public'].length) { + if (this.props.ActiveCoin.addresses && + this.props.ActiveCoin.addresses['public'] && + this.props.ActiveCoin.addresses['public'].length) { for (let i = 0; i < this.props.ActiveCoin.addresses['public'].length; i++) { if (this.props.ActiveCoin.addresses['public'][i].address === address) { return this.props.ActiveCoin.addresses['public'][i].amount; @@ -53,7 +56,9 @@ class SendCoin extends React.Component { } renderAddressByType(type) { - if (this.props.ActiveCoin.addresses && this.props.ActiveCoin.addresses[type] && this.props.ActiveCoin.addresses[type].length) { + if (this.props.ActiveCoin.addresses && + this.props.ActiveCoin.addresses[type] && + this.props.ActiveCoin.addresses[type].length) { if (this.state.sendApiType) { const mainAddress = this.props.Dashboard.activeHandle[this.props.ActiveCoin.coin]; const mainAddressAmount = this.renderAddressAmount(mainAddress); @@ -179,20 +184,32 @@ class SendCoin extends React.Component { 'sendsig': this.state.sendSig === true ? 0 : 1, 'utxos': utxoSet }; + iguanaUTXORawTX(sendData) .then(function(json) { console.log('sendData', sendData); console.log('iguanaUTXORawTXJSON', json); if (json.result === 'success' && json.completed === true) { Store.dispatch(triggerToaster(true, translate('TOASTR.SIGNED_TX_GENERATED') + '.', translate('TOASTR.WALLET_NOTIFICATION'), 'success')); - Store.dispatch(sendToAddressStateAlt(json)); if (sendData.sendsig === 1) { //Store.dispatch(triggerToaster(true, translate('TOASTR.SENDING_TX') + '.', translate('TOASTR.WALLET_NOTIFICATION'), 'success')); - /*ajax_data_dexrawtx = { + const dexrawtxData = { 'signedtx': json.signedtx, 'coin': sendData.coin - };*/ + }; + dexSendRawTX(dexrawtxData) + .then(function(dexRawTxJson) { + if (dexRawTxJson.error === undefined) { + Store.dispatch(sendToAddressStateAlt(dexRawTxJson)); + Store.dispatch(triggerToaster(true, translate('TOASTR.SIGNED_TX_SENT'), translate('TOASTR.WALLET_NOTIFICATION'))); + console.log('utxo remove', true); + } else { + console.log('utxo alt'); + Store.dispatch(triggerToaster(true, translate('TOASTR.SIGNED_TX_SENT'), translate('TOASTR.WALLET_NOTIFICATION'))); + Store.dispatch(sendToAddressStateAlt(dexRawTxJson)); + } + }); } else { Store.dispatch(sendToAddressStateAlt(json)); } @@ -241,9 +258,15 @@ class SendCoin extends React.Component { {this.props.ActiveCoin.lastSendToResponse[key] === true ? 'true' : 'success'} ); } else { - return ( - false - ); + if (this.props.ActiveCoin.lastSendToResponse[key].length > 20 && key === 'result') { + return ( + {this.props.ActiveCoin.lastSendToResponse[key]} + ); + } else { + return ( + false + ); + } } } else if (key === 'error') { return ( @@ -270,7 +293,6 @@ class SendCoin extends React.Component { renderSendCoinResponse() { if (this.props.ActiveCoin.lastSendToResponse) { - console.log('renderSendCoinResponse', this.props.ActiveCoin.lastSendToResponse); return Object.keys(this.props.ActiveCoin.lastSendToResponse).map((key, index) => {key} diff --git a/react/src/components/dashboard/walletsBalance.js b/react/src/components/dashboard/walletsBalance.js index 2730435..a731033 100644 --- a/react/src/components/dashboard/walletsBalance.js +++ b/react/src/components/dashboard/walletsBalance.js @@ -3,11 +3,16 @@ import { translate } from '../../translate/translate'; class WalletsBalance extends React.Component { render() { - if (this.props && this.props.coin && this.props.mode !== 'native' && this.props.balance && !this.props.send && !this.props.receive) { + if (this.props && + this.props.ActiveCoin && + this.props.ActiveCoin.coin && + this.props.ActiveCoin.mode !== 'native' && + !this.props.ActiveCoin.send && + !this.props.ActiveCoin.receive) { return (
-
+
- {this.props && this.props.balance ? this.props.balance : 0} + {this.props.ActiveCoin && this.props.ActiveCoin.balance ? this.props.ActiveCoin.balance : 0}
@@ -45,7 +50,7 @@ class WalletsBalance extends React.Component {
-
+
@@ -62,7 +67,7 @@ class WalletsBalance extends React.Component {
-
+