aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorfrankiebee <frankie.diamond@gmail.com>2017-08-05 01:55:00 +0800
committerfrankiebee <frankie.diamond@gmail.com>2017-08-05 01:55:00 +0800
commitcaee2a9e35c0e80efed9da0798cb75044db6c920 (patch)
tree56184228fcb8dd9cb74027ca9ea4a1c5be12ddf1 /app
parent3dcc199845f4026cc4d02f9f760332ac9752ff69 (diff)
downloadtangerine-wallet-browser-caee2a9e35c0e80efed9da0798cb75044db6c920.tar
tangerine-wallet-browser-caee2a9e35c0e80efed9da0798cb75044db6c920.tar.gz
tangerine-wallet-browser-caee2a9e35c0e80efed9da0798cb75044db6c920.tar.bz2
tangerine-wallet-browser-caee2a9e35c0e80efed9da0798cb75044db6c920.tar.lz
tangerine-wallet-browser-caee2a9e35c0e80efed9da0798cb75044db6c920.tar.xz
tangerine-wallet-browser-caee2a9e35c0e80efed9da0798cb75044db6c920.tar.zst
tangerine-wallet-browser-caee2a9e35c0e80efed9da0798cb75044db6c920.zip
move util functions to util.js
Diffstat (limited to 'app')
-rw-r--r--app/scripts/lib/tx-utils.js41
-rw-r--r--app/scripts/lib/util.js31
2 files changed, 40 insertions, 32 deletions
diff --git a/app/scripts/lib/tx-utils.js b/app/scripts/lib/tx-utils.js
index 3687a9652..a2db4abd8 100644
--- a/app/scripts/lib/tx-utils.js
+++ b/app/scripts/lib/tx-utils.js
@@ -1,7 +1,11 @@
-const ethUtil = require('ethereumjs-util')
+const EthQuery = require('ethjs-query')
const Transaction = require('ethereumjs-tx')
const normalize = require('eth-sig-util').normalize
-const BN = ethUtil.BN
+const {
+ hexToBn,
+ BnMultiplyByFraction,
+ bnToHex,
+} = require('./util')
/*
tx-utils are utility methods for Transaction manager
@@ -10,8 +14,8 @@ and used to do things like calculate gas of a tx.
*/
module.exports = class txProvideUtils {
- constructor (ethQuery) {
- this.query = ethQuery
+ constructor (provider) {
+ this.query = new EthQuery(provider)
}
async analyzeGasUsage (txMeta) {
@@ -91,31 +95,4 @@ module.exports = class txProvideUtils {
throw new Error(`Invalid transaction value of ${txParams.value} not a positive number.`)
}
}
-
- sufficientBalance (txParams, hexBalance) {
- const balance = hexToBn(hexBalance)
- const value = hexToBn(txParams.value)
- const gasLimit = hexToBn(txParams.gas)
- const gasPrice = hexToBn(txParams.gasPrice)
-
- const maxCost = value.add(gasLimit.mul(gasPrice))
- return balance.gte(maxCost)
- }
-
-}
-
-// util
-
-function bnToHex (inputBn) {
- return ethUtil.addHexPrefix(inputBn.toString(16))
-}
-
-function hexToBn (inputHex) {
- return new BN(ethUtil.stripHexPrefix(inputHex), 16)
-}
-
-function BnMultiplyByFraction (targetBN, numerator, denominator) {
- const numBN = new BN(numerator)
- const denomBN = new BN(denominator)
- return targetBN.mul(numBN).div(denomBN)
-}
+} \ No newline at end of file
diff --git a/app/scripts/lib/util.js b/app/scripts/lib/util.js
index bddd60ee8..70390e95c 100644
--- a/app/scripts/lib/util.js
+++ b/app/scripts/lib/util.js
@@ -1,8 +1,39 @@
+const ethUtil = require('ethereumjs-util')
+const BN = ethUtil.BN
+
module.exports = {
getStack,
+ sufficientBalance,
+ hexToBn,
+ bnToHex,
+ BnMultiplyByFraction,
}
function getStack () {
const stack = new Error('Stack trace generator - not an error').stack
return stack
}
+
+function sufficientBalance (txParams, hexBalance) {
+ const balance = hexToBn(hexBalance)
+ const value = hexToBn(txParams.value)
+ const gasLimit = hexToBn(txParams.gas)
+ const gasPrice = hexToBn(txParams.gasPrice)
+
+ const maxCost = value.add(gasLimit.mul(gasPrice))
+ return balance.gte(maxCost)
+}
+
+function bnToHex (inputBn) {
+ return ethUtil.addHexPrefix(inputBn.toString(16))
+}
+
+function hexToBn (inputHex) {
+ return new BN(ethUtil.stripHexPrefix(inputHex), 16)
+}
+
+function BnMultiplyByFraction (targetBN, numerator, denominator) {
+ const numBN = new BN(numerator)
+ const denomBN = new BN(denominator)
+ return targetBN.mul(numBN).div(denomBN)
+}