From 05e21208146c65325330746a7860ce086f10e345 Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Wed, 3 Jul 2019 18:03:44 -0230 Subject: Version 6.7.2 gas limit fix (#6786) * Introduce delay for eth_estimateGas calls with in test * Add test that fails when gas estimates of contract method calls without gas are too high. * Get transaction gas data from unApprovedTxs instead of confirmTransaction * Fix selection of gas data in gas-modal-page-container.container * Lint changes related to Version-6.7.2-gasLimitFix * Fix e2e tests on Version-6.7.2-gasLimitFix * Fix unit and integration tests for changes from Version-6.7.2-gasLimitFix * more e2e fixes * Add assertions for transaction values on confirm screen * Fix display of transaction amount on confirm screen. --- ui/app/selectors/confirm-transaction.js | 60 ++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) (limited to 'ui/app/selectors/confirm-transaction.js') diff --git a/ui/app/selectors/confirm-transaction.js b/ui/app/selectors/confirm-transaction.js index 9b5eda82f..82df4e776 100644 --- a/ui/app/selectors/confirm-transaction.js +++ b/ui/app/selectors/confirm-transaction.js @@ -1,7 +1,17 @@ import { createSelector } from 'reselect' import txHelper from '../../lib/tx-helper' import { calcTokenAmount } from '../helpers/utils/token-util' -import { roundExponential } from '../helpers/utils/confirm-tx.util' +import { + roundExponential, + getValueFromWeiHex, + getHexGasTotal, + getTransactionFee, + addFiat, + addEth, +} from '../helpers/utils/confirm-tx.util' +import { + sumHexes, +} from '../helpers/utils/transactions.util' const unapprovedTxsSelector = state => state.metamask.unapprovedTxs const unapprovedMsgsSelector = state => state.metamask.unapprovedMsgs @@ -207,3 +217,51 @@ export const contractExchangeRateSelector = createSelector( tokenAddressSelector, (contractExchangeRates, tokenAddress) => contractExchangeRates[tokenAddress] ) + +export const transactionFeeSelector = function (state, txData) { + const currentCurrency = currentCurrencySelector(state) + const conversionRate = conversionRateSelector(state) + const nativeCurrency = getNativeCurrency(state) + + const { txParams: { value = '0x0', gas: gasLimit = '0x0', gasPrice = '0x0' } = {} } = txData + + const fiatTransactionAmount = getValueFromWeiHex({ + value, fromCurrency: nativeCurrency, toCurrency: currentCurrency, conversionRate, numberOfDecimals: 2, + }) + const ethTransactionAmount = getValueFromWeiHex({ + value, fromCurrency: nativeCurrency, toCurrency: nativeCurrency, conversionRate, numberOfDecimals: 6, + }) + + const hexTransactionFee = getHexGasTotal({ gasLimit, gasPrice }) + + const fiatTransactionFee = getTransactionFee({ + value: hexTransactionFee, + fromCurrency: nativeCurrency, + toCurrency: currentCurrency, + numberOfDecimals: 2, + conversionRate, + }) + const ethTransactionFee = getTransactionFee({ + value: hexTransactionFee, + fromCurrency: nativeCurrency, + toCurrency: nativeCurrency, + numberOfDecimals: 6, + conversionRate, + }) + + const fiatTransactionTotal = addFiat(fiatTransactionFee, fiatTransactionAmount) + const ethTransactionTotal = addEth(ethTransactionFee, ethTransactionAmount) + const hexTransactionTotal = sumHexes(value, hexTransactionFee) + + return { + hexTransactionAmount: value, + fiatTransactionAmount, + ethTransactionAmount, + hexTransactionFee, + fiatTransactionFee, + ethTransactionFee, + fiatTransactionTotal, + ethTransactionTotal, + hexTransactionTotal, + } +} -- cgit