From a45e06aa565c7aa557fb7ba4a23f5a0a9c5d5ac5 Mon Sep 17 00:00:00 2001 From: pbca26 Date: Thu, 24 Aug 2017 20:11:44 +0300 Subject: [PATCH] native send address dropdown fix; substract fee toggle --- react/src/actions/actions/nativeSend.js | 46 ++++++++++------ .../walletsNativeSend/walletsNativeSend.js | 53 +++++++++++++++---- .../walletsNativeSend.render.js | 20 ++++++- react/src/translate/en.js | 2 + 4 files changed, 94 insertions(+), 27 deletions(-) diff --git a/react/src/actions/actions/nativeSend.js b/react/src/actions/actions/nativeSend.js index 0562f1a..39b505e 100644 --- a/react/src/actions/actions/nativeSend.js +++ b/react/src/actions/actions/nativeSend.js @@ -71,10 +71,20 @@ export function sendNativeTx(coin, _payload) { cmd: payload.function, params: (_payload.addressType === 'public' && _payload.sendTo.length !== 95) || !_payload.sendFrom ? - [ - _payload.sendTo, - _payload.amount - ] + (_payload.substractFee ? + [ + _payload.sendTo, + _payload.amount, + '', + '', + true + ] + : + [ + _payload.sendTo, + _payload.amount + ] + ) : [ _payload.sendFrom, @@ -134,25 +144,31 @@ export function sendNativeTx(coin, _payload) { json.indexOf('"},"id":"jl777"') ); - dispatch( - triggerToaster( - true, - _message, - translate('TOASTR.WALLET_NOTIFICATION'), - 'error' - ) - ); - if (json.indexOf('"code":-4') > -1) { dispatch( triggerToaster( - true, - translate('TOASTR.WALLET_NOTIFICATION'), translate('API.WALLETDAT_MISMATCH'), + translate('TOASTR.WALLET_NOTIFICATION'), 'info', false ) ); + } else if (json.indexOf('"code":-5') > -1) { + dispatch( + triggerToaster( + `Invalid ${coin} address`, + translate('TOASTR.WALLET_NOTIFICATION'), + 'error', + ) + ); + } else { + dispatch( + triggerToaster( + _message, + translate('TOASTR.WALLET_NOTIFICATION'), + 'error' + ) + ); } } else { dispatch( diff --git a/react/src/components/dashboard/walletsNativeSend/walletsNativeSend.js b/react/src/components/dashboard/walletsNativeSend/walletsNativeSend.js index f97e07b..b8deae5 100644 --- a/react/src/components/dashboard/walletsNativeSend/walletsNativeSend.js +++ b/react/src/components/dashboard/walletsNativeSend/walletsNativeSend.js @@ -31,6 +31,7 @@ class WalletsNativeSend extends React.Component { fee: 0, addressSelectorOpen: false, renderAddressDropdown: true, + substractFee: false, }; this.updateInput = this.updateInput.bind(this); this.handleSubmit = this.handleSubmit.bind(this); @@ -41,10 +42,18 @@ class WalletsNativeSend extends React.Component { this.setRecieverFromScan = this.setRecieverFromScan.bind(this); this.renderOPIDListCheck = this.renderOPIDListCheck.bind(this); this.WalletsNativeSendFormRender = _WalletsNativeSendFormRender.bind(this); + this.isTransparentTx = this.isTransparentTx.bind(this); + this.toggleSubstractFee = this.toggleSubstractFee.bind(this); } WalletsNativeSendFormRender() { - return this._WalletsNativeSendFormRender(); + return _WalletsNativeSendFormRender.call(this); + } + + toggleSubstractFee() { + this.setState({ + substractFee: !this.state.substractFee, + }); } componentWillMount() { @@ -166,20 +175,20 @@ class WalletsNativeSend extends React.Component { const _satatusDef = { queued: { icon: 'warning', - label: 'QUEUED' + label: 'QUEUED', }, executing: { icon: 'info', - label: 'EXECUTING' + label: 'EXECUTING', }, failed: { icon: 'danger', - label: 'FAILED' + label: 'FAILED', }, success: { icon: 'success', - label: 'SUCCESS' - } + label: 'SUCCESS', + }, }; return ( @@ -219,7 +228,7 @@ class WalletsNativeSend extends React.Component { isWaitingStatus = false; return ( - txid: { opid.result.txid } + { translate('KMD_NATIVE.TXID') }: { opid.result.txid }
{ translate('KMD_NATIVE.EXECUTION_SECONDS') }: { opid.execution_secs }
@@ -302,6 +311,7 @@ class WalletsNativeSend extends React.Component { fee: 0, addressSelectorOpen: false, renderAddressDropdown: true, + substractFee: false, }); } @@ -365,11 +375,12 @@ class WalletsNativeSend extends React.Component { validateSendFormData() { let valid = true; - if (!this.state.sendTo || this.state.sendTo.length < 34) { + if (!this.state.sendTo || + this.state.sendTo.length < 34) { Store.dispatch( triggerToaster( translate('SEND.SEND_TO_ADDRESS_MIN_LENGTH'), - '', + translate('TOASTR.WALLET_NOTIFICATION'), 'error' ) ); @@ -380,7 +391,7 @@ class WalletsNativeSend extends React.Component { Store.dispatch( triggerToaster( translate('SEND.AMOUNT_POSITIVE_NUMBER'), - '', + translate('TOASTR.WALLET_NOTIFICATION'), 'error' ) ); @@ -391,7 +402,19 @@ class WalletsNativeSend extends React.Component { Store.dispatch( triggerToaster( translate('SEND.INSUFFICIENT_FUNDS'), - '', + translate('TOASTR.WALLET_NOTIFICATION'), + 'error' + ) + ); + valid = false; + } + + if (this.state.sendTo.length > 34 && + (!this.state.sendFrom || this.state.sendFrom.length < 34)) { + Store.dispatch( + triggerToaster( + translate('SEND.SELECT_SOURCE_ADDRESS'), + translate('TOASTR.WALLET_NOTIFICATION'), 'error' ) ); @@ -401,6 +424,14 @@ class WalletsNativeSend extends React.Component { return valid; } + isTransparentTx() { + if (((this.state.sendFrom && this.state.sendFrom.length === 34) || !this.state.sendFrom) && + (this.state.sendTo && this.state.sendTo.length === 34)) { + return true; + } + + return false; + } render() { if (this.props && diff --git a/react/src/components/dashboard/walletsNativeSend/walletsNativeSend.render.js b/react/src/components/dashboard/walletsNativeSend/walletsNativeSend.render.js index 17c842b..f849791 100644 --- a/react/src/components/dashboard/walletsNativeSend/walletsNativeSend.render.js +++ b/react/src/components/dashboard/walletsNativeSend/walletsNativeSend.render.js @@ -27,6 +27,7 @@ export const AddressListRender = function() { style={{ display: this.state.sendFrom === null ? 'inline-block' : 'none' }}> + { this.renderAddressByType('public') } { this.renderAddressByType('private') } @@ -74,7 +75,7 @@ export const _WalletsNativeSendFormRender = function() { { this.state.renderAddressDropdown &&
- + { this.renderAddressList() }
@@ -112,6 +113,23 @@ export const _WalletsNativeSendFormRender = function() { placeholder="0.000" autoComplete="off" /> +
+ + +
this.toggleSubstractFee() }> + Substract fee from amount +
+
+