aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorDan Finlay <flyswatter@users.noreply.github.com>2017-03-29 05:50:55 +0800
committerGitHub <noreply@github.com>2017-03-29 05:50:55 +0800
commita3e08d779ecc81ebddf8609130eae5e6db08ad48 (patch)
tree1692e346c343b3b2f9823ff0626d11e961cf5484 /app
parent67892c49a6cb26e433e3dbeaa9f2f7790667f103 (diff)
parentd1733c1f7521d17b0e8acdae5a2be33c1a9bbd5c (diff)
downloadtangerine-wallet-browser-a3e08d779ecc81ebddf8609130eae5e6db08ad48.tar.gz
tangerine-wallet-browser-a3e08d779ecc81ebddf8609130eae5e6db08ad48.tar.zst
tangerine-wallet-browser-a3e08d779ecc81ebddf8609130eae5e6db08ad48.zip
Merge branch 'master' into kovan-faucet-instructions
Diffstat (limited to 'app')
-rw-r--r--app/manifest.json2
-rw-r--r--app/scripts/contentscript.js17
-rw-r--r--app/scripts/lib/hex-to-bn.js7
-rw-r--r--app/scripts/lib/tx-utils.js32
-rw-r--r--app/scripts/transaction-manager.js48
5 files changed, 60 insertions, 46 deletions
diff --git a/app/manifest.json b/app/manifest.json
index 97cc7dd6d..a163d4c06 100644
--- a/app/manifest.json
+++ b/app/manifest.json
@@ -51,7 +51,7 @@
"scripts/contentscript.js"
],
"run_at": "document_start",
- "all_frames": false
+ "all_frames": true
}
],
"permissions": [
diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js
index 020208ceb..9a390e580 100644
--- a/app/scripts/contentscript.js
+++ b/app/scripts/contentscript.js
@@ -65,10 +65,10 @@ function setupStreams () {
}
function shouldInjectWeb3 () {
- return isAllowedSuffix(window.location.href)
+ return doctypeCheck() || suffixCheck()
}
-function isAllowedSuffix (testCase) {
+function doctypeCheck () {
const doctype = window.document.doctype
if (doctype) {
return doctype.name === 'html'
@@ -76,3 +76,16 @@ function isAllowedSuffix (testCase) {
return false
}
}
+
+function suffixCheck() {
+ var prohibitedTypes = ['xml', 'pdf']
+ var currentUrl = window.location.href
+ var currentRegex
+ for (let i = 0; i < prohibitedTypes.length; i++) {
+ currentRegex = new RegExp(`\.${prohibitedTypes[i]}$`)
+ if (currentRegex.test(currentUrl)) {
+ return false
+ }
+ }
+ return true
+}
diff --git a/app/scripts/lib/hex-to-bn.js b/app/scripts/lib/hex-to-bn.js
new file mode 100644
index 000000000..184217279
--- /dev/null
+++ b/app/scripts/lib/hex-to-bn.js
@@ -0,0 +1,7 @@
+const ethUtil = require('ethereumjs-util')
+const BN = ethUtil.BN
+
+module.exports = function hexToBn (hex) {
+ return new BN(ethUtil.stripHexPrefix(hex), 16)
+}
+
diff --git a/app/scripts/lib/tx-utils.js b/app/scripts/lib/tx-utils.js
index 7988f83e9..72df53631 100644
--- a/app/scripts/lib/tx-utils.js
+++ b/app/scripts/lib/tx-utils.js
@@ -12,48 +12,49 @@ and used to do things like calculate gas of a tx.
*/
module.exports = class txProviderUtils {
+
constructor (provider) {
this.provider = provider
this.query = new EthQuery(provider)
}
- analyzeGasUsage (txData, cb) {
+ analyzeGasUsage (txMeta, cb) {
var self = this
this.query.getBlockByNumber('latest', true, (err, block) => {
if (err) return cb(err)
async.waterfall([
- self.estimateTxGas.bind(self, txData, block.gasLimit),
- self.setTxGas.bind(self, txData, block.gasLimit),
+ self.estimateTxGas.bind(self, txMeta, block.gasLimit),
+ self.setTxGas.bind(self, txMeta, block.gasLimit),
], cb)
})
}
- estimateTxGas (txData, blockGasLimitHex, cb) {
- const txParams = txData.txParams
+ estimateTxGas (txMeta, blockGasLimitHex, cb) {
+ const txParams = txMeta.txParams
// check if gasLimit is already specified
- txData.gasLimitSpecified = Boolean(txParams.gas)
+ txMeta.gasLimitSpecified = Boolean(txParams.gas)
// if not, fallback to block gasLimit
- if (!txData.gasLimitSpecified) {
+ if (!txMeta.gasLimitSpecified) {
txParams.gas = blockGasLimitHex
}
// run tx, see if it will OOG
this.query.estimateGas(txParams, cb)
}
- setTxGas (txData, blockGasLimitHex, estimatedGasHex, cb) {
- txData.estimatedGas = estimatedGasHex
- const txParams = txData.txParams
+ setTxGas (txMeta, blockGasLimitHex, estimatedGasHex, cb) {
+ txMeta.estimatedGas = estimatedGasHex
+ const txParams = txMeta.txParams
// if gasLimit was specified and doesnt OOG,
// use original specified amount
- if (txData.gasLimitSpecified) {
- txData.estimatedGas = txParams.gas
+ if (txMeta.gasLimitSpecified) {
+ txMeta.estimatedGas = txParams.gas
cb()
return
}
// if gasLimit not originally specified,
// try adding an additional gas buffer to our estimation for safety
- const recommendedGasHex = this.addGasBuffer(txData.estimatedGas, blockGasLimitHex)
+ const recommendedGasHex = this.addGasBuffer(txMeta.estimatedGas, blockGasLimitHex)
txParams.gas = recommendedGasHex
cb()
return
@@ -90,16 +91,13 @@ module.exports = class txProviderUtils {
// builds ethTx from txParams object
buildEthTxFromParams (txParams) {
- // apply gas multiplyer
- let gasPrice = hexToBn(txParams.gasPrice)
- // multiply and divide by 100 so as to add percision to integer mul
- 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.gas = normalize(txParams.gas || txParams.gasLimit)
+ txParams.gasPrice = normalize(txParams.gasPrice)
txParams.nonce = normalize(txParams.nonce)
// build ethTx
log.info(`Prepared tx for signing: ${JSON.stringify(txParams)}`)
diff --git a/app/scripts/transaction-manager.js b/app/scripts/transaction-manager.js
index 7227bdc87..a70159680 100644
--- a/app/scripts/transaction-manager.js
+++ b/app/scripts/transaction-manager.js
@@ -4,7 +4,7 @@ const extend = require('xtend')
const Semaphore = require('semaphore')
const ObservableStore = require('obs-store')
const ethUtil = require('ethereumjs-util')
-const BN = require('ethereumjs-util').BN
+const EthQuery = require('eth-query')
const TxProviderUtil = require('./lib/tx-utils')
const createId = require('./lib/random-id')
@@ -20,6 +20,7 @@ module.exports = class TransactionManager extends EventEmitter {
this.txHistoryLimit = opts.txHistoryLimit
this.provider = opts.provider
this.blockTracker = opts.blockTracker
+ this.query = new EthQuery(this.provider)
this.txProviderUtils = new TxProviderUtil(this.provider)
this.blockTracker.on('block', this.checkForTxInBlock.bind(this))
this.signEthTx = opts.signTransaction
@@ -78,8 +79,9 @@ module.exports = class TransactionManager extends EventEmitter {
fullTxList.splice(index, 1)
}
fullTxList.push(txMeta)
-
this._saveTxList(fullTxList)
+ this.emit('update')
+
this.once(`${txMeta.id}:signed`, function (txId) {
this.removeAllListeners(`${txMeta.id}:rejected`)
})
@@ -121,44 +123,38 @@ module.exports = class TransactionManager extends EventEmitter {
async.waterfall([
// validate
(cb) => this.txProviderUtils.validateTxParams(txParams, cb),
- // prepare txMeta
+ // construct txMeta
(cb) => {
- // create txMeta obj with parameters and meta data
- let time = (new Date()).getTime()
- let txId = createId()
- txParams.metamaskId = txId
- txParams.metamaskNetworkId = this.getNetwork()
txMeta = {
- id: txId,
- time: time,
+ id: createId(),
+ time: (new Date()).getTime(),
status: 'unapproved',
metamaskNetworkId: this.getNetwork(),
txParams: txParams,
}
- // calculate metadata for tx
- this.txProviderUtils.analyzeGasUsage(txMeta, cb)
+ cb()
},
+ // add default tx params
+ (cb) => this.addTxDefaults(txMeta, cb),
// save txMeta
(cb) => {
this.addTx(txMeta)
- this.setMaxTxCostAndFee(txMeta)
cb(null, txMeta)
},
], done)
}
- setMaxTxCostAndFee (txMeta) {
- var txParams = txMeta.txParams
- var gasCost = new BN(ethUtil.stripHexPrefix(txParams.gas || txMeta.estimatedGas), 16)
- var gasPrice = new BN(ethUtil.stripHexPrefix(txParams.gasPrice || '0x4a817c800'), 16)
- var txFee = gasCost.mul(gasPrice)
- var txValue = new BN(ethUtil.stripHexPrefix(txParams.value || '0x0'), 16)
- var maxCost = txValue.add(txFee)
- txMeta.txFee = txFee
- txMeta.txValue = txValue
- txMeta.maxCost = maxCost
- txMeta.gasPrice = gasPrice
- this.updateTx(txMeta)
+ addTxDefaults (txMeta, cb) {
+ const txParams = txMeta.txParams
+ // ensure value
+ txParams.value = txParams.value || '0x0'
+ this.query.gasPrice((err, gasPrice) => {
+ if (err) return cb(err)
+ // set gasPrice
+ txParams.gasPrice = gasPrice
+ // set gasLimit
+ this.txProviderUtils.analyzeGasUsage(txMeta, cb)
+ })
}
getUnapprovedTxList () {
@@ -336,7 +332,7 @@ module.exports = class TransactionManager extends EventEmitter {
}
return this.setTxStatusFailed(txId, errReason)
}
- this.txProviderUtils.query.getTransactionByHash(txHash, (err, txParams) => {
+ this.query.getTransactionByHash(txHash, (err, txParams) => {
if (err || !txParams) {
if (!txParams) return
txMeta.err = {