From: Zhiting Lin Date: Mon, 21 Oct 2019 08:45:54 +0000 (+0800) Subject: shown the correct chain gas amount for chain tranctions. X-Git-Url: http://git.osdn.net/view?p=bytom%2Fbytom-electron.git;a=commitdiff_plain;h=4679b53da65b314de3dcde1a7c766d20a4a43351 shown the correct chain gas amount for chain tranctions. --- diff --git a/src/features/shared/components/GasField/GasField.jsx b/src/features/shared/components/GasField/GasField.jsx index 4037aaa..0480aff 100644 --- a/src/features/shared/components/GasField/GasField.jsx +++ b/src/features/shared/components/GasField/GasField.jsx @@ -20,21 +20,20 @@ class GasField extends React.Component { render() { const fieldProps = pick(this.props.fieldProps, TEXT_FIELD_PROPS) const {touched, error} = this.props.fieldProps + const chainGas = this.props.chainGas || 0 - return( -
- {normalizeBTMAmountUnit(btmID, fieldProps.value* this.props.gas, this.props.btmAmountUnit)} - + return
+ {normalizeBTMAmountUnit(btmID, ( chainGas + fieldProps.value * this.props.gas ), this.props.btmAmountUnit)} + - {touched && error && {error}} - {this.props.hint && {this.props.hint}} -
- ) + {touched && error && {error}} + {this.props.hint && {this.props.hint}} +
} } diff --git a/src/features/transactions/components/New/ConfirmModal/ConfirmModal.jsx b/src/features/transactions/components/New/ConfirmModal/ConfirmModal.jsx index dab5bf0..d4d67c5 100644 --- a/src/features/transactions/components/New/ConfirmModal/ConfirmModal.jsx +++ b/src/features/transactions/components/New/ConfirmModal/ConfirmModal.jsx @@ -26,12 +26,13 @@ class ConfirmModal extends Component { cancel, error, gas, + chainGas, t, btmAmountUnit, assetDecimal } = this.props - const fee = Number(gasLevel.value * gas) + const fee = Number( (chainGas||0 ) + gasLevel.value * gas ) const totalAmount = sum(receivers, 'amount.value') diff --git a/src/features/transactions/components/New/NormalTransactionForm.jsx b/src/features/transactions/components/New/NormalTransactionForm.jsx index 9de7074..d48e3b4 100644 --- a/src/features/transactions/components/New/NormalTransactionForm.jsx +++ b/src/features/transactions/components/New/NormalTransactionForm.jsx @@ -23,6 +23,7 @@ class NormalTxForm extends React.Component { this.connection = chainClient().connection this.state = { estimateGas:null, + chainGas: 0, counter: 1 } @@ -58,6 +59,7 @@ class NormalTxForm extends React.Component { cancel={this.props.closeModal} onSubmit={this.submitWithValidation} gas={this.state.estimateGas} + chainGas={this.state.chainGas} btmAmountUnit={this.props.btmAmountUnit} assetDecimal={assetDecimal} asset={this.props.asset} @@ -105,27 +107,48 @@ class NormalTxForm extends React.Component { const noAccount = !accountAlias && !accountId const noAsset = !assetAlias && !assetId - if ( addresses.includes('') || amounts.includes(0)|| noAccount || noAsset) { + if ( addresses.includes('') || amounts.includes(NaN)|| amounts.includes(0)|| noAccount || noAsset) { this.setState({estimateGas: null}) return } + const isBTM = (assetAlias==='BTM') || (assetId === btmID) + const actions = normalTxActionBuilder(transaction, Math.pow(10, 7), 'amount' ) const body = {actions, ttl: 1} - this.connection.request('/build-transaction', body).then(resp => { - return this.connection.request('/estimate-transaction-gas', { - transactionTemplate: resp.data - }).then(resp => { - this.setState({estimateGas: Math.ceil(resp.data.totalNeu/100000)*100000}) - }).catch(err =>{ - throw err + if(isBTM){ + this.connection.request('/build-chain-transactions', body).then(resp => { + return this.connection.request('/estimate-chain-transaction-gas', { + transactionTemplates: resp.data + }).then(resp => { + this.setState({ + estimateGas: Math.ceil(resp.data.totalNeu/100000)*100000, + chainGas: Math.ceil(resp.data.chainTxNeu/100000)*100000 + }) + }).catch(err =>{ + throw err + }) + }).catch(err=>{ + this.setState({estimateGas: null, address: null}) + const errorMsg = err.code && i18n.exists(`btmError.${err.code}`) && t(`btmError.${err.code}`) || err.msg + this.props.showError(new Error(errorMsg)) }) - }).catch(err=>{ - this.setState({estimateGas: null, address: null}) - const errorMsg = err.code && i18n.exists(`btmError.${err.code}`) && t(`btmError.${err.code}`) || err.msg - this.props.showError(new Error(errorMsg)) - }) + }else{ + this.connection.request('/build-transaction', body).then(resp => { + return this.connection.request('/estimate-transaction-gas', { + transactionTemplate: resp.data + }).then(resp => { + this.setState({estimateGas: Math.ceil(resp.data.totalNeu/100000)*100000}) + }).catch(err =>{ + throw err + }) + }).catch(err=>{ + this.setState({estimateGas: null, address: null}) + const errorMsg = err.code && i18n.exists(`btmError.${err.code}`) && t(`btmError.${err.code}`) || err.msg + this.props.showError(new Error(errorMsg)) + }) + } } render() { @@ -154,46 +177,46 @@ class NormalTxForm extends React.Component { const showBtmAmountUnit = (assetAlias.value === 'BTM' || assetId.value === btmID) return ( - this.confirmedTransaction(e, assetDecimal)} - submitting={submitting} - submitLabel= {submitLabel} - disabled={this.disableSubmit()} - className={styles.container} - > -
- -
+ this.confirmedTransaction(e, assetDecimal)} + submitting={submitting} + submitLabel= {submitLabel} + disabled={this.disableSubmit()} + className={styles.container} + > +
+ +
+ +
-
- - {showAvailableBalance && availableBalance && + {showAvailableBalance && availableBalance && {t('transaction.normal.availableBalance')} {availableBalance}} -
+
- + -
+
{receivers.map((receiver, index) =>
)} - -
+ +
- -
- - {t('transaction.normal.feeDescription')} -
+ +
+ + {t('transaction.normal.feeDescription')}
- +
+
) } }