aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib
diff options
context:
space:
mode:
authorkumavis <kumavis@users.noreply.github.com>2017-01-22 02:06:50 +0800
committerGitHub <noreply@github.com>2017-01-22 02:06:50 +0800
commit74dc20bdf179cbd8b25f6fae007553784466e3ff (patch)
tree4b28d3230bf38c68b68e40efcb5b1bf810eacf3e /app/scripts/lib
parentbc1615f032186e88aebfa9dac38039dcff263162 (diff)
parent247f7aad5e358fae33616fd310e695e06673dd19 (diff)
downloadtangerine-wallet-browser-74dc20bdf179cbd8b25f6fae007553784466e3ff.tar
tangerine-wallet-browser-74dc20bdf179cbd8b25f6fae007553784466e3ff.tar.gz
tangerine-wallet-browser-74dc20bdf179cbd8b25f6fae007553784466e3ff.tar.bz2
tangerine-wallet-browser-74dc20bdf179cbd8b25f6fae007553784466e3ff.tar.lz
tangerine-wallet-browser-74dc20bdf179cbd8b25f6fae007553784466e3ff.tar.xz
tangerine-wallet-browser-74dc20bdf179cbd8b25f6fae007553784466e3ff.tar.zst
tangerine-wallet-browser-74dc20bdf179cbd8b25f6fae007553784466e3ff.zip
Merge branch 'dev' into obs-store2
Diffstat (limited to 'app/scripts/lib')
-rw-r--r--app/scripts/lib/config-manager.js2
-rw-r--r--app/scripts/lib/eth-store.js4
-rw-r--r--app/scripts/lib/tx-utils.js58
3 files changed, 62 insertions, 2 deletions
diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js
index 6d7305377..daba8bc7b 100644
--- a/app/scripts/lib/config-manager.js
+++ b/app/scripts/lib/config-manager.js
@@ -281,7 +281,7 @@ ConfigManager.prototype.updateConversionRate = function () {
this.setConversionPrice(parsedResponse.ticker.price)
this.setConversionDate(parsedResponse.timestamp)
}).catch((err) => {
- console.error('Error in conversion.', err)
+ console.warn('MetaMask - Failed to query currency conversion.')
this.setConversionPrice(0)
this.setConversionDate('N/A')
})
diff --git a/app/scripts/lib/eth-store.js b/app/scripts/lib/eth-store.js
index a42b2417f..7e2caf884 100644
--- a/app/scripts/lib/eth-store.js
+++ b/app/scripts/lib/eth-store.js
@@ -43,7 +43,9 @@ EthereumStore.prototype.addAccount = function (address) {
self._currentState.accounts[address] = {}
self._didUpdate()
if (!self.currentBlockNumber) return
- self._updateAccount(address, noop)
+ self._updateAccount(address, () => {
+ self._didUpdate()
+ })
}
EthereumStore.prototype.removeAccount = function (address) {
diff --git a/app/scripts/lib/tx-utils.js b/app/scripts/lib/tx-utils.js
index d1fb98f42..5116cb93b 100644
--- a/app/scripts/lib/tx-utils.js
+++ b/app/scripts/lib/tx-utils.js
@@ -1,6 +1,8 @@
const async = require('async')
const EthQuery = require('eth-query')
const ethUtil = require('ethereumjs-util')
+const Transaction = require('ethereumjs-tx')
+const normalize = require('./sig-util').normalize
const BN = ethUtil.BN
/*
@@ -14,6 +16,7 @@ module.exports = class txProviderUtils {
this.provider = provider
this.query = new EthQuery(provider)
}
+
analyzeGasUsage (txData, cb) {
var self = this
this.query.getBlockByNumber('latest', true, (err, block) => {
@@ -71,4 +74,59 @@ module.exports = class txProviderUtils {
const correct = bnGas.add(gasBuffer)
return ethUtil.addHexPrefix(correct.toString(16))
}
+
+ fillInTxParams (txParams, cb) {
+ let fromAddress = txParams.from
+ let reqs = {}
+
+ if (isUndef(txParams.gas)) reqs.gas = (cb) => this.query.estimateGas(txParams, cb)
+ if (isUndef(txParams.gasPrice)) reqs.gasPrice = (cb) => this.query.gasPrice(cb)
+ if (isUndef(txParams.nonce)) reqs.nonce = (cb) => this.query.getTransactionCount(fromAddress, 'pending', cb)
+
+ async.parallel(reqs, function(err, result) {
+ if (err) return cb(err)
+ // write results to txParams obj
+ Object.assign(txParams, result)
+ cb()
+ })
+ }
+
+ // builds ethTx from txParams object
+ buildEthTxFromParams (txParams, gasMultiplier = 1) {
+ // apply gas multiplyer
+ let gasPrice = new BN(ethUtil.stripHexPrefix(txParams.gasPrice), 16)
+ // multiply and divide by 100 so as to add percision to integer mul
+ gasPrice = gasPrice.mul(new BN(gasMultiplier * 100, 10)).div(new BN(100, 10))
+ txParams.gasPrice = ethUtil.intToHex(gasPrice.toNumber())
+ // normalize values
+ txParams.to = normalize(txParams.to)
+ txParams.from = normalize(txParams.from)
+ txParams.value = normalize(txParams.value)
+ txParams.data = normalize(txParams.data)
+ txParams.gasLimit = normalize(txParams.gasLimit || txParams.gas)
+ txParams.nonce = normalize(txParams.nonce)
+ // build ethTx
+ const ethTx = new Transaction(txParams)
+ return ethTx
+ }
+
+ publishTransaction (rawTx, cb) {
+ this.query.sendRawTransaction(rawTx, cb)
+ }
+
+ validateTxParams (txParams, cb) {
+ if (('value' in txParams) && txParams.value.indexOf('-') === 0) {
+ cb(new Error(`Invalid transaction value of ${txParams.value} not a positive number.`))
+ } else {
+ cb()
+ }
+ }
+
+
+}
+
+// util
+
+function isUndef(value) {
+ return value === undefined
}