diff options
author | Alexander Tseung <alextsg@users.noreply.github.com> | 2018-09-13 11:07:59 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-13 11:07:59 +0800 |
commit | 16d6cd5eb90e9720799f9a69e9c4e7d66d2fa89b (patch) | |
tree | f497f9f7d991b290f48cf7e5120a2f2e95d8f81f /ui/app/helpers/conversions.util.js | |
parent | 014240b066585f5983a4e6d65d6223f235044380 (diff) | |
parent | f1a309e0cc110060cc56252ec5f7626ca6403fab (diff) | |
download | tangerine-wallet-browser-16d6cd5eb90e9720799f9a69e9c4e7d66d2fa89b.tar tangerine-wallet-browser-16d6cd5eb90e9720799f9a69e9c4e7d66d2fa89b.tar.gz tangerine-wallet-browser-16d6cd5eb90e9720799f9a69e9c4e7d66d2fa89b.tar.bz2 tangerine-wallet-browser-16d6cd5eb90e9720799f9a69e9c4e7d66d2fa89b.tar.lz tangerine-wallet-browser-16d6cd5eb90e9720799f9a69e9c4e7d66d2fa89b.tar.xz tangerine-wallet-browser-16d6cd5eb90e9720799f9a69e9c4e7d66d2fa89b.tar.zst tangerine-wallet-browser-16d6cd5eb90e9720799f9a69e9c4e7d66d2fa89b.zip |
Merge pull request #5182 from MetaMask/tx-activity
Add Transaction Details to the Transaction List view
Diffstat (limited to 'ui/app/helpers/conversions.util.js')
-rw-r--r-- | ui/app/helpers/conversions.util.js | 38 |
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..5204faa1f 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, WEI] + + 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, }) } |