@ -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,7 +378,11 @@ SendTransactionScreen.prototype.validateAmount = function (value) {
const amount = value
const amount = value
let amountError = null
let amountError = null
const sufficientBalance = isBalanceSufficient ( {
let sufficientBalance = true
if ( gasTotal ) {
sufficientBalance = isBalanceSufficient ( {
amount : selectedToken ? '0x0' : amount ,
amount : selectedToken ? '0x0' : amount ,
gasTotal ,
gasTotal ,
balance ,
balance ,
@ -389,6 +390,7 @@ SendTransactionScreen.prototype.validateAmount = function (value) {
amountConversionRate ,
amountConversionRate ,
conversionRate ,
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' ) ,
] )
] )