aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/conversion-util.js
diff options
context:
space:
mode:
authorDan J Miller <danjm.com@gmail.com>2017-09-12 13:19:05 +0800
committerChi Kei Chan <chikeichan@gmail.com>2017-09-12 13:19:05 +0800
commit1e83835ba8cce0fdf794092a8c55b6c68664204a (patch)
treeb2e9e66a1eadd5c2e09ee0c1bd8a02bd9616e6c6 /ui/app/conversion-util.js
parent062e67bff83fd79647231be6e2448d35b5f312f9 (diff)
downloadtangerine-wallet-browser-1e83835ba8cce0fdf794092a8c55b6c68664204a.tar
tangerine-wallet-browser-1e83835ba8cce0fdf794092a8c55b6c68664204a.tar.gz
tangerine-wallet-browser-1e83835ba8cce0fdf794092a8c55b6c68664204a.tar.bz2
tangerine-wallet-browser-1e83835ba8cce0fdf794092a8c55b6c68664204a.tar.lz
tangerine-wallet-browser-1e83835ba8cce0fdf794092a8c55b6c68664204a.tar.xz
tangerine-wallet-browser-1e83835ba8cce0fdf794092a8c55b6c68664204a.tar.zst
tangerine-wallet-browser-1e83835ba8cce0fdf794092a8c55b6c68664204a.zip
[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.
Diffstat (limited to 'ui/app/conversion-util.js')
-rw-r--r--ui/app/conversion-util.js50
1 files changed, 50 insertions, 0 deletions
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