From 1e83835ba8cce0fdf794092a8c55b6c68664204a Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Tue, 12 Sep 2017 02:49:05 -0230 Subject: [New-UI] Confirm Screen restyle and connect to state (#2042) * Adds utility for converting currencies (WIP) * Implements confirm screen * Style tweaks. * Confirm screen total ammount now uses real data. * Confirm screen total ammount now uses real data. * Replace content divider with sibling css. * Replace section divider with scss. --- ui/app/conversion-util.js | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 ui/app/conversion-util.js (limited to 'ui/app/conversion-util.js') diff --git a/ui/app/conversion-util.js b/ui/app/conversion-util.js new file mode 100644 index 000000000..8f2214500 --- /dev/null +++ b/ui/app/conversion-util.js @@ -0,0 +1,50 @@ +const { + numericBalance, + parseBalance, + formatBalance, + normalizeToWei, + valueTable, +} = require('./util') +const hexToBn = require('../../app/scripts/lib/hex-to-bn') +const { BN } = require('ethereumjs-util') +const GWEI_MULTIPLIER = normalizeToWei(hexToBn(valueTable.gwei.toString(16)), 'gwei'); + +const conversionUtil = (value, { + fromCurrency, + toCurrency, + fromFormat, + toFormat, + precision = 2, + conversionRate, +}) => { + let result; + + if (fromFormat === 'BN') { + if (fromCurrency !== 'GWEI') { + result = normalizeToWei(value, 'gwei') + } + else { + result = value + } + + result = result.toString(16) + result = formatBalance(result, 9) + result = result.split(' ') + result = Number(result[0]) * 1000000000 + } + + if (fromCurrency === 'GWEI') { + result = result / 1000000000 + } + + if (toCurrency === 'USD') { + result = result * conversionRate + result = result.toFixed(precision) + } + + return result +}; + +module.exports = { + conversionUtil, +} \ No newline at end of file -- cgit v1.2.3 From 080890a46ec98814bce8680f561fae3b52d81ed2 Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 12 Sep 2017 18:08:02 -0230 Subject: Overhaul currency conversion utility and update calls to utility in pending-tx. --- ui/app/conversion-util.js | 141 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 100 insertions(+), 41 deletions(-) (limited to 'ui/app/conversion-util.js') diff --git a/ui/app/conversion-util.js b/ui/app/conversion-util.js index 8f2214500..5e1125194 100644 --- a/ui/app/conversion-util.js +++ b/ui/app/conversion-util.js @@ -1,49 +1,108 @@ -const { - numericBalance, - parseBalance, - formatBalance, - normalizeToWei, - valueTable, -} = require('./util') -const hexToBn = require('../../app/scripts/lib/hex-to-bn') -const { BN } = require('ethereumjs-util') -const GWEI_MULTIPLIER = normalizeToWei(hexToBn(valueTable.gwei.toString(16)), 'gwei'); +/* Currency Conversion Utility +* This utility function can be used for converting currency related values within metamask. +* The caller should be able to pass it a value, along with information about the value's +* numeric base, denomination and currency, and the desired numeric base, denomination and +* currency. It should return a single value. +* +* @param {(number | string | BN)} value The value to convert. +* @param {Object} [options] Options to specify details of the conversion +* @param {string} [options.fromCurrency = 'ETH' | 'USD'] The currency of the passed value +* @param {string} [options.toCurrency = 'ETH' | 'USD'] The desired currency of the result +* @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 {number} [options.conversionRate] The rate to use to make the fromCurrency -> toCurrency conversion +* @returns {(number | string | BN)} +* +* The utility passes value along with the options as a single object to the `converter` function. +* `converter` uses Ramda.js to apply a composition of conditional setters to the `value` property, depending +* on the accompanying options. Some of these conditional setters are selected via key-value maps, where +* the keys are specified in the options parameters and the values are setter functions. +*/ + +const BigNumber = require('bignumber.js') +const R = require('ramda') +const { stripHexPrefix } = require('ethereumjs-util') + +BigNumber.config({ + ROUNDING_MODE: BigNumber.ROUND_HALF_DOWN, +}) + +// Big Number Constants +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) + +// Setter Maps +const toBigNumber = { + hex: n => new BigNumber(stripHexPrefix(n), 16), + dec: n => new BigNumber(n, 10), + BN: n => new BigNumber(n.toString(16), 16), +} +const toNormalizedDenomination = { + WEI: bigNumber => bigNumber.div(BIG_NUMBER_WEI_MULTIPLIER) +} +const baseChange = { + hex: n => n.toString(16), + dec: n => n.toString(10), + BN: n => new BN(n.toString(16)), +} + +// Predicates +const fromAndToCurrencyPropsNotEqual = R.compose( + R.not, + R.eqBy(R.__, 'fromCurrency', 'toCurrency'), + R.flip(R.prop) +) + +// Lens +const valuePropertyLense = R.over(R.lensProp('value')) + +// conditional 'value' setting wrappers +const whenPredSetWithPropAndSetter = (pred, prop, setter) => R.when( + pred, + R.converge( + valuePropertyLense, + [R.pipe(R.prop(prop), setter), R.identity] + ) +) +const whenPropApplySetterMap = (prop, setterMap) => whenPredSetWithPropAndSetter( + R.prop(prop), + prop, + R.prop(R.__, setterMap) +) + +// Conversion utility function +const converter = R.pipe( + whenPropApplySetterMap('fromNumericBase', toBigNumber), + whenPropApplySetterMap('fromDenomination', toNormalizedDenomination), + whenPredSetWithPropAndSetter(fromAndToCurrencyPropsNotEqual, 'conversionRate', convert), + whenPredSetWithPropAndSetter(R.prop('numberOfDecimals'), 'numberOfDecimals', round), + whenPropApplySetterMap('toNumericBase', baseChange), + R.view(R.lensProp('value')) +); const conversionUtil = (value, { + fromCurrency = null, + toCurrency = fromCurrency, + fromNumericBase, + toNumericBase, + fromDenomination, + numberOfDecimals, + conversionRate, +}) => converter({ fromCurrency, toCurrency, - fromFormat, - toFormat, - precision = 2, + fromNumericBase, + toNumericBase, + fromDenomination, + numberOfDecimals, conversionRate, -}) => { - let result; - - if (fromFormat === 'BN') { - if (fromCurrency !== 'GWEI') { - result = normalizeToWei(value, 'gwei') - } - else { - result = value - } - - result = result.toString(16) - result = formatBalance(result, 9) - result = result.split(' ') - result = Number(result[0]) * 1000000000 - } - - if (fromCurrency === 'GWEI') { - result = result / 1000000000 - } - - if (toCurrency === 'USD') { - result = result * conversionRate - result = result.toFixed(precision) - } - - return result -}; + value, +}); module.exports = { conversionUtil, -- cgit v1.2.3 From b64471833fc925899acb0e9d858624e978eb29af Mon Sep 17 00:00:00 2001 From: Chi Kei Chan Date: Tue, 12 Sep 2017 19:05:00 -0700 Subject: Revert "Overhaul currency conversion utility and update calls to utility in pending-tx." This reverts commit 080890a46ec98814bce8680f561fae3b52d81ed2. --- ui/app/conversion-util.js | 141 ++++++++++++++-------------------------------- 1 file changed, 41 insertions(+), 100 deletions(-) (limited to 'ui/app/conversion-util.js') diff --git a/ui/app/conversion-util.js b/ui/app/conversion-util.js index 5e1125194..8f2214500 100644 --- a/ui/app/conversion-util.js +++ b/ui/app/conversion-util.js @@ -1,108 +1,49 @@ -/* Currency Conversion Utility -* This utility function can be used for converting currency related values within metamask. -* The caller should be able to pass it a value, along with information about the value's -* numeric base, denomination and currency, and the desired numeric base, denomination and -* currency. It should return a single value. -* -* @param {(number | string | BN)} value The value to convert. -* @param {Object} [options] Options to specify details of the conversion -* @param {string} [options.fromCurrency = 'ETH' | 'USD'] The currency of the passed value -* @param {string} [options.toCurrency = 'ETH' | 'USD'] The desired currency of the result -* @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 {number} [options.conversionRate] The rate to use to make the fromCurrency -> toCurrency conversion -* @returns {(number | string | BN)} -* -* The utility passes value along with the options as a single object to the `converter` function. -* `converter` uses Ramda.js to apply a composition of conditional setters to the `value` property, depending -* on the accompanying options. Some of these conditional setters are selected via key-value maps, where -* the keys are specified in the options parameters and the values are setter functions. -*/ - -const BigNumber = require('bignumber.js') -const R = require('ramda') -const { stripHexPrefix } = require('ethereumjs-util') - -BigNumber.config({ - ROUNDING_MODE: BigNumber.ROUND_HALF_DOWN, -}) - -// Big Number Constants -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) - -// Setter Maps -const toBigNumber = { - hex: n => new BigNumber(stripHexPrefix(n), 16), - dec: n => new BigNumber(n, 10), - BN: n => new BigNumber(n.toString(16), 16), -} -const toNormalizedDenomination = { - WEI: bigNumber => bigNumber.div(BIG_NUMBER_WEI_MULTIPLIER) -} -const baseChange = { - hex: n => n.toString(16), - dec: n => n.toString(10), - BN: n => new BN(n.toString(16)), -} - -// Predicates -const fromAndToCurrencyPropsNotEqual = R.compose( - R.not, - R.eqBy(R.__, 'fromCurrency', 'toCurrency'), - R.flip(R.prop) -) - -// Lens -const valuePropertyLense = R.over(R.lensProp('value')) - -// conditional 'value' setting wrappers -const whenPredSetWithPropAndSetter = (pred, prop, setter) => R.when( - pred, - R.converge( - valuePropertyLense, - [R.pipe(R.prop(prop), setter), R.identity] - ) -) -const whenPropApplySetterMap = (prop, setterMap) => whenPredSetWithPropAndSetter( - R.prop(prop), - prop, - R.prop(R.__, setterMap) -) - -// Conversion utility function -const converter = R.pipe( - whenPropApplySetterMap('fromNumericBase', toBigNumber), - whenPropApplySetterMap('fromDenomination', toNormalizedDenomination), - whenPredSetWithPropAndSetter(fromAndToCurrencyPropsNotEqual, 'conversionRate', convert), - whenPredSetWithPropAndSetter(R.prop('numberOfDecimals'), 'numberOfDecimals', round), - whenPropApplySetterMap('toNumericBase', baseChange), - R.view(R.lensProp('value')) -); +const { + numericBalance, + parseBalance, + formatBalance, + normalizeToWei, + valueTable, +} = require('./util') +const hexToBn = require('../../app/scripts/lib/hex-to-bn') +const { BN } = require('ethereumjs-util') +const GWEI_MULTIPLIER = normalizeToWei(hexToBn(valueTable.gwei.toString(16)), 'gwei'); const conversionUtil = (value, { - fromCurrency = null, - toCurrency = fromCurrency, - fromNumericBase, - toNumericBase, - fromDenomination, - numberOfDecimals, - conversionRate, -}) => converter({ fromCurrency, toCurrency, - fromNumericBase, - toNumericBase, - fromDenomination, - numberOfDecimals, + fromFormat, + toFormat, + precision = 2, conversionRate, - value, -}); +}) => { + let result; + + if (fromFormat === 'BN') { + if (fromCurrency !== 'GWEI') { + result = normalizeToWei(value, 'gwei') + } + else { + result = value + } + + result = result.toString(16) + result = formatBalance(result, 9) + result = result.split(' ') + result = Number(result[0]) * 1000000000 + } + + if (fromCurrency === 'GWEI') { + result = result / 1000000000 + } + + if (toCurrency === 'USD') { + result = result * conversionRate + result = result.toFixed(precision) + } + + return result +}; module.exports = { conversionUtil, -- cgit v1.2.3 From 6fa1cd62258ba96d1a55bee140f2d1f10f091ed2 Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 12 Sep 2017 18:08:02 -0230 Subject: Reapply conversion utility changes and fix calls to utility in pending-tx. --- ui/app/conversion-util.js | 141 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 100 insertions(+), 41 deletions(-) (limited to 'ui/app/conversion-util.js') diff --git a/ui/app/conversion-util.js b/ui/app/conversion-util.js index 8f2214500..5e1125194 100644 --- a/ui/app/conversion-util.js +++ b/ui/app/conversion-util.js @@ -1,49 +1,108 @@ -const { - numericBalance, - parseBalance, - formatBalance, - normalizeToWei, - valueTable, -} = require('./util') -const hexToBn = require('../../app/scripts/lib/hex-to-bn') -const { BN } = require('ethereumjs-util') -const GWEI_MULTIPLIER = normalizeToWei(hexToBn(valueTable.gwei.toString(16)), 'gwei'); +/* Currency Conversion Utility +* This utility function can be used for converting currency related values within metamask. +* The caller should be able to pass it a value, along with information about the value's +* numeric base, denomination and currency, and the desired numeric base, denomination and +* currency. It should return a single value. +* +* @param {(number | string | BN)} value The value to convert. +* @param {Object} [options] Options to specify details of the conversion +* @param {string} [options.fromCurrency = 'ETH' | 'USD'] The currency of the passed value +* @param {string} [options.toCurrency = 'ETH' | 'USD'] The desired currency of the result +* @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 {number} [options.conversionRate] The rate to use to make the fromCurrency -> toCurrency conversion +* @returns {(number | string | BN)} +* +* The utility passes value along with the options as a single object to the `converter` function. +* `converter` uses Ramda.js to apply a composition of conditional setters to the `value` property, depending +* on the accompanying options. Some of these conditional setters are selected via key-value maps, where +* the keys are specified in the options parameters and the values are setter functions. +*/ + +const BigNumber = require('bignumber.js') +const R = require('ramda') +const { stripHexPrefix } = require('ethereumjs-util') + +BigNumber.config({ + ROUNDING_MODE: BigNumber.ROUND_HALF_DOWN, +}) + +// Big Number Constants +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) + +// Setter Maps +const toBigNumber = { + hex: n => new BigNumber(stripHexPrefix(n), 16), + dec: n => new BigNumber(n, 10), + BN: n => new BigNumber(n.toString(16), 16), +} +const toNormalizedDenomination = { + WEI: bigNumber => bigNumber.div(BIG_NUMBER_WEI_MULTIPLIER) +} +const baseChange = { + hex: n => n.toString(16), + dec: n => n.toString(10), + BN: n => new BN(n.toString(16)), +} + +// Predicates +const fromAndToCurrencyPropsNotEqual = R.compose( + R.not, + R.eqBy(R.__, 'fromCurrency', 'toCurrency'), + R.flip(R.prop) +) + +// Lens +const valuePropertyLense = R.over(R.lensProp('value')) + +// conditional 'value' setting wrappers +const whenPredSetWithPropAndSetter = (pred, prop, setter) => R.when( + pred, + R.converge( + valuePropertyLense, + [R.pipe(R.prop(prop), setter), R.identity] + ) +) +const whenPropApplySetterMap = (prop, setterMap) => whenPredSetWithPropAndSetter( + R.prop(prop), + prop, + R.prop(R.__, setterMap) +) + +// Conversion utility function +const converter = R.pipe( + whenPropApplySetterMap('fromNumericBase', toBigNumber), + whenPropApplySetterMap('fromDenomination', toNormalizedDenomination), + whenPredSetWithPropAndSetter(fromAndToCurrencyPropsNotEqual, 'conversionRate', convert), + whenPredSetWithPropAndSetter(R.prop('numberOfDecimals'), 'numberOfDecimals', round), + whenPropApplySetterMap('toNumericBase', baseChange), + R.view(R.lensProp('value')) +); const conversionUtil = (value, { + fromCurrency = null, + toCurrency = fromCurrency, + fromNumericBase, + toNumericBase, + fromDenomination, + numberOfDecimals, + conversionRate, +}) => converter({ fromCurrency, toCurrency, - fromFormat, - toFormat, - precision = 2, + fromNumericBase, + toNumericBase, + fromDenomination, + numberOfDecimals, conversionRate, -}) => { - let result; - - if (fromFormat === 'BN') { - if (fromCurrency !== 'GWEI') { - result = normalizeToWei(value, 'gwei') - } - else { - result = value - } - - result = result.toString(16) - result = formatBalance(result, 9) - result = result.split(' ') - result = Number(result[0]) * 1000000000 - } - - if (fromCurrency === 'GWEI') { - result = result / 1000000000 - } - - if (toCurrency === 'USD') { - result = result * conversionRate - result = result.toFixed(precision) - } - - return result -}; + value, +}); module.exports = { conversionUtil, -- cgit v1.2.3 From 095d327140fe4bb2b4a131a66e2774bdfeb8ce37 Mon Sep 17 00:00:00 2001 From: Dan Date: Fri, 15 Sep 2017 10:01:25 -0230 Subject: Adds USD to token list. --- ui/app/conversion-util.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'ui/app/conversion-util.js') diff --git a/ui/app/conversion-util.js b/ui/app/conversion-util.js index 5e1125194..847650758 100644 --- a/ui/app/conversion-util.js +++ b/ui/app/conversion-util.js @@ -13,6 +13,7 @@ * @param {string} [options.fromDenomination = 'WEI'] The denomination of the passed value * @param {number} [options.numberOfDecimals] The desired number of in the result * @param {number} [options.conversionRate] The rate to use to make the fromCurrency -> toCurrency conversion +* @param {number} [options.ethToUSDRate] If present, a second conversion - at ethToUSDRate - happens after conversionRate is applied. * @returns {(number | string | BN)} * * The utility passes value along with the options as a single object to the `converter` function. @@ -80,6 +81,7 @@ const converter = R.pipe( whenPropApplySetterMap('fromNumericBase', toBigNumber), whenPropApplySetterMap('fromDenomination', toNormalizedDenomination), whenPredSetWithPropAndSetter(fromAndToCurrencyPropsNotEqual, 'conversionRate', convert), + whenPredSetWithPropAndSetter(R.prop('ethToUSDRate'), 'ethToUSDRate', convert), whenPredSetWithPropAndSetter(R.prop('numberOfDecimals'), 'numberOfDecimals', round), whenPropApplySetterMap('toNumericBase', baseChange), R.view(R.lensProp('value')) @@ -93,6 +95,7 @@ const conversionUtil = (value, { fromDenomination, numberOfDecimals, conversionRate, + ethToUSDRate, }) => converter({ fromCurrency, toCurrency, @@ -101,6 +104,7 @@ const conversionUtil = (value, { fromDenomination, numberOfDecimals, conversionRate, + ethToUSDRate, value, }); -- cgit v1.2.3 From 54bbf8d8590014b92e7857f30bdc2d8f3779431a Mon Sep 17 00:00:00 2001 From: Dan Date: Wed, 13 Sep 2017 23:50:13 -0230 Subject: Handle transaction totals in WEI in tx-list, send and pending. --- ui/app/conversion-util.js | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'ui/app/conversion-util.js') diff --git a/ui/app/conversion-util.js b/ui/app/conversion-util.js index 847650758..b440aea7f 100644 --- a/ui/app/conversion-util.js +++ b/ui/app/conversion-util.js @@ -46,6 +46,9 @@ const toBigNumber = { const toNormalizedDenomination = { WEI: bigNumber => bigNumber.div(BIG_NUMBER_WEI_MULTIPLIER) } +const toSpecifiedDenomination = { + WEI: bigNumber => bigNumber.times(BIG_NUMBER_WEI_MULTIPLIER) +} const baseChange = { hex: n => n.toString(16), dec: n => n.toString(10), @@ -80,6 +83,7 @@ const whenPropApplySetterMap = (prop, setterMap) => whenPredSetWithPropAndSetter const converter = R.pipe( whenPropApplySetterMap('fromNumericBase', toBigNumber), whenPropApplySetterMap('fromDenomination', toNormalizedDenomination), + whenPropApplySetterMap('toDenomination', toSpecifiedDenomination), whenPredSetWithPropAndSetter(fromAndToCurrencyPropsNotEqual, 'conversionRate', convert), whenPredSetWithPropAndSetter(R.prop('ethToUSDRate'), 'ethToUSDRate', convert), whenPredSetWithPropAndSetter(R.prop('numberOfDecimals'), 'numberOfDecimals', round), @@ -93,6 +97,7 @@ const conversionUtil = (value, { fromNumericBase, toNumericBase, fromDenomination, + toDenomination, numberOfDecimals, conversionRate, ethToUSDRate, @@ -102,6 +107,7 @@ const conversionUtil = (value, { fromNumericBase, toNumericBase, fromDenomination, + toDenomination, numberOfDecimals, conversionRate, ethToUSDRate, -- cgit v1.2.3 From 566ffee8cd4c2d25e5399a9f6fb4d9ed1c8cd564 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 18 Sep 2017 22:05:52 -0230 Subject: Ensure conversion util does not return insignificant trailing zeroes. --- ui/app/conversion-util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ui/app/conversion-util.js') diff --git a/ui/app/conversion-util.js b/ui/app/conversion-util.js index b440aea7f..29e5ce668 100644 --- a/ui/app/conversion-util.js +++ b/ui/app/conversion-util.js @@ -51,7 +51,7 @@ const toSpecifiedDenomination = { } const baseChange = { hex: n => n.toString(16), - dec: n => n.toString(10), + dec: n => Number(n).toString(10), BN: n => new BN(n.toString(16)), } -- cgit v1.2.3 From 39afbea7aaf17cfee5d7fc11299cb82e657edd7e Mon Sep 17 00:00:00 2001 From: Dan Date: Wed, 20 Sep 2017 11:26:20 -0230 Subject: Confirm screen shows amount plus gas in total field --- ui/app/conversion-util.js | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'ui/app/conversion-util.js') diff --git a/ui/app/conversion-util.js b/ui/app/conversion-util.js index 29e5ce668..0ede77487 100644 --- a/ui/app/conversion-util.js +++ b/ui/app/conversion-util.js @@ -114,6 +114,16 @@ const conversionUtil = (value, { value, }); +const addCurrencies = (a, b, { toNumericBase, numberOfDecimals }) => { + const value = (new BigNumber(a)).add(b); + return converter({ + value, + toNumericBase, + numberOfDecimals, + }) +} + module.exports = { conversionUtil, + addCurrencies, } \ No newline at end of file -- cgit v1.2.3 From 14bdc5a78c8529742754d69b8e45693b06b380fe Mon Sep 17 00:00:00 2001 From: Dan Date: Wed, 20 Sep 2017 15:07:12 -0230 Subject: Client side error handling for from, to and amount fields in send.js --- ui/app/conversion-util.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'ui/app/conversion-util.js') diff --git a/ui/app/conversion-util.js b/ui/app/conversion-util.js index 0ede77487..7e02fe2bd 100644 --- a/ui/app/conversion-util.js +++ b/ui/app/conversion-util.js @@ -123,7 +123,20 @@ const addCurrencies = (a, b, { toNumericBase, numberOfDecimals }) => { }) } +const conversionGreaterThan = ( + { value, fromNumericBase }, + { value: compareToValue, fromNumericBase: compareToBase }, +) => { + const firstValue = converter({ value, fromNumericBase }) + const secondValue = converter({ + value: compareToValue, + fromNumericBase: compareToBase, + }) + return firstValue.gt(secondValue) +} + module.exports = { conversionUtil, addCurrencies, + conversionGreaterThan, } \ No newline at end of file -- cgit v1.2.3 From a195427e7208096f6f873175f2cbdbbb0a802191 Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 28 Sep 2017 11:40:33 -0230 Subject: Fix send of USD and backspacing amount to 0 --- ui/app/conversion-util.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ui/app/conversion-util.js') diff --git a/ui/app/conversion-util.js b/ui/app/conversion-util.js index 7e02fe2bd..37877d12c 100644 --- a/ui/app/conversion-util.js +++ b/ui/app/conversion-util.js @@ -47,7 +47,7 @@ const toNormalizedDenomination = { WEI: bigNumber => bigNumber.div(BIG_NUMBER_WEI_MULTIPLIER) } const toSpecifiedDenomination = { - WEI: bigNumber => bigNumber.times(BIG_NUMBER_WEI_MULTIPLIER) + WEI: bigNumber => bigNumber.times(BIG_NUMBER_WEI_MULTIPLIER).round() } const baseChange = { hex: n => n.toString(16), @@ -83,8 +83,8 @@ const whenPropApplySetterMap = (prop, setterMap) => whenPredSetWithPropAndSetter const converter = R.pipe( whenPropApplySetterMap('fromNumericBase', toBigNumber), whenPropApplySetterMap('fromDenomination', toNormalizedDenomination), - whenPropApplySetterMap('toDenomination', toSpecifiedDenomination), whenPredSetWithPropAndSetter(fromAndToCurrencyPropsNotEqual, 'conversionRate', convert), + whenPropApplySetterMap('toDenomination', toSpecifiedDenomination), whenPredSetWithPropAndSetter(R.prop('ethToUSDRate'), 'ethToUSDRate', convert), whenPredSetWithPropAndSetter(R.prop('numberOfDecimals'), 'numberOfDecimals', round), whenPropApplySetterMap('toNumericBase', baseChange), -- cgit v1.2.3 From db1258f3de88f14cd54e2b4fd1cecc62cf6361e5 Mon Sep 17 00:00:00 2001 From: Dan Date: Fri, 6 Oct 2017 12:51:02 -0230 Subject: Conversion util can invert conversion rate --- ui/app/conversion-util.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'ui/app/conversion-util.js') 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, }); -- cgit v1.2.3 From ea7926c211965e2e529e5795a4e1655e97e32144 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 9 Oct 2017 13:55:23 -0230 Subject: Adds amount and gas field to sendV2. --- ui/app/conversion-util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ui/app/conversion-util.js') diff --git a/ui/app/conversion-util.js b/ui/app/conversion-util.js index 20f77b35b..70c3c2622 100644 --- a/ui/app/conversion-util.js +++ b/ui/app/conversion-util.js @@ -125,7 +125,7 @@ const conversionUtil = (value, { conversionRate, ethToUSDRate, invertConversionRate, - value, + value: value || '0', }); const addCurrencies = (a, b, { toNumericBase, numberOfDecimals }) => { -- cgit v1.2.3 From 803eaaf968161f16aaf72d59b979dfbb7fb9b352 Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Fri, 13 Oct 2017 16:19:22 -0400 Subject: [NewUI] SendV2-#8: Send container handles tokens; gas info dynamic from state (#2364) * Adds memo field to send-v2. * Vertical align transaction with flexbox. * Customize Gas UI * Remove internal state from InputNumber and fix use in gastooltip. * Move customize-gas-modal to its own folder and minor cleanup * Create send container, get account info from state, and make currency display more reusable * Adjusts send-v2 and container for send-token. Dynamically getting suggested gas prices. --- ui/app/conversion-util.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'ui/app/conversion-util.js') diff --git a/ui/app/conversion-util.js b/ui/app/conversion-util.js index 70c3c2622..3a702bcdd 100644 --- a/ui/app/conversion-util.js +++ b/ui/app/conversion-util.js @@ -128,7 +128,8 @@ const conversionUtil = (value, { value: value || '0', }); -const addCurrencies = (a, b, { toNumericBase, numberOfDecimals }) => { +const addCurrencies = (a, b, options = {}) => { + const { toNumericBase, numberOfDecimals } = options const value = (new BigNumber(a)).add(b); return converter({ value, @@ -137,6 +138,16 @@ const addCurrencies = (a, b, { toNumericBase, numberOfDecimals }) => { }) } +const multiplyCurrencies = (a, b, options = {}) => { + const { toNumericBase, numberOfDecimals } = options + const value = (new BigNumber(a)).times(b); + return converter({ + value, + toNumericBase, + numberOfDecimals, + }) +} + const conversionGreaterThan = ( { value, fromNumericBase }, { value: compareToValue, fromNumericBase: compareToBase }, @@ -152,5 +163,6 @@ const conversionGreaterThan = ( module.exports = { conversionUtil, addCurrencies, + multiplyCurrencies, conversionGreaterThan, } \ No newline at end of file -- cgit v1.2.3 From a9244f5e426d6572ef135e07ab75a49c00e84942 Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 12 Oct 2017 14:12:14 -0230 Subject: Customize Gas connected to state --- ui/app/conversion-util.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'ui/app/conversion-util.js') diff --git a/ui/app/conversion-util.js b/ui/app/conversion-util.js index 3a702bcdd..3a9e9ad0f 100644 --- a/ui/app/conversion-util.js +++ b/ui/app/conversion-util.js @@ -32,6 +32,7 @@ BigNumber.config({ // Big Number Constants const BIG_NUMBER_WEI_MULTIPLIER = new BigNumber('1000000000000000000') +const BIG_NUMBER_GWEI_MULTIPLIER = new BigNumber('1000000000') // Individual Setters const convert = R.invoker(1, 'times') @@ -45,10 +46,12 @@ const toBigNumber = { BN: n => new BigNumber(n.toString(16), 16), } const toNormalizedDenomination = { - WEI: bigNumber => bigNumber.div(BIG_NUMBER_WEI_MULTIPLIER) + WEI: bigNumber => bigNumber.div(BIG_NUMBER_WEI_MULTIPLIER), + GWEI: bigNumber => bigNumber.div(BIG_NUMBER_GWEI_MULTIPLIER), } const toSpecifiedDenomination = { - WEI: bigNumber => bigNumber.times(BIG_NUMBER_WEI_MULTIPLIER).round() + WEI: bigNumber => bigNumber.times(BIG_NUMBER_WEI_MULTIPLIER).round(), + GWEI: bigNumber => bigNumber.times(BIG_NUMBER_GWEI_MULTIPLIER).round(), } const baseChange = { hex: n => n.toString(16), @@ -139,8 +142,13 @@ const addCurrencies = (a, b, options = {}) => { } const multiplyCurrencies = (a, b, options = {}) => { - const { toNumericBase, numberOfDecimals } = options - const value = (new BigNumber(a)).times(b); + const { + toNumericBase, + numberOfDecimals, + multiplicandBase, + multiplierBase, + } = options + const value = (new BigNumber(a, multiplicandBase)).times(b, multiplierBase); return converter({ value, toNumericBase, -- cgit v1.2.3 From 60eda592b5979ac1fdbfb6d5b3418a4924abc14d Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 17 Oct 2017 17:43:20 -0230 Subject: Handling to and amount errors. --- ui/app/conversion-util.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'ui/app/conversion-util.js') diff --git a/ui/app/conversion-util.js b/ui/app/conversion-util.js index 3a9e9ad0f..1ef276a39 100644 --- a/ui/app/conversion-util.js +++ b/ui/app/conversion-util.js @@ -157,14 +157,11 @@ const multiplyCurrencies = (a, b, options = {}) => { } const conversionGreaterThan = ( - { value, fromNumericBase }, - { value: compareToValue, fromNumericBase: compareToBase }, + { ...firstProps }, + { ...secondProps }, ) => { - const firstValue = converter({ value, fromNumericBase }) - const secondValue = converter({ - value: compareToValue, - fromNumericBase: compareToBase, - }) + const firstValue = converter({ ...firstProps }) + const secondValue = converter({ ...secondProps }) return firstValue.gt(secondValue) } -- cgit v1.2.3 From bd11e60b8c128dd69ba1bcf58d25fa9323d91a33 Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 19 Oct 2017 15:53:02 -0230 Subject: Amount field shows insufficient funds error based on amoutn + gas total. --- ui/app/conversion-util.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'ui/app/conversion-util.js') diff --git a/ui/app/conversion-util.js b/ui/app/conversion-util.js index 1ef276a39..e008ee1cb 100644 --- a/ui/app/conversion-util.js +++ b/ui/app/conversion-util.js @@ -132,12 +132,16 @@ const conversionUtil = (value, { }); const addCurrencies = (a, b, options = {}) => { - const { toNumericBase, numberOfDecimals } = options - const value = (new BigNumber(a)).add(b); + const { + aBase, + bBase, + ...conversionOptions, + } = options + const value = (new BigNumber(a, aBase)).add(b, bBase); + return converter({ value, - toNumericBase, - numberOfDecimals, + ...conversionOptions, }) } -- cgit v1.2.3 From 332c7441b656ec82ebfba863e3feb4dbf365d67b Mon Sep 17 00:00:00 2001 From: Dan Date: Wed, 18 Oct 2017 23:39:26 -0230 Subject: Get currency from state in account details, send and confirm screens. --- ui/app/conversion-util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ui/app/conversion-util.js') diff --git a/ui/app/conversion-util.js b/ui/app/conversion-util.js index e008ee1cb..50f903d9f 100644 --- a/ui/app/conversion-util.js +++ b/ui/app/conversion-util.js @@ -36,7 +36,7 @@ const BIG_NUMBER_GWEI_MULTIPLIER = new BigNumber('1000000000') // Individual Setters const convert = R.invoker(1, 'times') -const round = R.invoker(2, 'toFormat')(R.__, BigNumber.ROUND_DOWN) +const round = R.invoker(2, 'round')(R.__, BigNumber.ROUND_DOWN) const invertConversionRate = conversionRate => () => new BigNumber(1.0).div(conversionRate) // Setter Maps -- cgit v1.2.3 From 89af385a352daf66ad1a6fb3bba75676fd3b9e7f Mon Sep 17 00:00:00 2001 From: Dan Date: Wed, 18 Oct 2017 15:38:53 -0230 Subject: Fix handling of arithmetic on token gas in confirm-send-token. --- ui/app/conversion-util.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'ui/app/conversion-util.js') diff --git a/ui/app/conversion-util.js b/ui/app/conversion-util.js index e008ee1cb..51c7bd355 100644 --- a/ui/app/conversion-util.js +++ b/ui/app/conversion-util.js @@ -147,16 +147,16 @@ const addCurrencies = (a, b, options = {}) => { const multiplyCurrencies = (a, b, options = {}) => { const { - toNumericBase, - numberOfDecimals, multiplicandBase, multiplierBase, + ...conversionOptions, } = options + const value = (new BigNumber(a, multiplicandBase)).times(b, multiplierBase); + return converter({ value, - toNumericBase, - numberOfDecimals, + ...conversionOptions, }) } -- cgit v1.2.3 From 220da24f9ab4a57a10bc1fc3e249c511a98ecb46 Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 26 Oct 2017 13:36:34 -0230 Subject: Change min gas price to 0.1 GWEI --- ui/app/conversion-util.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'ui/app/conversion-util.js') diff --git a/ui/app/conversion-util.js b/ui/app/conversion-util.js index 2f3fb1678..39215cf1b 100644 --- a/ui/app/conversion-util.js +++ b/ui/app/conversion-util.js @@ -51,7 +51,7 @@ const toNormalizedDenomination = { } const toSpecifiedDenomination = { WEI: bigNumber => bigNumber.times(BIG_NUMBER_WEI_MULTIPLIER).round(), - GWEI: bigNumber => bigNumber.times(BIG_NUMBER_GWEI_MULTIPLIER).round(), + GWEI: bigNumber => bigNumber.times(BIG_NUMBER_GWEI_MULTIPLIER).round(1), } const baseChange = { hex: n => n.toString(16), @@ -169,9 +169,34 @@ const conversionGreaterThan = ( return firstValue.gt(secondValue) } +const conversionGTE = ( + { ...firstProps }, + { ...secondProps }, +) => { + const firstValue = converter({ ...firstProps }) + const secondValue = converter({ ...secondProps }) + return firstValue.greaterThanOrEqualTo(secondValue) +} + +const conversionLTE = ( + { ...firstProps }, + { ...secondProps }, +) => { + const firstValue = converter({ ...firstProps }) + const secondValue = converter({ ...secondProps }) + return firstValue.lessThanOrEqualTo(secondValue) +} + +const toNegative = (n, options = {}) => { + return multiplyCurrencies(n, -1, options) +} + module.exports = { conversionUtil, addCurrencies, multiplyCurrencies, conversionGreaterThan, + conversionGTE, + conversionLTE, + toNegative, } \ No newline at end of file -- cgit v1.2.3 From 3d53716f4366212ed7a51b49ce747584b13fd1ce Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Fri, 27 Oct 2017 03:25:34 -0230 Subject: Correct rendering of conversions when conversion rate is a token. (#2498) --- ui/app/conversion-util.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'ui/app/conversion-util.js') diff --git a/ui/app/conversion-util.js b/ui/app/conversion-util.js index 39215cf1b..cb715460f 100644 --- a/ui/app/conversion-util.js +++ b/ui/app/conversion-util.js @@ -13,7 +13,6 @@ * @param {string} [options.fromDenomination = 'WEI'] The denomination of the passed value * @param {number} [options.numberOfDecimals] The desired number of in the result * @param {number} [options.conversionRate] The rate to use to make the fromCurrency -> toCurrency conversion -* @param {number} [options.ethToUSDRate] If present, a second conversion - at ethToUSDRate - happens after conversionRate is applied. * @returns {(number | string | BN)} * * The utility passes value along with the options as a single object to the `converter` function. @@ -38,6 +37,7 @@ const BIG_NUMBER_GWEI_MULTIPLIER = new BigNumber('1000000000') const convert = R.invoker(1, 'times') const round = 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']) // Setter Maps const toBigNumber = { @@ -95,12 +95,12 @@ const whenPropApplySetterMap = (prop, setterMap) => whenPredSetWithPropAndSetter // Conversion utility function const converter = R.pipe( + whenPredSetCRWithPropAndSetter(R.prop('conversionRate'), 'conversionRate', decToBigNumberViaString), whenPredSetCRWithPropAndSetter(R.prop('invertConversionRate'), 'conversionRate', invertConversionRate), whenPropApplySetterMap('fromNumericBase', toBigNumber), whenPropApplySetterMap('fromDenomination', toNormalizedDenomination), whenPredSetWithPropAndSetter(fromAndToCurrencyPropsNotEqual, 'conversionRate', convert), whenPropApplySetterMap('toDenomination', toSpecifiedDenomination), - whenPredSetWithPropAndSetter(R.prop('ethToUSDRate'), 'ethToUSDRate', convert), whenPredSetWithPropAndSetter(R.prop('numberOfDecimals'), 'numberOfDecimals', round), whenPropApplySetterMap('toNumericBase', baseChange), R.view(R.lensProp('value')) @@ -115,7 +115,6 @@ const conversionUtil = (value, { toDenomination, numberOfDecimals, conversionRate, - ethToUSDRate, invertConversionRate, }) => converter({ fromCurrency, @@ -126,7 +125,6 @@ const conversionUtil = (value, { toDenomination, numberOfDecimals, conversionRate, - ethToUSDRate, invertConversionRate, value: value || '0', }); @@ -152,7 +150,10 @@ const multiplyCurrencies = (a, b, options = {}) => { ...conversionOptions, } = options - const value = (new BigNumber(a, multiplicandBase)).times(b, multiplierBase); + const bigNumberA = new BigNumber(String(a), multiplicandBase) + const bigNumberB = new BigNumber(String(b), multiplierBase) + + const value = bigNumberA.times(bigNumberB); return converter({ value, -- cgit v1.2.3 From 5a94775b3fa22517a71232ebe229ee83e9debcf1 Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 2 Nov 2017 00:00:33 -0230 Subject: Lint fixes for NewUI-flat. --- ui/app/conversion-util.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'ui/app/conversion-util.js') diff --git a/ui/app/conversion-util.js b/ui/app/conversion-util.js index cb715460f..3a7788ad1 100644 --- a/ui/app/conversion-util.js +++ b/ui/app/conversion-util.js @@ -22,6 +22,8 @@ */ const BigNumber = require('bignumber.js') +const ethUtil = require('ethereumjs-util') +const BN = ethUtil.BN const R = require('ramda') const { stripHexPrefix } = require('ethereumjs-util') @@ -133,7 +135,7 @@ const addCurrencies = (a, b, options = {}) => { const { aBase, bBase, - ...conversionOptions, + ...conversionOptions } = options const value = (new BigNumber(a, aBase)).add(b, bBase); @@ -147,7 +149,7 @@ const multiplyCurrencies = (a, b, options = {}) => { const { multiplicandBase, multiplierBase, - ...conversionOptions, + ...conversionOptions } = options const bigNumberA = new BigNumber(String(a), multiplicandBase) @@ -157,7 +159,7 @@ const multiplyCurrencies = (a, b, options = {}) => { return converter({ value, - ...conversionOptions, + ...conversionOptions }) } -- cgit v1.2.3 From 56e9f98bd05de8ae26f653d15eec4304f0c72155 Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 2 Nov 2017 09:45:59 -0230 Subject: More lint fixes --- ui/app/conversion-util.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'ui/app/conversion-util.js') diff --git a/ui/app/conversion-util.js b/ui/app/conversion-util.js index 3a7788ad1..9359d7c90 100644 --- a/ui/app/conversion-util.js +++ b/ui/app/conversion-util.js @@ -106,7 +106,7 @@ const converter = R.pipe( whenPredSetWithPropAndSetter(R.prop('numberOfDecimals'), 'numberOfDecimals', round), whenPropApplySetterMap('toNumericBase', baseChange), R.view(R.lensProp('value')) -); +) const conversionUtil = (value, { fromCurrency = null, @@ -129,7 +129,7 @@ const conversionUtil = (value, { conversionRate, invertConversionRate, value: value || '0', -}); +}) const addCurrencies = (a, b, options = {}) => { const { @@ -137,7 +137,7 @@ const addCurrencies = (a, b, options = {}) => { bBase, ...conversionOptions } = options - const value = (new BigNumber(a, aBase)).add(b, bBase); + const value = (new BigNumber(a, aBase)).add(b, bBase) return converter({ value, @@ -155,17 +155,17 @@ const multiplyCurrencies = (a, b, options = {}) => { const bigNumberA = new BigNumber(String(a), multiplicandBase) const bigNumberB = new BigNumber(String(b), multiplierBase) - const value = bigNumberA.times(bigNumberB); + const value = bigNumberA.times(bigNumberB) return converter({ value, - ...conversionOptions + ...conversionOptions, }) } const conversionGreaterThan = ( { ...firstProps }, - { ...secondProps }, + { ...secondProps }, ) => { const firstValue = converter({ ...firstProps }) const secondValue = converter({ ...secondProps }) @@ -174,7 +174,7 @@ const conversionGreaterThan = ( const conversionGTE = ( { ...firstProps }, - { ...secondProps }, + { ...secondProps }, ) => { const firstValue = converter({ ...firstProps }) const secondValue = converter({ ...secondProps }) @@ -183,7 +183,7 @@ const conversionGTE = ( const conversionLTE = ( { ...firstProps }, - { ...secondProps }, + { ...secondProps }, ) => { const firstValue = converter({ ...firstProps }) const secondValue = converter({ ...secondProps }) @@ -202,4 +202,4 @@ module.exports = { conversionGTE, conversionLTE, toNegative, -} \ No newline at end of file +} -- cgit v1.2.3 From 67bdfe87e31e695f8c4beab1659a3a4b764ccf24 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 30 Oct 2017 15:18:50 -0230 Subject: Token balance in send state; validating sufficient tokens, validation updates on 'from' switching. --- ui/app/conversion-util.js | 1 + 1 file changed, 1 insertion(+) (limited to 'ui/app/conversion-util.js') diff --git a/ui/app/conversion-util.js b/ui/app/conversion-util.js index 9359d7c90..5eadbdb99 100644 --- a/ui/app/conversion-util.js +++ b/ui/app/conversion-util.js @@ -169,6 +169,7 @@ const conversionGreaterThan = ( ) => { const firstValue = converter({ ...firstProps }) const secondValue = converter({ ...secondProps }) + return firstValue.gt(secondValue) } -- cgit v1.2.3 From 319779ab081f70343b5ef77531450878292a90d6 Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 26 Oct 2017 14:13:12 -0230 Subject: Adds max amount feature for send-ether --- ui/app/conversion-util.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'ui/app/conversion-util.js') diff --git a/ui/app/conversion-util.js b/ui/app/conversion-util.js index 5eadbdb99..3786641fb 100644 --- a/ui/app/conversion-util.js +++ b/ui/app/conversion-util.js @@ -145,6 +145,20 @@ const addCurrencies = (a, b, options = {}) => { }) } +const subtractCurrencies = (a, b, options = {}) => { + const { + aBase, + bBase, + ...conversionOptions, + } = options + const value = (new BigNumber(a, aBase)).minus(b, bBase); + + return converter({ + value, + ...conversionOptions, + }) +} + const multiplyCurrencies = (a, b, options = {}) => { const { multiplicandBase, @@ -203,4 +217,5 @@ module.exports = { conversionGTE, conversionLTE, toNegative, + subtractCurrencies, } -- cgit v1.2.3 From 716bbf67d7180ffe0f59d07484d30231ed5f5e49 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 30 Oct 2017 19:16:56 -0230 Subject: Set gas price allows for WEI precision. --- ui/app/conversion-util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ui/app/conversion-util.js') diff --git a/ui/app/conversion-util.js b/ui/app/conversion-util.js index 3786641fb..ee831262b 100644 --- a/ui/app/conversion-util.js +++ b/ui/app/conversion-util.js @@ -53,7 +53,7 @@ const toNormalizedDenomination = { } const toSpecifiedDenomination = { WEI: bigNumber => bigNumber.times(BIG_NUMBER_WEI_MULTIPLIER).round(), - GWEI: bigNumber => bigNumber.times(BIG_NUMBER_GWEI_MULTIPLIER).round(1), + GWEI: bigNumber => bigNumber.times(BIG_NUMBER_GWEI_MULTIPLIER).round(9), } const baseChange = { hex: n => n.toString(16), -- cgit v1.2.3 From 8c6e1232e417f5a2974b5aa1cc479dac4925df63 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 6 Nov 2017 16:14:46 -0330 Subject: Lint fixes. --- ui/app/conversion-util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ui/app/conversion-util.js') diff --git a/ui/app/conversion-util.js b/ui/app/conversion-util.js index ee831262b..ee2950071 100644 --- a/ui/app/conversion-util.js +++ b/ui/app/conversion-util.js @@ -149,7 +149,7 @@ const subtractCurrencies = (a, b, options = {}) => { const { aBase, bBase, - ...conversionOptions, + ...conversionOptions } = options const value = (new BigNumber(a, aBase)).minus(b, bBase); -- cgit v1.2.3 From 5120cfdff3047e4bf88cec544895cc713d063cdd Mon Sep 17 00:00:00 2001 From: Thomas Huang Date: Thu, 9 Nov 2017 14:23:10 -0800 Subject: Linting --- ui/app/conversion-util.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ui/app/conversion-util.js') diff --git a/ui/app/conversion-util.js b/ui/app/conversion-util.js index ee2950071..de37bd595 100644 --- a/ui/app/conversion-util.js +++ b/ui/app/conversion-util.js @@ -151,7 +151,7 @@ const subtractCurrencies = (a, b, options = {}) => { bBase, ...conversionOptions } = options - const value = (new BigNumber(a, aBase)).minus(b, bBase); + const value = (new BigNumber(a, aBase)).minus(b, bBase) return converter({ value, @@ -183,7 +183,7 @@ const conversionGreaterThan = ( ) => { const firstValue = converter({ ...firstProps }) const secondValue = converter({ ...secondProps }) - + return firstValue.gt(secondValue) } -- cgit v1.2.3 From 5a0126f17b3513fa7fa1513f2c52abff19535ac0 Mon Sep 17 00:00:00 2001 From: Dan Date: Fri, 10 Nov 2017 07:07:53 -0330 Subject: Rounding of vals < 0.01 in currency display consistent with master. --- ui/app/conversion-util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ui/app/conversion-util.js') diff --git a/ui/app/conversion-util.js b/ui/app/conversion-util.js index de37bd595..ee42ebea1 100644 --- a/ui/app/conversion-util.js +++ b/ui/app/conversion-util.js @@ -37,7 +37,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_DOWN) +const round = R.invoker(2, 'round')(R.__, BigNumber.ROUND_HALF_DOWN) const invertConversionRate = conversionRate => () => new BigNumber(1.0).div(conversionRate) const decToBigNumberViaString = n => R.pipe(String, toBigNumber['dec']) -- cgit v1.2.3