diff options
author | Alexander Tseung <alextsg@gmail.com> | 2018-09-01 03:14:06 +0800 |
---|---|---|
committer | Alexander Tseung <alextsg@gmail.com> | 2018-09-13 10:48:51 +0800 |
commit | 702b7568820d7a695f191df6bf44c76b37fdc7d8 (patch) | |
tree | ccec9173e15bd7d455ee8c0137f9c3f53af093e8 /ui/app/helpers | |
parent | e5ca2aac6f123e3e1db5e18c5854351c58af42b2 (diff) | |
download | tangerine-wallet-browser-702b7568820d7a695f191df6bf44c76b37fdc7d8.tar tangerine-wallet-browser-702b7568820d7a695f191df6bf44c76b37fdc7d8.tar.gz tangerine-wallet-browser-702b7568820d7a695f191df6bf44c76b37fdc7d8.tar.bz2 tangerine-wallet-browser-702b7568820d7a695f191df6bf44c76b37fdc7d8.tar.lz tangerine-wallet-browser-702b7568820d7a695f191df6bf44c76b37fdc7d8.tar.xz tangerine-wallet-browser-702b7568820d7a695f191df6bf44c76b37fdc7d8.tar.zst tangerine-wallet-browser-702b7568820d7a695f191df6bf44c76b37fdc7d8.zip |
Allow denominations in CurrencyDisplay component
Diffstat (limited to 'ui/app/helpers')
-rw-r--r-- | ui/app/helpers/confirm-transaction/util.js | 2 | ||||
-rw-r--r-- | ui/app/helpers/conversions.util.js | 38 |
2 files changed, 28 insertions, 12 deletions
diff --git a/ui/app/helpers/confirm-transaction/util.js b/ui/app/helpers/confirm-transaction/util.js index d1a4994e4..bcac22500 100644 --- a/ui/app/helpers/confirm-transaction/util.js +++ b/ui/app/helpers/confirm-transaction/util.js @@ -58,6 +58,7 @@ export function getValueFromWeiHex ({ toCurrency, conversionRate, numberOfDecimals, + toDenomination, }) { return conversionUtil(value, { fromNumericBase: 'hex', @@ -66,6 +67,7 @@ export function getValueFromWeiHex ({ toCurrency, numberOfDecimals, fromDenomination: 'WEI', + toDenomination, conversionRate, }) } 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, }) } |