aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ui/app/conversion-util.js18
-rw-r--r--ui/app/send.js9
2 files changed, 18 insertions, 9 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,
});
diff --git a/ui/app/send.js b/ui/app/send.js
index 2e6409f32..5643d927b 100644
--- a/ui/app/send.js
+++ b/ui/app/send.js
@@ -22,7 +22,6 @@ const {
const { stripHexPrefix, addHexPrefix } = require('ethereumjs-util')
const { isHex, numericBalance, isValidAddress, allNull } = require('./util')
const { conversionUtil, conversionGreaterThan } = require('./conversion-util')
-const BigNumber = require('bignumber.js')
module.exports = connect(mapStateToProps)(SendTransactionScreen)
@@ -470,18 +469,14 @@ SendTransactionScreen.prototype.getAmountToSend = function (amount) {
const { activeCurrency } = this.state
const { conversionRate } = this.props
- // TODO: need a clean way to integrate this into conversionUtil
- const sendConversionRate = activeCurrency === 'ETH'
- ? conversionRate
- : new BigNumber(1.0).div(conversionRate)
-
return conversionUtil(amount, {
fromNumericBase: 'dec',
toNumericBase: 'hex',
fromCurrency: activeCurrency,
toCurrency: 'ETH',
toDenomination: 'WEI',
- conversionRate: sendConversionRate,
+ conversionRate,
+ invertConversionRate: activeCurrency !== 'ETH',
})
}