aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'app/scripts')
-rw-r--r--app/scripts/controllers/infura.js42
-rw-r--r--app/scripts/controllers/transactions.js20
-rw-r--r--app/scripts/keyring-controller.js2
-rw-r--r--app/scripts/metamask-controller.js15
-rw-r--r--app/scripts/migrations/015.js38
-rw-r--r--app/scripts/migrations/index.js1
6 files changed, 105 insertions, 13 deletions
diff --git a/app/scripts/controllers/infura.js b/app/scripts/controllers/infura.js
new file mode 100644
index 000000000..98375b446
--- /dev/null
+++ b/app/scripts/controllers/infura.js
@@ -0,0 +1,42 @@
+const ObservableStore = require('obs-store')
+const extend = require('xtend')
+
+// every ten minutes
+const POLLING_INTERVAL = 300000
+
+class InfuraController {
+
+ constructor (opts = {}) {
+ const initState = extend({
+ infuraNetworkStatus: {},
+ }, opts.initState)
+ this.store = new ObservableStore(initState)
+ }
+
+ //
+ // PUBLIC METHODS
+ //
+
+ // Responsible for retrieving the status of Infura's nodes. Can return either
+ // ok, degraded, or down.
+ checkInfuraNetworkStatus () {
+ return fetch('https://api.infura.io/v1/status/metamask')
+ .then(response => response.json())
+ .then((parsedResponse) => {
+ this.store.updateState({
+ infuraNetworkStatus: parsedResponse,
+ })
+ })
+ }
+
+ scheduleInfuraNetworkCheck () {
+ if (this.conversionInterval) {
+ clearInterval(this.conversionInterval)
+ }
+ this.conversionInterval = setInterval(() => {
+ this.checkInfuraNetworkStatus()
+ }, POLLING_INTERVAL)
+ }
+}
+
+module.exports = InfuraController
diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js
index f6dea34e7..52251d66e 100644
--- a/app/scripts/controllers/transactions.js
+++ b/app/scripts/controllers/transactions.js
@@ -8,8 +8,6 @@ const TxProviderUtil = require('../lib/tx-utils')
const createId = require('../lib/random-id')
const denodeify = require('denodeify')
-const RETRY_LIMIT = 200
-
module.exports = class TransactionController extends EventEmitter {
constructor (opts) {
super()
@@ -152,13 +150,15 @@ module.exports = class TransactionController extends EventEmitter {
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)
- })
+ if (!txParams.gasPrice) {
+ this.query.gasPrice((err, gasPrice) => {
+ if (err) return cb(err)
+ // set gasPrice
+ txParams.gasPrice = gasPrice
+ })
+ }
+ // set gasLimit
+ this.txProviderUtils.analyzeGasUsage(txMeta, cb)
}
getUnapprovedTxList () {
@@ -435,8 +435,6 @@ module.exports = class TransactionController extends EventEmitter {
// Only auto-submit already-signed txs:
if (!('rawTx' in txMeta)) return cb()
- if (txMeta.retryCount > RETRY_LIMIT) return
-
// Increment a try counter.
txMeta.retryCount++
const rawTx = txMeta.rawTx
diff --git a/app/scripts/keyring-controller.js b/app/scripts/keyring-controller.js
index 5b3c80e40..2edc8060e 100644
--- a/app/scripts/keyring-controller.js
+++ b/app/scripts/keyring-controller.js
@@ -87,7 +87,7 @@ class KeyringController extends EventEmitter {
}
if (!bip39.validateMnemonic(seed)) {
- return Promise.reject('Seed phrase is invalid.')
+ return Promise.reject(new Error('Seed phrase is invalid.'))
}
this.clearKeyrings()
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index 39d22f278..782641b3f 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -15,6 +15,7 @@ const CurrencyController = require('./controllers/currency')
const NoticeController = require('./notice-controller')
const ShapeShiftController = require('./controllers/shapeshift')
const AddressBookController = require('./controllers/address-book')
+const InfuraController = require('./controllers/infura')
const MessageManager = require('./lib/message-manager')
const PersonalMessageManager = require('./lib/personal-message-manager')
const TransactionController = require('./controllers/transactions')
@@ -44,8 +45,8 @@ module.exports = class MetamaskController extends EventEmitter {
this.store = new ObservableStore(initState)
// network store
-
this.networkController = new NetworkController(initState.NetworkController)
+
// config manager
this.configManager = new ConfigManager({
store: this.store,
@@ -63,6 +64,13 @@ module.exports = class MetamaskController extends EventEmitter {
this.currencyController.updateConversionRate()
this.currencyController.scheduleConversionInterval()
+ // infura controller
+ this.infuraController = new InfuraController({
+ initState: initState.InfuraController,
+ })
+ this.infuraController.scheduleInfuraNetworkCheck()
+
+
// rpc provider
this.provider = this.initializeProvider()
@@ -147,6 +155,9 @@ module.exports = class MetamaskController extends EventEmitter {
this.networkController.store.subscribe((state) => {
this.store.updateState({ NetworkController: state })
})
+ this.infuraController.store.subscribe((state) => {
+ this.store.updateState({ InfuraController: state })
+ })
// manual mem state subscriptions
this.networkController.store.subscribe(this.sendUpdate.bind(this))
@@ -160,6 +171,7 @@ module.exports = class MetamaskController extends EventEmitter {
this.currencyController.store.subscribe(this.sendUpdate.bind(this))
this.noticeController.memStore.subscribe(this.sendUpdate.bind(this))
this.shapeshiftController.store.subscribe(this.sendUpdate.bind(this))
+ this.infuraController.store.subscribe(this.sendUpdate.bind(this))
}
//
@@ -237,6 +249,7 @@ module.exports = class MetamaskController extends EventEmitter {
this.addressBookController.store.getState(),
this.currencyController.store.getState(),
this.noticeController.memStore.getState(),
+ this.infuraController.store.getState(),
// config manager
this.configManager.getConfig(),
this.shapeshiftController.store.getState(),
diff --git a/app/scripts/migrations/015.js b/app/scripts/migrations/015.js
new file mode 100644
index 000000000..4b839580b
--- /dev/null
+++ b/app/scripts/migrations/015.js
@@ -0,0 +1,38 @@
+const version = 15
+
+/*
+
+This migration sets transactions with the 'Gave up submitting tx.' err message
+to a 'failed' stated
+
+*/
+
+const clone = require('clone')
+
+module.exports = {
+ version,
+
+ migrate: function (originalVersionedData) {
+ const versionedData = clone(originalVersionedData)
+ versionedData.meta.version = version
+ try {
+ const state = versionedData.data
+ const newState = transformState(state)
+ versionedData.data = newState
+ } catch (err) {
+ console.warn(`MetaMask Migration #${version}` + err.stack)
+ }
+ return Promise.resolve(versionedData)
+ },
+}
+
+function transformState (state) {
+ const newState = state
+ const transactions = newState.TransactionController.transactions
+ newState.TransactionController.transactions = transactions.map((txMeta) => {
+ if (!txMeta.err) return txMeta
+ else if (txMeta.err.message === 'Gave up submitting tx.') txMeta.status = 'failed'
+ return txMeta
+ })
+ return newState
+}
diff --git a/app/scripts/migrations/index.js b/app/scripts/migrations/index.js
index fb1ad7863..651ee6a9c 100644
--- a/app/scripts/migrations/index.js
+++ b/app/scripts/migrations/index.js
@@ -25,4 +25,5 @@ module.exports = [
require('./012'),
require('./013'),
require('./014'),
+ require('./015'),
]