From 04c4fcd564c9c14fb776e2e4b30f5db9eae856f1 Mon Sep 17 00:00:00 2001 From: pbca26 Date: Sat, 29 Apr 2017 12:04:13 +0300 Subject: [PATCH] addr amount render fix; toggle send api type --- react/src/actions/actionCreators.js | 72 +++++++++++-- react/src/components/dashboard/sendCoin.js | 101 +++++++++++++++--- react/src/components/dashboard/walletsData.js | 15 ++- 3 files changed, 169 insertions(+), 19 deletions(-) diff --git a/react/src/actions/actionCreators.js b/react/src/actions/actionCreators.js index 1b3529c..7f99a85 100644 --- a/react/src/actions/actionCreators.js +++ b/react/src/actions/actionCreators.js @@ -978,7 +978,7 @@ export function getKMDAddressesNative(coin, mode, currentAddress) { 'account': '*' }; } - console.log('pl', payload); + //console.log('pl', payload); if (sessionStorage.getItem('useCache') && mode === 'basilisk') { const pubkey = JSON.parse(sessionStorage.getItem('IguanaActiveAccount')).pubkey; @@ -1063,7 +1063,7 @@ export function getKMDAddressesNative(coin, mode, currentAddress) { } function calcBalance(result, json, dispatch, mode) { - console.log('result', result); + //console.log('result', result); if (mode === 'full' || mode === 'basilisk') { result[0] = result[0].result; } else { @@ -1071,8 +1071,8 @@ export function getKMDAddressesNative(coin, mode, currentAddress) { result[1] = result[1].result; } - console.log('calc result', result); - console.log('calc json', json); + //console.log('calc result', result); + //console.log('calc json', json); if (mode !== 'basilisk') { const allAddrArray = json.map(res => res.address).filter((x, i, a) => a.indexOf(x) == i); @@ -1112,8 +1112,8 @@ export function getKMDAddressesNative(coin, mode, currentAddress) { } else { filteredArray = json.filter(res => res.address === result[a][b]).map(res => res.amount); } - console.log('filteredArray', filteredArray); - console.log('addr', result[a][b]); + //console.log('filteredArray', filteredArray); + //console.log('addr', result[a][b]); let sum = 0; @@ -1752,6 +1752,34 @@ export function sendToAddress(coin, _payload) { } } +export function sendFromAddress(coin, _payload) { + const payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'coin': coin, + 'method': 'sendfrom', + 'params': [ + _payload.sendFrom, + _payload.sendTo, + _payload.amount, + 'EasyDEX', + 'EasyDEXTransaction' + ] + }; + + 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, 'sendFromAddress', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => dispatch(sendToAddressState(json, dispatch))) + } +} + function checkAddressBasiliskHandle(json) { if (json && json.error) { return dispatch => { @@ -2116,6 +2144,38 @@ export function connectNotaries() { } } +export function iguanaUTXORawTX(data) { + const payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'symbol': data.coin, + 'agent': 'basilisk', + 'method': 'utxorawtx', + 'vals': { + 'timelock': 0, + 'changeaddr': data.sendfrom, + 'destaddr': data.sendtoaddr, + 'txfee': data.txfee, + 'amount': data.amount, + 'sendflag': data.sendsig + }, + 'utxos': data.utxos + }; + console.log('iguanaUTXORawTXExport', payload); + + 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, 'iguanaUTXORawTX', '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/dashboard/sendCoin.js b/react/src/components/dashboard/sendCoin.js index b698e60..555c90d 100644 --- a/react/src/components/dashboard/sendCoin.js +++ b/react/src/components/dashboard/sendCoin.js @@ -3,6 +3,7 @@ import Config from '../../config'; import { translate } from '../../translate/translate'; import { sendToAddress, + sendFromAddress, sendNativeTx, getKMDOPID, resolveOpenAliasAddress, @@ -26,22 +27,47 @@ class SendCoin extends React.Component { amount: 0, fee: 0.0001, sendSig: false, + sendApiType: false, addressSelectorOpen: false, }; this.updateInput = this.updateInput.bind(this); - this.handleSubmit = this.handleSubmit.bind(this); + this.handleBasiliskSend = this.handleBasiliskSend.bind(this); this.openDropMenu = this.openDropMenu.bind(this); this.toggleSendSig = this.toggleSendSig.bind(this); this.getOAdress = this.getOAdress.bind(this); + this.toggleSendAPIType = this.toggleSendAPIType.bind(this); + } + + renderAddressAmount(address) { + 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; + } + } + } else { + return 0; + } } renderAddressByType(type) { if (this.props.ActiveCoin.addresses && this.props.ActiveCoin.addresses[type] && this.props.ActiveCoin.addresses[type].length) { - return this.props.ActiveCoin.addresses[type].map((address) => -
  • - this.updateAddressSelection(address.address, type, address.amount)}> [ {address.amount} {this.props.ActiveCoin.coin} ]  {address.address} -
  • - ); + if (this.state.sendApiType) { + const mainAddress = this.props.Dashboard.activeHandle[this.props.ActiveCoin.coin]; + const mainAddressAmount = this.renderAddressAmount(mainAddress); + + return( +
  • + this.updateAddressSelection(mainAddress, type, mainAddressAmount)}> [ {mainAddressAmount} {this.props.ActiveCoin.coin} ]  {mainAddress} +
  • + ); + } else { + return this.props.ActiveCoin.addresses[type].map((address) => +
  • + this.updateAddressSelection(address.address, type, address.amount)}> [ {address.amount} {this.props.ActiveCoin.coin} ]  {address.address} +
  • + ); + } } else { return null; } @@ -54,6 +80,16 @@ class SendCoin extends React.Component { [ {this.state.sendFromAmount} {this.props.ActiveCoin.coin} ]  {this.state.sendFrom} ); + } else if (this.state.sendApiType) { + const mainAddress = this.props.Dashboard.activeHandle[this.props.ActiveCoin.coin]; + const mainAddressAmount = this.renderAddressAmount(mainAddress); + + console.log('sendApiType', this.state.sendApiType); + return ( + + [ {mainAddressAmount} {this.props.ActiveCoin.coin} ]  {mainAddress} + + ); } else { return ( - Select Transparent or Private Address - @@ -89,7 +125,7 @@ class SendCoin extends React.Component { this.setState(Object.assign({}, this.state, { sendFrom: address, addressType: type, - sendFromAmount: amount, + sendFromAmount: amount ? amount : this.props.ActiveCoin.addresses[type][address].amount, addressSelectorOpen: !this.state.addressSelectorOpen, })); } @@ -100,7 +136,12 @@ class SendCoin extends React.Component { })); if (step === 2) { - Store.dispatch(sendToAddress(this.props.ActiveCoin.coin, this.state)); + if (!this.state.sendApiType) { + handleBasiliskSend(); + } else { + Store.dispatch(sendToAddress(this.props.ActiveCoin.coin, this.state)); + } + //Store.dispatch(sendFromAddress(this.props.ActiveCoin.coin, this.state)); } } @@ -110,14 +151,19 @@ class SendCoin extends React.Component { })); } + toggleSendAPIType() { + this.setState(Object.assign({}, this.state, { + sendApiType: !this.state.sendApiType, + })); + } + updateInput(e) { this.setState({ [e.target.name]: e.target.value, }); - console.log(this.state); } - handleSubmit() { + handleBasiliskSend() { const utxoSet = this.props.ActiveCoin.cache[this.props.ActiveCoin.coin][this.state.sendFrom].refresh; const sendData = { 'coin': this.props.ActiveCoin.coin, @@ -130,6 +176,19 @@ class SendCoin extends React.Component { }; 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'))); + + if (sendData.sendsig === 1) { + Store.dispatch(triggerToaster(true, translate('TOASTR.SENDING_TX') + '.', translate('TOASTR.WALLET_NOTIFICATION'))); + ajax_data_dexrawtx = { + 'signedtx': json.signedtx, + 'coin': sendData.coin + }; + } + } console.log(json); }); //Store.dispatch(sendNativeTx(this.props.ActiveCoin.coin, this.state)); @@ -218,7 +277,7 @@ class SendCoin extends React.Component { } if (this.state.sendTo === '') { - Store.dispatch(triggerToaster(true, 'Couldn\'t find any ' + this.props.ActiveCoin.coin +' addresses', 'OpenAlias', 'error')); + Store.dispatch(triggerToaster(true, 'Couldn\'t find any ' + this.props.ActiveCoin.coin + ' addresses', 'OpenAlias', 'error')); } } else { Store.dispatch(triggerToaster(true, 'Couldn\'t find any addresses', 'OpenAlias', 'error')); @@ -231,7 +290,7 @@ class SendCoin extends React.Component { return (
    - +
    @@ -246,6 +305,23 @@ class SendCoin extends React.Component { } } + renderSendApiTypeSelector() { + if (this.props.ActiveCoin.mode === 'basilisk') { + return ( +
    +
    +
    + +
    + +
    +
    + ); + } else { + return null; + } + } + render() { if (this.props.ActiveCoin && this.props.ActiveCoin.send && this.props.ActiveCoin.mode !== 'native') { return ( @@ -283,6 +359,7 @@ class SendCoin extends React.Component {
    + {this.renderSendApiTypeSelector()}
    diff --git a/react/src/components/dashboard/walletsData.js b/react/src/components/dashboard/walletsData.js index fb623f5..1748f50 100644 --- a/react/src/components/dashboard/walletsData.js +++ b/react/src/components/dashboard/walletsData.js @@ -64,6 +64,7 @@ class WalletsData extends React.Component { toggleCacheApi() { const _useCache = !this.state.useCache; + console.log('useCache is set to', _useCache); sessionStorage.setItem('useCache', _useCache); this.setState(Object.assign({}, this.state, { @@ -353,11 +354,23 @@ class WalletsData extends React.Component { } } + renderAddressAmount() { + if (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 === this.state.currentAddress) { + return this.props.ActiveCoin.addresses['public'][i].amount; + } + } + } else { + return 0; + } + } + renderSelectorCurrentLabel() { if (this.state.currentAddress) { return ( - [ {this.state.sendFromAmount} {this.props.ActiveCoin.coin} ]  {this.state.currentAddress} + [ {this.renderAddressAmount()} {this.props.ActiveCoin.coin} ]  {this.state.currentAddress} ); } else {