aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/selectors
diff options
context:
space:
mode:
authorDan J Miller <danjm.com@gmail.com>2019-07-04 04:33:44 +0800
committerDan Miller <danjm.com@gmail.com>2019-07-05 00:44:03 +0800
commit05e21208146c65325330746a7860ce086f10e345 (patch)
treea4d5b364be451f43e4dc44e3da143a2d7e9b6cda /ui/app/selectors
parent397e0d128d034d10ab3f44641128f3aef99355a9 (diff)
downloadtangerine-wallet-browser-05e21208146c65325330746a7860ce086f10e345.tar.gz
tangerine-wallet-browser-05e21208146c65325330746a7860ce086f10e345.tar.zst
tangerine-wallet-browser-05e21208146c65325330746a7860ce086f10e345.zip
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.
Diffstat (limited to 'ui/app/selectors')
-rw-r--r--ui/app/selectors/confirm-transaction.js60
1 files changed, 59 insertions, 1 deletions
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,
+ }
+}