aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/conversion-util.js
diff options
context:
space:
mode:
authorbrunobar79 <brunobar79@gmail.com>2018-07-04 02:21:17 +0800
committerbrunobar79 <brunobar79@gmail.com>2018-07-04 02:21:17 +0800
commit595447ccac0c6d178d63850d45f0ad5456964e4f (patch)
tree61b83e1ba63615351da8e4c2dc7b446353411c9d /ui/app/conversion-util.js
parent11736e6318182ab5b43430410a46059e5f46ad52 (diff)
parent2e9bd7e9d101287b4466475561df9131f0ef56a6 (diff)
downloadtangerine-wallet-browser-595447ccac0c6d178d63850d45f0ad5456964e4f.tar.gz
tangerine-wallet-browser-595447ccac0c6d178d63850d45f0ad5456964e4f.tar.zst
tangerine-wallet-browser-595447ccac0c6d178d63850d45f0ad5456964e4f.zip
Merge remote-tracking branch 'upstream/develop' into HEAD
Diffstat (limited to 'ui/app/conversion-util.js')
-rw-r--r--ui/app/conversion-util.js18
1 files changed, 16 insertions, 2 deletions
diff --git a/ui/app/conversion-util.js b/ui/app/conversion-util.js
index d484ed16d..a7a226cc5 100644
--- a/ui/app/conversion-util.js
+++ b/ui/app/conversion-util.js
@@ -11,7 +11,8 @@
* @param {string} [options.fromNumericBase = 'hex' | 'dec' | 'BN'] The numeric basic of the passed value.
* @param {string} [options.toNumericBase = 'hex' | 'dec' | 'BN'] The desired numeric basic of the result.
* @param {string} [options.fromDenomination = 'WEI'] The denomination of the passed value
-* @param {number} [options.numberOfDecimals] The desired number of in the result
+* @param {string} [options.numberOfDecimals] The desired number of decimals in the result
+* @param {string} [options.roundDown] The desired number of decimals to round down to
* @param {number} [options.conversionRate] The rate to use to make the fromCurrency -> toCurrency conversion
* @returns {(number | string | BN)}
*
@@ -38,6 +39,7 @@ const BIG_NUMBER_GWEI_MULTIPLIER = new BigNumber('1000000000')
// Individual Setters
const convert = R.invoker(1, 'times')
const round = R.invoker(2, 'round')(R.__, BigNumber.ROUND_HALF_DOWN)
+const roundDown = R.invoker(2, 'round')(R.__, BigNumber.ROUND_DOWN)
const invertConversionRate = conversionRate => () => new BigNumber(1.0).div(conversionRate)
const decToBigNumberViaString = n => R.pipe(String, toBigNumber['dec'])
@@ -104,6 +106,7 @@ const converter = R.pipe(
whenPredSetWithPropAndSetter(fromAndToCurrencyPropsNotEqual, 'conversionRate', convert),
whenPropApplySetterMap('toDenomination', toSpecifiedDenomination),
whenPredSetWithPropAndSetter(R.prop('numberOfDecimals'), 'numberOfDecimals', round),
+ whenPredSetWithPropAndSetter(R.prop('roundDown'), 'roundDown', roundDown),
whenPropApplySetterMap('toNumericBase', baseChange),
R.view(R.lensProp('value'))
)
@@ -137,7 +140,7 @@ const addCurrencies = (a, b, options = {}) => {
bBase,
...conversionOptions
} = options
- const value = (new BigNumber(a, aBase)).add(b, bBase)
+ const value = (new BigNumber(a.toString(), aBase)).add(b.toString(), bBase)
return converter({
value,
@@ -187,6 +190,16 @@ const conversionGreaterThan = (
return firstValue.gt(secondValue)
}
+const conversionLessThan = (
+ { ...firstProps },
+ { ...secondProps },
+) => {
+ const firstValue = converter({ ...firstProps })
+ const secondValue = converter({ ...secondProps })
+
+ return firstValue.lt(secondValue)
+}
+
const conversionMax = (
{ ...firstProps },
{ ...secondProps },
@@ -226,6 +239,7 @@ module.exports = {
addCurrencies,
multiplyCurrencies,
conversionGreaterThan,
+ conversionLessThan,
conversionGTE,
conversionLTE,
conversionMax,