aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/helpers/conversions.util.js
diff options
context:
space:
mode:
authorAlexander Tseung <alextsg@gmail.com>2018-09-01 03:14:06 +0800
committerAlexander Tseung <alextsg@gmail.com>2018-09-13 10:48:51 +0800
commit702b7568820d7a695f191df6bf44c76b37fdc7d8 (patch)
treeccec9173e15bd7d455ee8c0137f9c3f53af093e8 /ui/app/helpers/conversions.util.js
parente5ca2aac6f123e3e1db5e18c5854351c58af42b2 (diff)
downloadtangerine-wallet-browser-702b7568820d7a695f191df6bf44c76b37fdc7d8.tar.gz
tangerine-wallet-browser-702b7568820d7a695f191df6bf44c76b37fdc7d8.tar.zst
tangerine-wallet-browser-702b7568820d7a695f191df6bf44c76b37fdc7d8.zip
Allow denominations in CurrencyDisplay component
Diffstat (limited to 'ui/app/helpers/conversions.util.js')
-rw-r--r--ui/app/helpers/conversions.util.js38
1 files changed, 26 insertions, 12 deletions
diff --git a/ui/app/helpers/conversions.util.js b/ui/app/helpers/conversions.util.js
index 1dec216fa..74802c86b 100644
--- a/ui/app/helpers/conversions.util.js
+++ b/ui/app/helpers/conversions.util.js
@@ -1,4 +1,5 @@
import { conversionUtil } from '../conversion-util'
+import { ETH, GWEI, WEI } from '../constants/common'
export function hexToDecimal (hexValue) {
return conversionUtil(hexValue, {
@@ -7,16 +8,27 @@ export function hexToDecimal (hexValue) {
})
}
-export function getEthFromWeiHex ({
- value,
- conversionRate,
-}) {
- return getValueFromWeiHex({
- value,
- conversionRate,
- toCurrency: 'ETH',
- numberOfDecimals: 6,
- })
+export function getEthConversionFromWeiHex ({ value, conversionRate, numberOfDecimals = 6 }) {
+ const denominations = [ETH, GWEI]
+
+ let nonZeroDenomination
+
+ for (let i = 0; i < denominations.length; i++) {
+ const convertedValue = getValueFromWeiHex({
+ value,
+ conversionRate,
+ toCurrency: ETH,
+ numberOfDecimals,
+ toDenomination: denominations[i],
+ })
+
+ if (convertedValue !== '0' || i === denominations.length - 1) {
+ nonZeroDenomination = `${convertedValue} ${denominations[i]}`
+ break
+ }
+ }
+
+ return nonZeroDenomination
}
export function getValueFromWeiHex ({
@@ -24,14 +36,16 @@ export function getValueFromWeiHex ({
toCurrency,
conversionRate,
numberOfDecimals,
+ toDenomination,
}) {
return conversionUtil(value, {
fromNumericBase: 'hex',
toNumericBase: 'dec',
- fromCurrency: 'ETH',
+ fromCurrency: ETH,
toCurrency,
numberOfDecimals,
- fromDenomination: 'WEI',
+ fromDenomination: WEI,
+ toDenomination,
conversionRate,
})
}