aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Tseung <alextsg@gmail.com>2018-07-27 03:15:34 +0800
committerAlexander Tseung <alextsg@gmail.com>2018-07-28 03:22:10 +0800
commitd0c901d081e3b40a191dcb826fda7925d16df92c (patch)
tree13b8b5a75531f0bec35118bc5747ad39fe90c03a
parentcd2b67cdd956cd7f2a29f94292939a4bb939b7b3 (diff)
downloadtangerine-wallet-browser-d0c901d081e3b40a191dcb826fda7925d16df92c.tar
tangerine-wallet-browser-d0c901d081e3b40a191dcb826fda7925d16df92c.tar.gz
tangerine-wallet-browser-d0c901d081e3b40a191dcb826fda7925d16df92c.tar.bz2
tangerine-wallet-browser-d0c901d081e3b40a191dcb826fda7925d16df92c.tar.lz
tangerine-wallet-browser-d0c901d081e3b40a191dcb826fda7925d16df92c.tar.xz
tangerine-wallet-browser-d0c901d081e3b40a191dcb826fda7925d16df92c.tar.zst
tangerine-wallet-browser-d0c901d081e3b40a191dcb826fda7925d16df92c.zip
Round large exponential numbers
-rw-r--r--ui/app/components/pages/confirm-token-transaction-base/confirm-token-transaction-base.component.js7
-rw-r--r--ui/app/helpers/confirm-transaction/util.js9
-rw-r--r--ui/app/selectors/confirm-transaction.js13
3 files changed, 23 insertions, 6 deletions
diff --git a/ui/app/components/pages/confirm-token-transaction-base/confirm-token-transaction-base.component.js b/ui/app/components/pages/confirm-token-transaction-base/confirm-token-transaction-base.component.js
index 365ae216e..acaed383a 100644
--- a/ui/app/components/pages/confirm-token-transaction-base/confirm-token-transaction-base.component.js
+++ b/ui/app/components/pages/confirm-token-transaction-base/confirm-token-transaction-base.component.js
@@ -5,6 +5,7 @@ import {
formatCurrency,
convertTokenToFiat,
addFiat,
+ roundExponential,
} from '../../../helpers/confirm-transaction/util'
export default class ConfirmTokenTransactionBase extends Component {
@@ -42,7 +43,8 @@ export default class ConfirmTokenTransactionBase extends Component {
return this.context.t('noConversionRateAvailable')
} else {
const fiatTransactionAmount = this.getFiatTransactionAmount()
- return formatCurrency(fiatTransactionAmount, currentCurrency)
+ const roundedFiatTransactionAmount = roundExponential(fiatTransactionAmount)
+ return formatCurrency(roundedFiatTransactionAmount, currentCurrency)
}
}
@@ -54,7 +56,8 @@ export default class ConfirmTokenTransactionBase extends Component {
} else {
const fiatTransactionAmount = this.getFiatTransactionAmount()
const fiatTotal = addFiat(fiatTransactionAmount, fiatTransactionTotal)
- return formatCurrency(fiatTotal, currentCurrency)
+ const roundedFiatTotal = roundExponential(fiatTotal)
+ return formatCurrency(roundedFiatTotal, currentCurrency)
}
}
diff --git a/ui/app/helpers/confirm-transaction/util.js b/ui/app/helpers/confirm-transaction/util.js
index f015b2bf5..a37778c19 100644
--- a/ui/app/helpers/confirm-transaction/util.js
+++ b/ui/app/helpers/confirm-transaction/util.js
@@ -3,6 +3,7 @@ import currencies from 'currency-formatter/currencies'
import abi from 'human-standard-token-abi'
import abiDecoder from 'abi-decoder'
import ethUtil from 'ethereumjs-util'
+import BigNumber from 'bignumber.js'
abiDecoder.addABI(abi)
@@ -137,3 +138,11 @@ export function convertTokenToFiat ({
export function hasUnconfirmedTransactions (state) {
return unconfirmedTransactionsCountSelector(state) > 0
}
+
+export function roundExponential (value) {
+ const PRECISION = 4
+ const bigNumberValue = new BigNumber(value)
+
+ // In JS, numbers with exponentials greater than 20 get displayed as an exponential.
+ return bigNumberValue.e > 20 ? Number(bigNumberValue.toPrecision(PRECISION)) : value
+}
diff --git a/ui/app/selectors/confirm-transaction.js b/ui/app/selectors/confirm-transaction.js
index 8f8e0ea74..9548cf75e 100644
--- a/ui/app/selectors/confirm-transaction.js
+++ b/ui/app/selectors/confirm-transaction.js
@@ -1,6 +1,7 @@
import { createSelector } from 'reselect'
import txHelper from '../../lib/tx-helper'
import { calcTokenAmount } from '../token-util'
+import { roundExponential } from '../helpers/confirm-transaction/util'
const unapprovedTxsSelector = state => state.metamask.unapprovedTxs
const unapprovedMsgsSelector = state => state.metamask.unapprovedMsgs
@@ -133,7 +134,8 @@ export const tokenAmountAndToAddressSelector = createSelector(
const toParam = params.find(param => param.name === TOKEN_PARAM_TO)
const valueParam = params.find(param => param.name === TOKEN_PARAM_VALUE)
toAddress = toParam ? toParam.value : params[0].value
- tokenAmount = valueParam ? Number(valueParam.value) : Number(params[1].value)
+ const value = valueParam ? Number(valueParam.value) : Number(params[1].value)
+ tokenAmount = roundExponential(value)
}
return {
@@ -151,7 +153,8 @@ export const approveTokenAmountAndToAddressSelector = createSelector(
if (params && params.length) {
toAddress = params.find(param => param.name === TOKEN_PARAM_SPENDER).value
- tokenAmount = Number(params.find(param => param.name === TOKEN_PARAM_VALUE).value)
+ const value = Number(params.find(param => param.name === TOKEN_PARAM_VALUE).value)
+ tokenAmount = roundExponential(value)
}
return {
@@ -170,11 +173,13 @@ export const sendTokenTokenAmountAndToAddressSelector = createSelector(
if (params && params.length) {
toAddress = params.find(param => param.name === TOKEN_PARAM_TO).value
- tokenAmount = Number(params.find(param => param.name === TOKEN_PARAM_VALUE).value)
+ let value = Number(params.find(param => param.name === TOKEN_PARAM_VALUE).value)
if (tokenDecimals) {
- tokenAmount = calcTokenAmount(tokenAmount, tokenDecimals)
+ value = calcTokenAmount(value, tokenDecimals)
}
+
+ tokenAmount = roundExponential(value)
}
return {