|
|
@ -85,6 +85,20 @@ SendTransactionScreen.prototype.componentWillMount = function () { |
|
|
|
const { |
|
|
|
const { |
|
|
|
updateTokenExchangeRate, |
|
|
|
updateTokenExchangeRate, |
|
|
|
selectedToken = {}, |
|
|
|
selectedToken = {}, |
|
|
|
|
|
|
|
} = this.props |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { symbol } = selectedToken || {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (symbol) { |
|
|
|
|
|
|
|
updateTokenExchangeRate(symbol) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.updateGas() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SendTransactionScreen.prototype.updateGas = function () { |
|
|
|
|
|
|
|
const { |
|
|
|
|
|
|
|
selectedToken = {}, |
|
|
|
getGasPrice, |
|
|
|
getGasPrice, |
|
|
|
estimateGas, |
|
|
|
estimateGas, |
|
|
|
selectedAddress, |
|
|
|
selectedAddress, |
|
|
@ -96,17 +110,16 @@ SendTransactionScreen.prototype.componentWillMount = function () { |
|
|
|
gasPrice, |
|
|
|
gasPrice, |
|
|
|
gasLimit, |
|
|
|
gasLimit, |
|
|
|
} = this.props |
|
|
|
} = this.props |
|
|
|
|
|
|
|
|
|
|
|
const { symbol } = selectedToken || {} |
|
|
|
const { symbol } = selectedToken || {} |
|
|
|
|
|
|
|
|
|
|
|
if (symbol) { |
|
|
|
const tokenBalancePromise = tokenContract |
|
|
|
updateTokenExchangeRate(symbol) |
|
|
|
? tokenContract.balanceOf(from.address) |
|
|
|
} |
|
|
|
: Promise.resolve() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!editingTransactionId) { |
|
|
|
const estimateGasParams = getParamsForGasEstimate(selectedAddress, symbol, data) |
|
|
|
const estimateGasParams = getParamsForGasEstimate(selectedAddress, symbol, data) |
|
|
|
|
|
|
|
|
|
|
|
const tokenBalancePromise = tokenContract && tokenContract.balanceOf(from.address) |
|
|
|
|
|
|
|
let newGasTotal |
|
|
|
|
|
|
|
if (!editingTransactionId) { |
|
|
|
|
|
|
|
Promise |
|
|
|
Promise |
|
|
|
.all([ |
|
|
|
.all([ |
|
|
|
getGasPrice(), |
|
|
|
getGasPrice(), |
|
|
@ -114,25 +127,24 @@ SendTransactionScreen.prototype.componentWillMount = function () { |
|
|
|
tokenBalancePromise, |
|
|
|
tokenBalancePromise, |
|
|
|
]) |
|
|
|
]) |
|
|
|
.then(([gasPrice, gas, usersToken]) => { |
|
|
|
.then(([gasPrice, gas, usersToken]) => { |
|
|
|
|
|
|
|
const newGasTotal = this.getGasTotal(gas, gasPrice) |
|
|
|
const newGasTotal = multiplyCurrencies(gas, gasPrice, { |
|
|
|
|
|
|
|
toNumericBase: 'hex', |
|
|
|
|
|
|
|
multiplicandBase: 16, |
|
|
|
|
|
|
|
multiplierBase: 16, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
updateGasTotal(newGasTotal) |
|
|
|
updateGasTotal(newGasTotal) |
|
|
|
this.updateSendTokenBalance(usersToken) |
|
|
|
this.updateSendTokenBalance(usersToken) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
newGasTotal = multiplyCurrencies(gasLimit, gasPrice, { |
|
|
|
const newGasTotal = this.getGasTotal(gasLimit, gasPrice) |
|
|
|
|
|
|
|
updateGasTotal(newGasTotal) |
|
|
|
|
|
|
|
tokenBalancePromise |
|
|
|
|
|
|
|
.then(usersToken => this.updateSendTokenBalance(usersToken)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SendTransactionScreen.prototype.getGasTotal = function (gasLimit, gasPrice) { |
|
|
|
|
|
|
|
return multiplyCurrencies(gasLimit, gasPrice, { |
|
|
|
toNumericBase: 'hex', |
|
|
|
toNumericBase: 'hex', |
|
|
|
multiplicandBase: 16, |
|
|
|
multiplicandBase: 16, |
|
|
|
multiplierBase: 16, |
|
|
|
multiplierBase: 16, |
|
|
|
}) |
|
|
|
}) |
|
|
|
updateGasTotal(newGasTotal) |
|
|
|
|
|
|
|
tokenBalancePromise && tokenBalancePromise.then( |
|
|
|
|
|
|
|
usersToken => this.updateSendTokenBalance(usersToken)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
SendTransactionScreen.prototype.componentDidUpdate = function (prevProps) { |
|
|
|
SendTransactionScreen.prototype.componentDidUpdate = function (prevProps) { |
|
|
@ -142,11 +154,14 @@ SendTransactionScreen.prototype.componentDidUpdate = function (prevProps) { |
|
|
|
tokenBalance, |
|
|
|
tokenBalance, |
|
|
|
amount, |
|
|
|
amount, |
|
|
|
selectedToken, |
|
|
|
selectedToken, |
|
|
|
|
|
|
|
network, |
|
|
|
} = this.props |
|
|
|
} = this.props |
|
|
|
|
|
|
|
|
|
|
|
const { |
|
|
|
const { |
|
|
|
from: { balance: prevBalance }, |
|
|
|
from: { balance: prevBalance }, |
|
|
|
gasTotal: prevGasTotal, |
|
|
|
gasTotal: prevGasTotal, |
|
|
|
tokenBalance: prevTokenBalance, |
|
|
|
tokenBalance: prevTokenBalance, |
|
|
|
|
|
|
|
network: prevNetwork, |
|
|
|
} = prevProps |
|
|
|
} = prevProps |
|
|
|
|
|
|
|
|
|
|
|
const notFirstRender = [prevBalance, prevGasTotal].every(n => n !== null) |
|
|
|
const notFirstRender = [prevBalance, prevGasTotal].every(n => n !== null) |
|
|
@ -156,9 +171,15 @@ SendTransactionScreen.prototype.componentDidUpdate = function (prevProps) { |
|
|
|
const tokenBalanceHasChanged = selectedToken && tokenBalance !== prevTokenBalance |
|
|
|
const tokenBalanceHasChanged = selectedToken && tokenBalance !== prevTokenBalance |
|
|
|
const amountValidationChange = balanceHasChanged || gasTotalHasChange || tokenBalanceHasChanged |
|
|
|
const amountValidationChange = balanceHasChanged || gasTotalHasChange || tokenBalanceHasChanged |
|
|
|
|
|
|
|
|
|
|
|
if (notFirstRender && amountValidationChange) { |
|
|
|
if (notFirstRender) { |
|
|
|
|
|
|
|
if (amountValidationChange) { |
|
|
|
this.validateAmount(amount) |
|
|
|
this.validateAmount(amount) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (network !== prevNetwork && network !== 'loading') { |
|
|
|
|
|
|
|
this.updateGas() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
SendTransactionScreen.prototype.renderHeaderIcon = function () { |
|
|
|
SendTransactionScreen.prototype.renderHeaderIcon = function () { |
|
|
|