From cd351e8aef59f314c170d0436d98aaf111db1c00 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 28 Aug 2017 20:36:10 -0230 Subject: Move getTaxBN and bnMultiplyByFraction to util.js --- ui/app/util.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'ui/app/util.js') diff --git a/ui/app/util.js b/ui/app/util.js index 4dd0e30f3..4b48db0ca 100644 --- a/ui/app/util.js +++ b/ui/app/util.js @@ -1,4 +1,5 @@ const ethUtil = require('ethereumjs-util') +const hexToBn = require('../../app/scripts/lib/hex-to-bn') const vreme = new (require('vreme'))() // formatData :: ( date: ) -> String @@ -43,6 +44,8 @@ module.exports = { bnTable: bnTable, isHex: isHex, formatDate, + bnMultiplyByFraction, + getTxFeeBn, } function valuesFor (obj) { @@ -222,3 +225,24 @@ function readableDate (ms) { function isHex (str) { return Boolean(str.match(/^(0x)?[0-9a-fA-F]+$/)) } + +function bnMultiplyByFraction (targetBN, numerator, denominator) { + const numBN = new ethUtil.BN(numerator) + const denomBN = new ethUtil.BN(denominator) + return targetBN.mul(numBN).div(denomBN) +} + +function getTxFeeBn (gas, gasPrice = MIN_GAS_PRICE_BN.toString(16), blockGasLimit) { + const gasBn = hexToBn(gas) + const gasLimit = new ethUtil.BN(parseInt(blockGasLimit)) + const safeGasLimit = bnMultiplyByFraction(gasLimit, 19, 20).toString(10) + + // Gas Price + const gasPriceBn = hexToBn(gasPrice) + const txFeeBn = gasBn.mul(gasPriceBn) + + const fiatMultiplier = hexToBn((1000000000).toString(16)) + const txFeeAsFiatBn = txFeeBn.mul(fiatMultiplier) + + return txFeeAsFiatBn; +} -- cgit v1.2.3