@ -7,6 +7,8 @@ import {
setGasPrice ,
setGasPrice ,
createSpeedUpTransaction ,
createSpeedUpTransaction ,
hideSidebar ,
hideSidebar ,
updateSendAmount ,
setGasTotal ,
} from '../../../../store/actions'
} from '../../../../store/actions'
import {
import {
setCustomGasPrice ,
setCustomGasPrice ,
@ -18,6 +20,7 @@ import {
} from '../../../../ducks/gas/gas.duck'
} from '../../../../ducks/gas/gas.duck'
import {
import {
hideGasButtonGroup ,
hideGasButtonGroup ,
updateSendErrors ,
} from '../../../../ducks/send/send.duck'
} from '../../../../ducks/send/send.duck'
import {
import {
updateGasAndCalculate ,
updateGasAndCalculate ,
@ -45,6 +48,9 @@ import {
getBasicGasEstimateBlockTime ,
getBasicGasEstimateBlockTime ,
isCustomPriceSafe ,
isCustomPriceSafe ,
} from '../../../../selectors/custom-gas'
} from '../../../../selectors/custom-gas'
import {
getTokenBalance ,
} from '../../../../pages/send/send.selectors'
import {
import {
submittedPendingTransactionsSelector ,
submittedPendingTransactionsSelector ,
} from '../../../../selectors/transactions'
} from '../../../../selectors/transactions'
@ -53,6 +59,7 @@ import {
} from '../../../../helpers/utils/confirm-tx.util'
} from '../../../../helpers/utils/confirm-tx.util'
import {
import {
addHexWEIsToDec ,
addHexWEIsToDec ,
subtractHexWEIsToDec ,
decEthToConvertedCurrency as ethTotalToConvertedCurrency ,
decEthToConvertedCurrency as ethTotalToConvertedCurrency ,
decGWEIToHexWEI ,
decGWEIToHexWEI ,
hexWEIToDecGWEI ,
hexWEIToDecGWEI ,
@ -66,6 +73,8 @@ import {
} from '../../../../pages/send/send.utils'
} from '../../../../pages/send/send.utils'
import { addHexPrefix } from 'ethereumjs-util'
import { addHexPrefix } from 'ethereumjs-util'
import { getAdjacentGasPrices , extrapolateY } from '../gas-price-chart/gas-price-chart.utils'
import { getAdjacentGasPrices , extrapolateY } from '../gas-price-chart/gas-price-chart.utils'
import { getMaxModeOn } from '../../../../pages/send/send-content/send-amount-row/amount-max-button/amount-max-button.selectors'
import { calcMaxAmount } from '../../../../pages/send/send-content/send-amount-row/amount-max-button/amount-max-button.utils'
const mapStateToProps = ( state , ownProps ) => {
const mapStateToProps = ( state , ownProps ) => {
const { transaction = { } } = ownProps
const { transaction = { } } = ownProps
@ -75,8 +84,6 @@ const mapStateToProps = (state, ownProps) => {
const { gasPrice : currentGasPrice , gas : currentGasLimit , value } = getTxParams ( state , transaction . id )
const { gasPrice : currentGasPrice , gas : currentGasLimit , value } = getTxParams ( state , transaction . id )
const customModalGasPriceInHex = getCustomGasPrice ( state ) || currentGasPrice
const customModalGasPriceInHex = getCustomGasPrice ( state ) || currentGasPrice
const customModalGasLimitInHex = getCustomGasLimit ( state ) || currentGasLimit
const customModalGasLimitInHex = getCustomGasLimit ( state ) || currentGasLimit
const gasTotal = calcGasTotal ( customModalGasLimitInHex , customModalGasPriceInHex )
const customGasTotal = calcGasTotal ( customModalGasLimitInHex , customModalGasPriceInHex )
const customGasTotal = calcGasTotal ( customModalGasLimitInHex , customModalGasPriceInHex )
const gasButtonInfo = getRenderableBasicEstimateData ( state , customModalGasLimitInHex )
const gasButtonInfo = getRenderableBasicEstimateData ( state , customModalGasLimitInHex )
@ -90,6 +97,8 @@ const mapStateToProps = (state, ownProps) => {
const customGasPrice = calcCustomGasPrice ( customModalGasPriceInHex )
const customGasPrice = calcCustomGasPrice ( customModalGasPriceInHex )
const maxModeOn = getMaxModeOn ( state )
const gasPrices = getEstimatedGasPrices ( state )
const gasPrices = getEstimatedGasPrices ( state )
const estimatedTimes = getEstimatedGasTimes ( state )
const estimatedTimes = getEstimatedGasTimes ( state )
const balance = getCurrentEthBalance ( state )
const balance = getCurrentEthBalance ( state )
@ -98,9 +107,13 @@ const mapStateToProps = (state, ownProps) => {
const isMainnet = getIsMainnet ( state )
const isMainnet = getIsMainnet ( state )
const showFiat = Boolean ( isMainnet || showFiatInTestnets )
const showFiat = Boolean ( isMainnet || showFiatInTestnets )
const insufficientBalance = ! isBalanceSufficient ( {
const newTotalEth = maxModeOn ? addHexWEIsToRenderableEth ( balance , '0x0' ) : addHexWEIsToRenderableEth ( value , customGasTotal )
const sendAmount = maxModeOn ? subtractHexWEIsFromRenderableEth ( balance , customGasTotal ) : addHexWEIsToRenderableEth ( value , '0x0' )
const insufficientBalance = maxModeOn ? false : ! isBalanceSufficient ( {
amount : value ,
amount : value ,
gasTotal ,
gasTotal : customGasTotal ,
balance ,
balance ,
conversionRate ,
conversionRate ,
} )
} )
@ -112,10 +125,12 @@ const mapStateToProps = (state, ownProps) => {
customModalGasLimitInHex ,
customModalGasLimitInHex ,
customGasPrice ,
customGasPrice ,
customGasLimit : calcCustomGasLimit ( customModalGasLimitInHex ) ,
customGasLimit : calcCustomGasLimit ( customModalGasLimitInHex ) ,
customGasTotal ,
newTotalFiat ,
newTotalFiat ,
currentTimeEstimate : getRenderableTimeEstimate ( customGasPrice , gasPrices , estimatedTimes ) ,
currentTimeEstimate : getRenderableTimeEstimate ( customGasPrice , gasPrices , estimatedTimes ) ,
blockTime : getBasicGasEstimateBlockTime ( state ) ,
blockTime : getBasicGasEstimateBlockTime ( state ) ,
customPriceIsSafe : isCustomPriceSafe ( state ) ,
customPriceIsSafe : isCustomPriceSafe ( state ) ,
maxModeOn ,
gasPriceButtonGroupProps : {
gasPriceButtonGroupProps : {
buttonDataLoading ,
buttonDataLoading ,
defaultActiveButtonIndex : getDefaultActiveButtonIndex ( gasButtonInfo , customModalGasPriceInHex ) ,
defaultActiveButtonIndex : getDefaultActiveButtonIndex ( gasButtonInfo , customModalGasPriceInHex ) ,
@ -129,12 +144,12 @@ const mapStateToProps = (state, ownProps) => {
estimatedTimesMax : estimatedTimes [ 0 ] ,
estimatedTimesMax : estimatedTimes [ 0 ] ,
} ,
} ,
infoRowProps : {
infoRowProps : {
originalTotalFiat : addHexWEIsToRenderableFiat ( value , g asTotal, currentCurrency , conversionRate ) ,
originalTotalFiat : addHexWEIsToRenderableFiat ( value , customG asTotal, currentCurrency , conversionRate ) ,
originalTotalEth : addHexWEIsToRenderableEth ( value , g asTotal) ,
originalTotalEth : addHexWEIsToRenderableEth ( value , customG asTotal) ,
newTotalFiat : showFiat ? newTotalFiat : '' ,
newTotalFiat : showFiat ? newTotalFiat : '' ,
newTotalEth : addHexWEIsToRenderableEth ( value , customGasTotal ) ,
newTotalEth ,
transactionFee : addHexWEIsToRenderableEth ( '0x0' , customGasTotal ) ,
transactionFee : addHexWEIsToRenderableEth ( '0x0' , customGasTotal ) ,
sendAmount : addHexWEIsToRenderableEth ( value , '0x0' ) ,
sendAmount ,
} ,
} ,
isSpeedUp : transaction . status === 'submitted' ,
isSpeedUp : transaction . status === 'submitted' ,
txId : transaction . id ,
txId : transaction . id ,
@ -142,6 +157,9 @@ const mapStateToProps = (state, ownProps) => {
gasEstimatesLoading ,
gasEstimatesLoading ,
isMainnet ,
isMainnet ,
isEthereumNetwork : isEthereumNetwork ( state ) ,
isEthereumNetwork : isEthereumNetwork ( state ) ,
selectedToken : getSelectedToken ( state ) ,
balance ,
tokenBalance : getTokenBalance ( state ) ,
}
}
}
}
@ -174,11 +192,16 @@ const mapDispatchToProps = dispatch => {
hideSidebar : ( ) => dispatch ( hideSidebar ( ) ) ,
hideSidebar : ( ) => dispatch ( hideSidebar ( ) ) ,
fetchGasEstimates : ( blockTime ) => dispatch ( fetchGasEstimates ( blockTime ) ) ,
fetchGasEstimates : ( blockTime ) => dispatch ( fetchGasEstimates ( blockTime ) ) ,
fetchBasicGasAndTimeEstimates : ( ) => dispatch ( fetchBasicGasAndTimeEstimates ( ) ) ,
fetchBasicGasAndTimeEstimates : ( ) => dispatch ( fetchBasicGasAndTimeEstimates ( ) ) ,
setGasTotal : ( total ) => dispatch ( setGasTotal ( total ) ) ,
setAmountToMax : ( maxAmountDataObject ) => {
dispatch ( updateSendErrors ( { amount : null } ) )
dispatch ( updateSendAmount ( calcMaxAmount ( maxAmountDataObject ) ) )
} ,
}
}
}
}
const mergeProps = ( stateProps , dispatchProps , ownProps ) => {
const mergeProps = ( stateProps , dispatchProps , ownProps ) => {
const { gasPriceButtonGroupProps , isConfirm , txId , isSpeedUp , insufficientBalance , customGasPrice } = stateProps
const { gasPriceButtonGroupProps , isConfirm , txId , isSpeedUp , insufficientBalance , maxModeOn , customGasPrice , customGasTotal , balance , selectedToken , tokenBalance } = stateProps
const {
const {
updateCustomGasPrice : dispatchUpdateCustomGasPrice ,
updateCustomGasPrice : dispatchUpdateCustomGasPrice ,
hideGasButtonGroup : dispatchHideGasButtonGroup ,
hideGasButtonGroup : dispatchHideGasButtonGroup ,
@ -188,6 +211,7 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => {
hideSidebar : dispatchHideSidebar ,
hideSidebar : dispatchHideSidebar ,
cancelAndClose : dispatchCancelAndClose ,
cancelAndClose : dispatchCancelAndClose ,
hideModal : dispatchHideModal ,
hideModal : dispatchHideModal ,
setAmountToMax : dispatchSetAmountToMax ,
... otherDispatchProps
... otherDispatchProps
} = dispatchProps
} = dispatchProps
@ -208,6 +232,14 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => {
dispatchHideGasButtonGroup ( )
dispatchHideGasButtonGroup ( )
dispatchCancelAndClose ( )
dispatchCancelAndClose ( )
}
}
if ( maxModeOn ) {
dispatchSetAmountToMax ( {
balance ,
gasTotal : customGasTotal ,
selectedToken ,
tokenBalance ,
} )
}
} ,
} ,
gasPriceButtonGroupProps : {
gasPriceButtonGroupProps : {
... gasPriceButtonGroupProps ,
... gasPriceButtonGroupProps ,
@ -258,6 +290,13 @@ function addHexWEIsToRenderableEth (aHexWEI, bHexWEI) {
) ( aHexWEI , bHexWEI )
) ( aHexWEI , bHexWEI )
}
}
function subtractHexWEIsFromRenderableEth ( aHexWEI , bHexWei ) {
return pipe (
subtractHexWEIsToDec ,
formatETHFee
) ( aHexWEI , bHexWei )
}
function addHexWEIsToRenderableFiat ( aHexWEI , bHexWEI , convertedCurrency , conversionRate ) {
function addHexWEIsToRenderableFiat ( aHexWEI , bHexWEI , convertedCurrency , conversionRate ) {
return pipe (
return pipe (
addHexWEIsToDec ,
addHexWEIsToDec ,