aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorFrankie <frankie.diamond@gmail.com>2017-05-24 08:36:11 +0800
committerGitHub <noreply@github.com>2017-05-24 08:36:11 +0800
commit97ea7454b353acb8f87dac087eeae61f945325d7 (patch)
treeb1ed4d382b3008fe3271b0c10a8f6dab41b6ee9f /app
parentc1239608a62a4283d138b1a6586653ac791eb655 (diff)
parent9c316664de2eb82bdd10ab9cd6fa0a33f5185e20 (diff)
downloadtangerine-wallet-browser-97ea7454b353acb8f87dac087eeae61f945325d7.tar
tangerine-wallet-browser-97ea7454b353acb8f87dac087eeae61f945325d7.tar.gz
tangerine-wallet-browser-97ea7454b353acb8f87dac087eeae61f945325d7.tar.bz2
tangerine-wallet-browser-97ea7454b353acb8f87dac087eeae61f945325d7.tar.lz
tangerine-wallet-browser-97ea7454b353acb8f87dac087eeae61f945325d7.tar.xz
tangerine-wallet-browser-97ea7454b353acb8f87dac087eeae61f945325d7.tar.zst
tangerine-wallet-browser-97ea7454b353acb8f87dac087eeae61f945325d7.zip
Merge branch 'master' into networkController
Diffstat (limited to 'app')
-rw-r--r--app/manifest.json2
-rw-r--r--app/scripts/controllers/transactions.js59
-rw-r--r--app/scripts/lib/inpage-provider.js22
3 files changed, 73 insertions, 10 deletions
diff --git a/app/manifest.json b/app/manifest.json
index 31e4598c7..5fd4420be 100644
--- a/app/manifest.json
+++ b/app/manifest.json
@@ -1,7 +1,7 @@
{
"name": "MetaMask",
"short_name": "Metamask",
- "version": "3.6.5",
+ "version": "3.7.0",
"manifest_version": 2,
"author": "https://metamask.io",
"description": "Ethereum Browser Extension",
diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js
index 2ebeed3ab..faccf1ab1 100644
--- a/app/scripts/controllers/transactions.js
+++ b/app/scripts/controllers/transactions.js
@@ -6,8 +6,12 @@ const ObservableStore = require('obs-store')
const ethUtil = require('ethereumjs-util')
const TxProviderUtil = require('../lib/tx-utils')
const createId = require('../lib/random-id')
+const denodeify = require('denodeify')
-module.exports = class TransactionManager extends EventEmitter {
+const RETRY_LIMIT = 200
+const RESUBMIT_INTERVAL = 10000 // Ten seconds
+
+module.exports = class TransactionController extends EventEmitter {
constructor (opts) {
super()
this.store = new ObservableStore(extend({
@@ -30,6 +34,8 @@ module.exports = class TransactionManager extends EventEmitter {
this.store.subscribe(() => this._updateMemstore())
this.networkStore.subscribe(() => this._updateMemstore())
this.preferencesStore.subscribe(() => this._updateMemstore())
+
+ this.continuallyResubmitPendingTxs()
}
getState () {
@@ -229,7 +235,11 @@ module.exports = class TransactionManager extends EventEmitter {
})
}
- publishTransaction (txId, rawTx, cb) {
+ publishTransaction (txId, rawTx, cb = warn) {
+ const txMeta = this.getTx(txId)
+ txMeta.rawTx = rawTx
+ this.updateTx(txMeta)
+
this.txProviderUtils.publishTransaction(rawTx, (err, txHash) => {
if (err) return cb(err)
this.setTxHash(txId, txHash)
@@ -352,7 +362,7 @@ module.exports = class TransactionManager extends EventEmitter {
message: 'There was a problem loading this transaction.',
}
this.updateTx(txMeta)
- return console.error(err)
+ return log.error(err)
}
if (txParams.blockNumber) {
this.setTxStatusConfirmed(txId)
@@ -378,6 +388,7 @@ module.exports = class TransactionManager extends EventEmitter {
this.emit(`${txMeta.id}:${status}`, txId)
if (status === 'submitted' || status === 'rejected') {
this.emit(`${txMeta.id}:finished`, txMeta)
+
}
this.updateTx(txMeta)
this.emit('updateBadge')
@@ -397,7 +408,47 @@ module.exports = class TransactionManager extends EventEmitter {
})
this.memStore.updateState({ unapprovedTxs, selectedAddressTxList })
}
+
+ continuallyResubmitPendingTxs () {
+ const pending = this.getTxsByMetaData('status', 'submitted')
+ const resubmit = denodeify(this.resubmitTx.bind(this))
+ Promise.all(pending.map(txMeta => resubmit(txMeta)))
+ .catch((reason) => {
+ log.info('Problem resubmitting tx', reason)
+ })
+ .then(() => {
+ global.setTimeout(() => {
+ this.continuallyResubmitPendingTxs()
+ }, RESUBMIT_INTERVAL)
+ })
+ }
+
+ resubmitTx (txMeta, cb) {
+ // Increment a try counter.
+ if (!('retryCount' in txMeta)) {
+ txMeta.retryCount = 0
+ }
+
+ // Only auto-submit already-signed txs:
+ if (!('rawTx' in txMeta)) {
+ return cb()
+ }
+
+ if (txMeta.retryCount > RETRY_LIMIT) {
+ txMeta.err = {
+ isWarning: true,
+ message: 'Gave up submitting tx.',
+ }
+ this.updateTx(txMeta)
+ return log.error(txMeta.err.message)
+ }
+
+ txMeta.retryCount++
+ const rawTx = txMeta.rawTx
+ this.txProviderUtils.publishTransaction(rawTx, cb)
+ }
+
}
-const warn = () => console.warn('warn was used no cb provided')
+const warn = () => log.warn('warn was used no cb provided')
diff --git a/app/scripts/lib/inpage-provider.js b/app/scripts/lib/inpage-provider.js
index e5e398e24..e54f547bd 100644
--- a/app/scripts/lib/inpage-provider.js
+++ b/app/scripts/lib/inpage-provider.js
@@ -1,5 +1,7 @@
const pipe = require('pump')
-const StreamProvider = require('web3-stream-provider')
+const ProviderEngine = require('web3-provider-engine')
+const FilterSubprovider = require('web3-provider-engine/subproviders/filters')
+const StreamSubprovider = require('web3-provider-engine/subproviders/stream')
const LocalStorageStore = require('obs-store')
const ObjectMultiplex = require('./obj-multiplex')
const createRandomId = require('./random-id')
@@ -27,14 +29,24 @@ function MetamaskInpageProvider (connectionStream) {
)
// connect to async provider
- const asyncProvider = self.asyncProvider = new StreamProvider()
+ const engine = new ProviderEngine()
+
+ const filterSubprovider = new FilterSubprovider()
+ engine.addProvider(filterSubprovider)
+
+ const streamSubprovider = new StreamSubprovider()
+ engine.addProvider(streamSubprovider)
+
pipe(
- asyncProvider,
+ streamSubprovider,
multiStream.createStream('provider'),
- asyncProvider,
+ streamSubprovider,
(err) => logStreamDisconnectWarning('MetaMask RpcProvider', err)
)
+ // start polling
+ engine.start()
+
self.idMap = {}
// handle sendAsync requests via asyncProvider
self.sendAsync = function (payload, cb) {
@@ -46,7 +58,7 @@ function MetamaskInpageProvider (connectionStream) {
return message
})
// forward to asyncProvider
- asyncProvider.sendAsync(request, function (err, res) {
+ engine.sendAsync(request, function (err, res) {
if (err) return cb(err)
// transform messages to original ids
eachJsonMessage(res, (message) => {