mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
[NewUI] Send screen gas loading fixes (#3027)
* Allow entering amount, but disable validation of amount, opening of gas customizer or clicking of next, when gas loading in send. * Fix variable name.
This commit is contained in:
parent
fdaf6eacb2
commit
4fae461a67
@ -32,8 +32,9 @@ GasFeeDisplay.prototype.render = function () {
|
|||||||
})
|
})
|
||||||
: h('div.currency-display', 'Loading...'),
|
: h('div.currency-display', 'Loading...'),
|
||||||
|
|
||||||
h('div.send-v2__sliders-icon-container', {
|
h('button.send-v2__sliders-icon-container', {
|
||||||
onClick,
|
onClick,
|
||||||
|
disabled: !gasTotal,
|
||||||
}, [
|
}, [
|
||||||
h('i.fa.fa-sliders.send-v2__sliders-icon'),
|
h('i.fa.fa-sliders.send-v2__sliders-icon'),
|
||||||
]),
|
]),
|
||||||
|
@ -652,11 +652,11 @@
|
|||||||
border: 1px solid $curious-blue;
|
border: 1px solid $curious-blue;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
background-color: $white;
|
background-color: $white;
|
||||||
padding: 5px;
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
right: 15px;
|
right: 15px;
|
||||||
top: 14px;
|
top: 14px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
font-size: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
&__sliders-icon {
|
&__sliders-icon {
|
||||||
|
@ -13,7 +13,6 @@ const MemoTextArea = require('./components/send/memo-textarea')
|
|||||||
const GasFeeDisplay = require('./components/send/gas-fee-display-v2')
|
const GasFeeDisplay = require('./components/send/gas-fee-display-v2')
|
||||||
|
|
||||||
const {
|
const {
|
||||||
MIN_GAS_TOTAL,
|
|
||||||
TOKEN_TRANSFER_FUNCTION_SIGNATURE,
|
TOKEN_TRANSFER_FUNCTION_SIGNATURE,
|
||||||
} = require('./components/send/send-constants')
|
} = require('./components/send/send-constants')
|
||||||
|
|
||||||
@ -116,6 +115,8 @@ SendTransactionScreen.prototype.updateGas = function () {
|
|||||||
const tokenBalancePromise = tokenContract
|
const tokenBalancePromise = tokenContract
|
||||||
? tokenContract.balanceOf(from.address)
|
? tokenContract.balanceOf(from.address)
|
||||||
: Promise.resolve()
|
: Promise.resolve()
|
||||||
|
tokenBalancePromise
|
||||||
|
.then(usersToken => this.updateSendTokenBalance(usersToken))
|
||||||
|
|
||||||
if (!editingTransactionId) {
|
if (!editingTransactionId) {
|
||||||
const estimateGasParams = getParamsForGasEstimate(selectedAddress, symbol, data)
|
const estimateGasParams = getParamsForGasEstimate(selectedAddress, symbol, data)
|
||||||
@ -124,18 +125,14 @@ SendTransactionScreen.prototype.updateGas = function () {
|
|||||||
.all([
|
.all([
|
||||||
getGasPrice(),
|
getGasPrice(),
|
||||||
estimateGas(estimateGasParams),
|
estimateGas(estimateGasParams),
|
||||||
tokenBalancePromise,
|
|
||||||
])
|
])
|
||||||
.then(([gasPrice, gas, usersToken]) => {
|
.then(([gasPrice, gas]) => {
|
||||||
const newGasTotal = this.getGasTotal(gas, gasPrice)
|
const newGasTotal = this.getGasTotal(gas, gasPrice)
|
||||||
updateGasTotal(newGasTotal)
|
updateGasTotal(newGasTotal)
|
||||||
this.updateSendTokenBalance(usersToken)
|
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
const newGasTotal = this.getGasTotal(gasLimit, gasPrice)
|
const newGasTotal = this.getGasTotal(gasLimit, gasPrice)
|
||||||
updateGasTotal(newGasTotal)
|
updateGasTotal(newGasTotal)
|
||||||
tokenBalancePromise
|
|
||||||
.then(usersToken => this.updateSendTokenBalance(usersToken))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,14 +161,14 @@ SendTransactionScreen.prototype.componentDidUpdate = function (prevProps) {
|
|||||||
network: prevNetwork,
|
network: prevNetwork,
|
||||||
} = prevProps
|
} = prevProps
|
||||||
|
|
||||||
const notFirstRender = [prevBalance, prevGasTotal].every(n => n !== null)
|
const uninitialized = [prevBalance, prevGasTotal].every(n => n === null)
|
||||||
|
|
||||||
const balanceHasChanged = balance !== prevBalance
|
const balanceHasChanged = balance !== prevBalance
|
||||||
const gasTotalHasChange = gasTotal !== prevGasTotal
|
const gasTotalHasChange = gasTotal !== prevGasTotal
|
||||||
const tokenBalanceHasChanged = selectedToken && tokenBalance !== prevTokenBalance
|
const tokenBalanceHasChanged = selectedToken && tokenBalance !== prevTokenBalance
|
||||||
const amountValidationChange = balanceHasChanged || gasTotalHasChange || tokenBalanceHasChanged
|
const amountValidationChange = balanceHasChanged || gasTotalHasChange || tokenBalanceHasChanged
|
||||||
|
|
||||||
if (notFirstRender) {
|
if (!uninitialized) {
|
||||||
if (amountValidationChange) {
|
if (amountValidationChange) {
|
||||||
this.validateAmount(amount)
|
this.validateAmount(amount)
|
||||||
}
|
}
|
||||||
@ -381,14 +378,19 @@ SendTransactionScreen.prototype.validateAmount = function (value) {
|
|||||||
const amount = value
|
const amount = value
|
||||||
|
|
||||||
let amountError = null
|
let amountError = null
|
||||||
const sufficientBalance = isBalanceSufficient({
|
|
||||||
amount: selectedToken ? '0x0' : amount,
|
let sufficientBalance = true
|
||||||
gasTotal,
|
|
||||||
balance,
|
if (gasTotal) {
|
||||||
primaryCurrency,
|
sufficientBalance = isBalanceSufficient({
|
||||||
amountConversionRate,
|
amount: selectedToken ? '0x0' : amount,
|
||||||
conversionRate,
|
gasTotal,
|
||||||
})
|
balance,
|
||||||
|
primaryCurrency,
|
||||||
|
amountConversionRate,
|
||||||
|
conversionRate,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
let sufficientTokens
|
let sufficientTokens
|
||||||
if (selectedToken) {
|
if (selectedToken) {
|
||||||
@ -404,7 +406,7 @@ SendTransactionScreen.prototype.validateAmount = function (value) {
|
|||||||
{ value: amount, fromNumericBase: 'hex' },
|
{ value: amount, fromNumericBase: 'hex' },
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!sufficientBalance) {
|
if (conversionRate && !sufficientBalance) {
|
||||||
amountError = 'Insufficient funds.'
|
amountError = 'Insufficient funds.'
|
||||||
} else if (selectedToken && !sufficientTokens) {
|
} else if (selectedToken && !sufficientTokens) {
|
||||||
amountError = 'Insufficient tokens.'
|
amountError = 'Insufficient tokens.'
|
||||||
@ -461,7 +463,7 @@ SendTransactionScreen.prototype.renderGasRow = function () {
|
|||||||
conversionRate,
|
conversionRate,
|
||||||
convertedCurrency,
|
convertedCurrency,
|
||||||
showCustomizeGasModal,
|
showCustomizeGasModal,
|
||||||
gasTotal = MIN_GAS_TOTAL,
|
gasTotal,
|
||||||
} = this.props
|
} = this.props
|
||||||
|
|
||||||
return h('div.send-v2__form-row', [
|
return h('div.send-v2__form-row', [
|
||||||
@ -477,12 +479,6 @@ SendTransactionScreen.prototype.renderGasRow = function () {
|
|||||||
onClick: showCustomizeGasModal,
|
onClick: showCustomizeGasModal,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
h('div.send-v2__sliders-icon-container', {
|
|
||||||
onClick: showCustomizeGasModal,
|
|
||||||
}, [
|
|
||||||
h('i.fa.fa-sliders.send-v2__sliders-icon'),
|
|
||||||
]),
|
|
||||||
|
|
||||||
]),
|
]),
|
||||||
|
|
||||||
])
|
])
|
||||||
@ -533,6 +529,7 @@ SendTransactionScreen.prototype.renderFooter = function () {
|
|||||||
const {
|
const {
|
||||||
goHome,
|
goHome,
|
||||||
clearSend,
|
clearSend,
|
||||||
|
gasTotal,
|
||||||
errors: { amount: amountError, to: toError },
|
errors: { amount: amountError, to: toError },
|
||||||
} = this.props
|
} = this.props
|
||||||
|
|
||||||
@ -546,7 +543,7 @@ SendTransactionScreen.prototype.renderFooter = function () {
|
|||||||
},
|
},
|
||||||
}, 'Cancel'),
|
}, 'Cancel'),
|
||||||
h('button.btn-clear.send-v2__next-btn', {
|
h('button.btn-clear.send-v2__next-btn', {
|
||||||
disabled: !noErrors,
|
disabled: !noErrors || !gasTotal,
|
||||||
onClick: event => this.onSubmit(event),
|
onClick: event => this.onSubmit(event),
|
||||||
}, 'Next'),
|
}, 'Next'),
|
||||||
])
|
])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user