aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'app/scripts')
-rw-r--r--app/scripts/contentscript.js6
-rw-r--r--app/scripts/controllers/currency.js2
-rw-r--r--app/scripts/controllers/transactions.js14
-rw-r--r--app/scripts/lib/nonce-tracker.js5
-rw-r--r--app/scripts/lib/setupRaven.js14
-rw-r--r--app/scripts/lib/tx-state-manager.js16
-rw-r--r--app/scripts/metamask-controller.js7
-rw-r--r--app/scripts/ui.js (renamed from app/scripts/popup.js)0
8 files changed, 43 insertions, 21 deletions
diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js
index 7abbc60e7..2098fae27 100644
--- a/app/scripts/contentscript.js
+++ b/app/scripts/contentscript.js
@@ -7,8 +7,8 @@ const ObjectMultiplex = require('obj-multiplex')
const extension = require('extensionizer')
const PortStream = require('./lib/port-stream.js')
-const inpageContent = fs.readFileSync(path.join(__dirname, '..', '..', 'dist', 'chrome', 'scripts', 'inpage.js')).toString()
-const inpageSuffix = '//# sourceURL=' + extension.extension.getURL('scripts/inpage.js') + '\n'
+const inpageContent = fs.readFileSync(path.join(__dirname, '..', '..', 'dist', 'chrome', 'inpage.js')).toString()
+const inpageSuffix = '//# sourceURL=' + extension.extension.getURL('inpage.js') + '\n'
const inpageBundle = inpageContent + inpageSuffix
// Eventually this streaming injection could be replaced with:
@@ -96,7 +96,7 @@ function logStreamDisconnectWarning (remoteLabel, err) {
}
function shouldInjectWeb3 () {
- return doctypeCheck() && suffixCheck()
+ return doctypeCheck() && suffixCheck()
&& documentElementCheck() && !blacklistedDomainCheck()
}
diff --git a/app/scripts/controllers/currency.js b/app/scripts/controllers/currency.js
index 25a7a942e..930fc52e8 100644
--- a/app/scripts/controllers/currency.js
+++ b/app/scripts/controllers/currency.js
@@ -52,7 +52,7 @@ class CurrencyController {
this.setConversionDate(Number(parsedResponse.timestamp))
}).catch((err) => {
if (err) {
- console.warn('MetaMask - Failed to query currency conversion.')
+ console.warn(`MetaMask - Failed to query currency conversion:`, currentCurrency, err)
this.setConversionRate(0)
this.setConversionDate('N/A')
}
diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js
index 3e3909361..a18a2d2e2 100644
--- a/app/scripts/controllers/transactions.js
+++ b/app/scripts/controllers/transactions.js
@@ -161,9 +161,11 @@ module.exports = class TransactionController extends EventEmitter {
this.emit(`${txMeta.id}:unapproved`, txMeta)
}
- async newUnapprovedTransaction (txParams) {
+ async newUnapprovedTransaction (txParams, opts = {}) {
log.debug(`MetaMaskController newUnapprovedTransaction ${JSON.stringify(txParams)}`)
const initialTxMeta = await this.addUnapprovedTransaction(txParams)
+ initialTxMeta.origin = opts.origin
+ this.txStateManager.updateTx(initialTxMeta, '#newUnapprovedTransaction - adding the origin')
// listen for tx completion (success, fail)
return new Promise((resolve, reject) => {
this.txStateManager.once(`${initialTxMeta.id}:finished`, (finishedTxMeta) => {
@@ -250,7 +252,7 @@ module.exports = class TransactionController extends EventEmitter {
// wait for a nonce
nonceLock = await this.nonceTracker.getNonceLock(fromAddress)
// add nonce to txParams
- // if txMeta has lastGasPrice then it is a retry at same nonce with higher
+ // if txMeta has lastGasPrice then it is a retry at same nonce with higher
// gas price transaction and their for the nonce should not be calculated
const nonce = txMeta.lastGasPrice ? txMeta.txParams.nonce : nonceLock.nextNonce
txMeta.txParams.nonce = ethUtil.addHexPrefix(nonce.toString(16))
@@ -273,12 +275,14 @@ module.exports = class TransactionController extends EventEmitter {
async signTransaction (txId) {
const txMeta = this.txStateManager.getTx(txId)
- const txParams = txMeta.txParams
- const fromAddress = txParams.from
// add network/chain id
- txParams.chainId = ethUtil.addHexPrefix(this.getChainId().toString(16))
+ const chainId = this.getChainId()
+ const txParams = Object.assign({}, txMeta.txParams, { chainId })
+ // sign tx
+ const fromAddress = txParams.from
const ethTx = new Transaction(txParams)
await this.signEthTx(ethTx, fromAddress)
+ // set state to signed
this.txStateManager.setTxStatusSigned(txMeta.id)
const rawTx = ethUtil.bufferToHex(ethTx.serialize())
return rawTx
diff --git a/app/scripts/lib/nonce-tracker.js b/app/scripts/lib/nonce-tracker.js
index ed9dd3f11..5b1cd7f43 100644
--- a/app/scripts/lib/nonce-tracker.js
+++ b/app/scripts/lib/nonce-tracker.js
@@ -31,14 +31,13 @@ class NonceTracker {
const networkNonceResult = await this._getNetworkNextNonce(address)
const highestLocallyConfirmed = this._getHighestLocallyConfirmed(address)
const nextNetworkNonce = networkNonceResult.nonce
- const highestLocalNonce = highestLocallyConfirmed
- const highestSuggested = Math.max(nextNetworkNonce, highestLocalNonce)
+ const highestSuggested = Math.max(nextNetworkNonce, highestLocallyConfirmed)
const pendingTxs = this.getPendingTransactions(address)
const localNonceResult = this._getHighestContinuousFrom(pendingTxs, highestSuggested) || 0
nonceDetails.params = {
- highestLocalNonce,
+ highestLocallyConfirmed,
highestSuggested,
nextNetworkNonce,
}
diff --git a/app/scripts/lib/setupRaven.js b/app/scripts/lib/setupRaven.js
index a869588d0..b93591e65 100644
--- a/app/scripts/lib/setupRaven.js
+++ b/app/scripts/lib/setupRaven.js
@@ -23,10 +23,20 @@ function setupRaven(opts) {
release,
transport: function(opts) {
const report = opts.data
- // simplify ethjs error messages
+ // simplify certain complex error messages
report.exception.values.forEach(item => {
- item.value = extractEthjsErrorMessage(item.value)
+ let errorMessage = item.value
+ // simplify ethjs error messages
+ errorMessage = extractEthjsErrorMessage(errorMessage)
+ // simplify 'Transaction Failed: known transaction'
+ if (errorMessage.indexOf('Transaction Failed: known transaction') === 0) {
+ // cut the hash from the error message
+ errorMessage = 'Transaction Failed: known transaction'
+ }
+ // finalize
+ item.value = errorMessage
})
+
// modify report urls
rewriteReportUrls(report)
// make request normally
diff --git a/app/scripts/lib/tx-state-manager.js b/app/scripts/lib/tx-state-manager.js
index ab344ae9b..23c915a61 100644
--- a/app/scripts/lib/tx-state-manager.js
+++ b/app/scripts/lib/tx-state-manager.js
@@ -106,12 +106,9 @@ module.exports = class TransactionStateManager extends EventEmitter {
}
updateTx (txMeta, note) {
+ // validate txParams
if (txMeta.txParams) {
- Object.keys(txMeta.txParams).forEach((key) => {
- const value = txMeta.txParams[key]
- if (typeof value !== 'string') console.error(`${key}: ${value} in txParams is not a string`)
- if (!ethUtil.isHexPrefixed(value)) console.error('is not hex prefixed, anything on txParams must be hex prefixed')
- })
+ this.validateTxParams(txMeta.txParams)
}
// create txMeta snapshot for history
@@ -139,6 +136,15 @@ module.exports = class TransactionStateManager extends EventEmitter {
this.updateTx(txMeta, `txStateManager#updateTxParams`)
}
+ // validates txParams members by type
+ validateTxParams(txParams) {
+ Object.keys(txParams).forEach((key) => {
+ const value = txParams[key]
+ if (typeof value !== 'string') throw new Error(`${key}: ${value} in txParams is not a string`)
+ if (!ethUtil.isHexPrefixed(value)) throw new Error('is not hex prefixed, everything on txParams must be hex prefixed')
+ })
+ }
+
/*
Takes an object of fields to search for eg:
let thingsToLookFor = {
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index 4422a5cf3..b96acc9da 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -57,7 +57,6 @@ module.exports = class MetamaskController extends EventEmitter {
this.defaultMaxListeners = 20
this.sendUpdate = debounce(this.privateSendUpdate.bind(this), 200)
-
this.opts = opts
const initState = opts.initState || {}
this.recordFirstTimeInfo(initState)
@@ -242,6 +241,11 @@ module.exports = class MetamaskController extends EventEmitter {
static: {
eth_syncing: false,
web3_clientVersion: `MetaMask/v${version}`,
+ eth_sendTransaction: (payload, next, end) => {
+ const origin = payload.origin
+ const txParams = payload.params[0]
+ nodeify(this.txController.newUnapprovedTransaction, this.txController)(txParams, { origin }, end)
+ },
},
// account mgmt
getAccounts: (cb) => {
@@ -256,7 +260,6 @@ module.exports = class MetamaskController extends EventEmitter {
cb(null, result)
},
// tx signing
- processTransaction: nodeify(async (txParams) => await this.txController.newUnapprovedTransaction(txParams), this),
// old style msg signing
processMessage: this.newUnsignedMessage.bind(this),
// personal_sign msg signing
diff --git a/app/scripts/popup.js b/app/scripts/ui.js
index 13c7ac5ec..13c7ac5ec 100644
--- a/app/scripts/popup.js
+++ b/app/scripts/ui.js