aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/conversion-util.js
diff options
context:
space:
mode:
authorDan <danjm.com@gmail.com>2017-10-06 23:21:02 +0800
committerChi Kei Chan <chikeichan@gmail.com>2017-10-09 08:49:52 +0800
commitdb1258f3de88f14cd54e2b4fd1cecc62cf6361e5 (patch)
tree2ec138204631eaae2ac6ce6c9986a751070ae02a /ui/app/conversion-util.js
parent49f76d27a9967cbeff0ba5b3d41277c558999472 (diff)
downloadtangerine-wallet-browser-db1258f3de88f14cd54e2b4fd1cecc62cf6361e5.tar
tangerine-wallet-browser-db1258f3de88f14cd54e2b4fd1cecc62cf6361e5.tar.gz
tangerine-wallet-browser-db1258f3de88f14cd54e2b4fd1cecc62cf6361e5.tar.bz2
tangerine-wallet-browser-db1258f3de88f14cd54e2b4fd1cecc62cf6361e5.tar.lz
tangerine-wallet-browser-db1258f3de88f14cd54e2b4fd1cecc62cf6361e5.tar.xz
tangerine-wallet-browser-db1258f3de88f14cd54e2b4fd1cecc62cf6361e5.tar.zst
tangerine-wallet-browser-db1258f3de88f14cd54e2b4fd1cecc62cf6361e5.zip
Conversion util can invert conversion rate
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 37877d12c..20f77b35b 100644
--- a/ui/app/conversion-util.js
+++ b/ui/app/conversion-util.js
@@ -36,6 +36,7 @@ const BIG_NUMBER_WEI_MULTIPLIER = new BigNumber('1000000000000000000')
// Individual Setters
const convert = R.invoker(1, 'times')
const round = R.invoker(2, 'toFormat')(R.__, BigNumber.ROUND_DOWN)
+const invertConversionRate = conversionRate => () => new BigNumber(1.0).div(conversionRate)
// Setter Maps
const toBigNumber = {
@@ -63,13 +64,23 @@ const fromAndToCurrencyPropsNotEqual = R.compose(
)
// Lens
-const valuePropertyLense = R.over(R.lensProp('value'))
+const valuePropertyLens = R.over(R.lensProp('value'))
+const conversionRateLens = R.over(R.lensProp('conversionRate'))
+
+// conditional conversionRate setting wrapper
+const whenPredSetCRWithPropAndSetter = (pred, prop, setter) => R.when(
+ pred,
+ R.converge(
+ conversionRateLens,
+ [R.pipe(R.prop(prop), setter), R.identity]
+ )
+)
// conditional 'value' setting wrappers
const whenPredSetWithPropAndSetter = (pred, prop, setter) => R.when(
pred,
R.converge(
- valuePropertyLense,
+ valuePropertyLens,
[R.pipe(R.prop(prop), setter), R.identity]
)
)
@@ -81,6 +92,7 @@ const whenPropApplySetterMap = (prop, setterMap) => whenPredSetWithPropAndSetter
// Conversion utility function
const converter = R.pipe(
+ whenPredSetCRWithPropAndSetter(R.prop('invertConversionRate'), 'conversionRate', invertConversionRate),
whenPropApplySetterMap('fromNumericBase', toBigNumber),
whenPropApplySetterMap('fromDenomination', toNormalizedDenomination),
whenPredSetWithPropAndSetter(fromAndToCurrencyPropsNotEqual, 'conversionRate', convert),
@@ -101,6 +113,7 @@ const conversionUtil = (value, {
numberOfDecimals,
conversionRate,
ethToUSDRate,
+ invertConversionRate,
}) => converter({
fromCurrency,
toCurrency,
@@ -111,6 +124,7 @@ const conversionUtil = (value, {
numberOfDecimals,
conversionRate,
ethToUSDRate,
+ invertConversionRate,
value,
});