diff options
author | Thomas Huang <thomas.b.huang@gmail.com> | 2017-06-28 01:32:28 +0800 |
---|---|---|
committer | Thomas Huang <thomas.b.huang@gmail.com> | 2017-06-28 01:32:28 +0800 |
commit | 1977417017eec00a546ab816fa635ea575e4835d (patch) | |
tree | 77f942810eda1665b4b8974077985f082bfc24c3 /app/scripts | |
parent | 235cb1f2d790a7bda349ab0d33ad1009751a8536 (diff) | |
parent | 48f7cff8c0e765e85532c860c5f3061ca1d6deb7 (diff) | |
download | tangerine-wallet-browser-1977417017eec00a546ab816fa635ea575e4835d.tar tangerine-wallet-browser-1977417017eec00a546ab816fa635ea575e4835d.tar.gz tangerine-wallet-browser-1977417017eec00a546ab816fa635ea575e4835d.tar.bz2 tangerine-wallet-browser-1977417017eec00a546ab816fa635ea575e4835d.tar.lz tangerine-wallet-browser-1977417017eec00a546ab816fa635ea575e4835d.tar.xz tangerine-wallet-browser-1977417017eec00a546ab816fa635ea575e4835d.tar.zst tangerine-wallet-browser-1977417017eec00a546ab816fa635ea575e4835d.zip |
Merge branch 'master' into i1473-dappDefaultGasPrice
Diffstat (limited to 'app/scripts')
-rw-r--r-- | app/scripts/background.js | 4 | ||||
-rw-r--r-- | app/scripts/controllers/infura.js | 42 | ||||
-rw-r--r-- | app/scripts/controllers/preferences.js | 8 | ||||
-rw-r--r-- | app/scripts/controllers/transactions.js | 2 | ||||
-rw-r--r-- | app/scripts/keyring-controller.js | 2 | ||||
-rw-r--r-- | app/scripts/metamask-controller.js | 16 |
6 files changed, 70 insertions, 4 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js index 1dbfb1b98..e8987394f 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -116,13 +116,15 @@ function setupController (initState) { updateBadge() controller.txController.on('updateBadge', updateBadge) controller.messageManager.on('updateBadge', updateBadge) + controller.personalMessageManager.on('updateBadge', updateBadge) // plugin badge text function updateBadge () { var label = '' var unapprovedTxCount = controller.txController.unapprovedTxCount var unapprovedMsgCount = controller.messageManager.unapprovedMsgCount - var count = unapprovedTxCount + unapprovedMsgCount + var unapprovedPersonalMsgs = controller.personalMessageManager.unapprovedPersonalMsgCount + var count = unapprovedTxCount + unapprovedMsgCount + unapprovedPersonalMsgs if (count) { label = String(count) } 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/preferences.js b/app/scripts/controllers/preferences.js index 7212c7c43..aa8e05fcc 100644 --- a/app/scripts/controllers/preferences.js +++ b/app/scripts/controllers/preferences.js @@ -7,6 +7,7 @@ class PreferencesController { constructor (opts = {}) { const initState = extend({ frequentRpcList: [], + currentAccountTab: 'history', }, opts.initState) this.store = new ObservableStore(initState) } @@ -35,6 +36,13 @@ class PreferencesController { }) } + setCurrentAccountTab (currentAccountTab) { + return new Promise((resolve, reject) => { + this.store.updateState({ currentAccountTab }) + resolve() + }) + } + addToFrequentRpcList (_url) { const rpcList = this.getFrequentRpcList() const index = rpcList.findIndex((element) => { return element === _url }) diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index e3c2d74d3..1efa96610 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -384,13 +384,13 @@ module.exports = class TransactionController extends EventEmitter { // - `'signed'` the tx is signed // - `'submitted'` the tx is sent to a server // - `'confirmed'` the tx has been included in a block. + // - `'failed'` the tx failed for some reason, included on tx data. _setTxStatus (txId, status) { var txMeta = this.getTx(txId) txMeta.status = status this.emit(`${txMeta.id}:${status}`, txId) if (status === 'submitted' || status === 'rejected') { this.emit(`${txMeta.id}:finished`, txMeta) - } this.updateTx(txMeta) this.emit('updateBadge') 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 de9a15924..1a83c70f5 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(), @@ -280,6 +293,7 @@ module.exports = class MetamaskController extends EventEmitter { // PreferencesController setSelectedAddress: nodeify(preferencesController.setSelectedAddress).bind(preferencesController), + setCurrentAccountTab: nodeify(preferencesController.setCurrentAccountTab).bind(preferencesController), setDefaultRpc: nodeify(this.setDefaultRpc).bind(this), setCustomRpc: nodeify(this.setCustomRpc).bind(this), |