aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Tseung <alextsg@gmail.com>2018-06-16 05:36:52 +0800
committerAlexander Tseung <alextsg@gmail.com>2018-06-16 05:36:52 +0800
commit5685c4bafed0458e350b401791e108b8162a88e0 (patch)
treed6008af37952ac17d8ada6a5d1304edbb7bcc084
parente4d3bdba125964042480e35847747903f3de7ac3 (diff)
downloadtangerine-wallet-browser-5685c4bafed0458e350b401791e108b8162a88e0.tar
tangerine-wallet-browser-5685c4bafed0458e350b401791e108b8162a88e0.tar.gz
tangerine-wallet-browser-5685c4bafed0458e350b401791e108b8162a88e0.tar.bz2
tangerine-wallet-browser-5685c4bafed0458e350b401791e108b8162a88e0.tar.lz
tangerine-wallet-browser-5685c4bafed0458e350b401791e108b8162a88e0.tar.xz
tangerine-wallet-browser-5685c4bafed0458e350b401791e108b8162a88e0.tar.zst
tangerine-wallet-browser-5685c4bafed0458e350b401791e108b8162a88e0.zip
Estimate gas limit when the token amount changes. Fix amount input
-rw-r--r--ui/app/components/send_/send-content/send-amount-row/send-amount-row.component.js16
-rw-r--r--ui/app/components/send_/send-content/send-content.component.js2
-rw-r--r--ui/app/components/send_/send.component.js4
-rw-r--r--ui/app/components/send_/send.utils.js12
4 files changed, 18 insertions, 16 deletions
diff --git a/ui/app/components/send_/send-content/send-amount-row/send-amount-row.component.js b/ui/app/components/send_/send-content/send-amount-row/send-amount-row.component.js
index 8aefeed4a..e6cb405e9 100644
--- a/ui/app/components/send_/send-content/send-amount-row/send-amount-row.component.js
+++ b/ui/app/components/send_/send-content/send-amount-row/send-amount-row.component.js
@@ -23,6 +23,7 @@ export default class SendAmountRow extends Component {
tokenBalance: PropTypes.string,
updateSendAmount: PropTypes.func,
updateSendAmountError: PropTypes.func,
+ updateGas: PropTypes.func,
}
validateAmount (amount) {
@@ -54,6 +55,15 @@ export default class SendAmountRow extends Component {
setMaxModeTo(false)
updateSendAmount(amount)
+ this.validateAmount(amount)
+ }
+
+ updateGas (amount) {
+ const { selectedToken, updateGas } = this.props
+
+ if (selectedToken) {
+ updateGas({ amount })
+ }
}
render () {
@@ -77,12 +87,12 @@ export default class SendAmountRow extends Component {
<CurrencyDisplay
conversionRate={amountConversionRate}
convertedCurrency={convertedCurrency}
- onBlur={newAmount => this.updateAmount(newAmount)}
- onChange={newAmount => this.validateAmount(newAmount)}
+ onBlur={newAmount => this.updateGas(newAmount)}
+ onChange={newAmount => this.updateAmount(newAmount)}
inError={inError}
primaryCurrency={primaryCurrency || 'ETH'}
selectedToken={selectedToken}
- value={amount || '0x0'}
+ value={amount}
/>
</SendRowWrapper>
)
diff --git a/ui/app/components/send_/send-content/send-content.component.js b/ui/app/components/send_/send-content/send-content.component.js
index 3a14054eb..adc114c0e 100644
--- a/ui/app/components/send_/send-content/send-content.component.js
+++ b/ui/app/components/send_/send-content/send-content.component.js
@@ -18,7 +18,7 @@ export default class SendContent extends Component {
<div className="send-v2__form">
<SendFromRow />
<SendToRow updateGas={(updateData) => this.props.updateGas(updateData)} />
- <SendAmountRow />
+ <SendAmountRow updateGas={(updateData) => this.props.updateGas(updateData)} />
<SendGasRow />
</div>
</PageContainerContent>
diff --git a/ui/app/components/send_/send.component.js b/ui/app/components/send_/send.component.js
index 516251e22..38da4910b 100644
--- a/ui/app/components/send_/send.component.js
+++ b/ui/app/components/send_/send.component.js
@@ -38,7 +38,7 @@ export default class SendTransactionScreen extends PersistentForm {
updateSendTokenBalance: PropTypes.func,
};
- updateGas ({ to } = {}) {
+ updateGas ({ to, amount: value } = {}) {
const {
amount,
blockGasLimit,
@@ -60,7 +60,7 @@ export default class SendTransactionScreen extends PersistentForm {
selectedAddress,
selectedToken,
to: to && to.toLowerCase(),
- value: amount,
+ value: value || amount,
})
}
diff --git a/ui/app/components/send_/send.utils.js b/ui/app/components/send_/send.utils.js
index 8772d464b..3d8e1a882 100644
--- a/ui/app/components/send_/send.utils.js
+++ b/ui/app/components/send_/send.utils.js
@@ -203,21 +203,13 @@ async function estimateGas ({ selectedAddress, selectedToken, blockGasLimit, to,
err.message.includes('gas required exceeds allowance or always failing transaction')
)
if (simulationFailed) {
- const estimateWithBuffer = addGasBuffer(
- paramsForGasEstimate.gas,
- blockGasLimit,
- selectedToken ? 2 : 1.5
- )
+ const estimateWithBuffer = addGasBuffer(paramsForGasEstimate.gas, blockGasLimit, 1.5)
return resolve(ethUtil.addHexPrefix(estimateWithBuffer))
} else {
return reject(err)
}
}
- const estimateWithBuffer = addGasBuffer(
- estimatedGas.toString(16),
- blockGasLimit,
- selectedToken ? 2 : 1.5
- )
+ const estimateWithBuffer = addGasBuffer(estimatedGas.toString(16), blockGasLimit, 1.5)
return resolve(ethUtil.addHexPrefix(estimateWithBuffer))
})
})