mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Send token now estimates gas and price.
This commit is contained in:
parent
79bcb88db3
commit
fc3e071ad6
@ -57,6 +57,9 @@ function mapDispatchToProps (dispatch) {
|
|||||||
dispatch(actions.signTokenTx(tokenAddress, toAddress, amount, txData))
|
dispatch(actions.signTokenTx(tokenAddress, toAddress, amount, txData))
|
||||||
),
|
),
|
||||||
updateTokenExchangeRate: token => dispatch(actions.updateTokenExchangeRate(token)),
|
updateTokenExchangeRate: token => dispatch(actions.updateTokenExchangeRate(token)),
|
||||||
|
estimateGas: ({ to, amount }) => dispatch(actions.estimateGas({ to, amount })),
|
||||||
|
getGasPrice: () => dispatch(actions.getGasPrice()),
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,8 +72,8 @@ function SendTokenScreen () {
|
|||||||
amountToSend: '0x0',
|
amountToSend: '0x0',
|
||||||
selectedCurrency: 'USD',
|
selectedCurrency: 'USD',
|
||||||
isGasTooltipOpen: false,
|
isGasTooltipOpen: false,
|
||||||
gasPrice: '0x5d21dba00',
|
gasPrice: null,
|
||||||
gasLimit: '0x7b0d',
|
gasLimit: null,
|
||||||
errors: {},
|
errors: {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -84,6 +87,24 @@ SendTokenScreen.prototype.componentWillMount = function () {
|
|||||||
updateTokenExchangeRate(symbol)
|
updateTokenExchangeRate(symbol)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SendTokenScreen.prototype.estimateGasAndPrice = function () {
|
||||||
|
const { selectedToken } = this.props
|
||||||
|
const { errors, amount, to } = this.state
|
||||||
|
|
||||||
|
if (!errors.to && !errors.amount && amount > 0) {
|
||||||
|
Promise.all([
|
||||||
|
this.props.getGasPrice(),
|
||||||
|
this.props.estimateGas({ to, amount: this.getAmountToSend(amount, selectedToken) }),
|
||||||
|
])
|
||||||
|
.then(([blockGasPrice, estimatedGas]) => {
|
||||||
|
this.setState({
|
||||||
|
blockGasPrice,
|
||||||
|
estimatedGas,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SendTokenScreen.prototype.validate = function () {
|
SendTokenScreen.prototype.validate = function () {
|
||||||
const {
|
const {
|
||||||
to,
|
to,
|
||||||
@ -215,7 +236,10 @@ SendTokenScreen.prototype.renderToAddressInput = function () {
|
|||||||
to: e.target.value,
|
to: e.target.value,
|
||||||
errors: {},
|
errors: {},
|
||||||
}),
|
}),
|
||||||
onBlur: () => this.setErrorsFor('to'),
|
onBlur: () => {
|
||||||
|
this.setErrorsFor('to')
|
||||||
|
this.estimateGasAndPrice()
|
||||||
|
},
|
||||||
onFocus: () => this.clearErrorsFor('to'),
|
onFocus: () => this.clearErrorsFor('to'),
|
||||||
}),
|
}),
|
||||||
h('datalist#addresses', [
|
h('datalist#addresses', [
|
||||||
@ -271,7 +295,10 @@ SendTokenScreen.prototype.renderAmountInput = function () {
|
|||||||
onChange: e => this.setState({
|
onChange: e => this.setState({
|
||||||
amount: e.target.value,
|
amount: e.target.value,
|
||||||
}),
|
}),
|
||||||
onBlur: () => this.setErrorsFor('amount'),
|
onBlur: () => {
|
||||||
|
this.setErrorsFor('amount')
|
||||||
|
this.estimateGasAndPrice()
|
||||||
|
},
|
||||||
onFocus: () => this.clearErrorsFor('amount'),
|
onFocus: () => this.clearErrorsFor('amount'),
|
||||||
}),
|
}),
|
||||||
h('div.send-screen-input-wrapper__error-message', [ errorMessage ]),
|
h('div.send-screen-input-wrapper__error-message', [ errorMessage ]),
|
||||||
@ -283,6 +310,8 @@ SendTokenScreen.prototype.renderGasInput = function () {
|
|||||||
isGasTooltipOpen,
|
isGasTooltipOpen,
|
||||||
gasPrice,
|
gasPrice,
|
||||||
gasLimit,
|
gasLimit,
|
||||||
|
blockGasPrice,
|
||||||
|
estimatedGas,
|
||||||
selectedCurrency,
|
selectedCurrency,
|
||||||
errors: {
|
errors: {
|
||||||
gasPrice: gasPriceErrorMessage,
|
gasPrice: gasPriceErrorMessage,
|
||||||
@ -303,8 +332,8 @@ SendTokenScreen.prototype.renderGasInput = function () {
|
|||||||
}, [
|
}, [
|
||||||
isGasTooltipOpen && h(GasTooltip, {
|
isGasTooltipOpen && h(GasTooltip, {
|
||||||
className: 'send-tooltip',
|
className: 'send-tooltip',
|
||||||
gasPrice,
|
gasPrice: gasPrice || blockGasPrice || '0x0',
|
||||||
gasLimit,
|
gasLimit: gasLimit || estimatedGas || '0x0',
|
||||||
onClose: () => this.setState({ isGasTooltipOpen: false }),
|
onClose: () => this.setState({ isGasTooltipOpen: false }),
|
||||||
onFeeChange: ({ gasLimit, gasPrice }) => {
|
onFeeChange: ({ gasLimit, gasPrice }) => {
|
||||||
this.setState({ gasLimit, gasPrice, errors: {} })
|
this.setState({ gasLimit, gasPrice, errors: {} })
|
||||||
@ -327,9 +356,9 @@ SendTokenScreen.prototype.renderGasInput = function () {
|
|||||||
h(GasFeeDisplay, {
|
h(GasFeeDisplay, {
|
||||||
conversionRate,
|
conversionRate,
|
||||||
tokenExchangeRate,
|
tokenExchangeRate,
|
||||||
gasPrice,
|
gasPrice: gasPrice || blockGasPrice || '0x0',
|
||||||
activeCurrency: selectedCurrency,
|
activeCurrency: selectedCurrency,
|
||||||
gas: gasLimit,
|
gas: gasLimit || estimatedGas || '0x0',
|
||||||
blockGasLimit: currentBlockGasLimit,
|
blockGasLimit: currentBlockGasLimit,
|
||||||
}),
|
}),
|
||||||
h(
|
h(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user