diff options
Merge pull request #152 from MetaMask/FilterTransactionList
Filter transaction list for current network
Diffstat (limited to 'app')
-rw-r--r-- | app/scripts/background.js | 6 | ||||
-rw-r--r-- | app/scripts/lib/idStore.js | 15 | ||||
-rw-r--r-- | app/scripts/popup.js | 9 |
3 files changed, 20 insertions, 10 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js index e5281b8d6..523df1261 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -11,6 +11,7 @@ const createTxNotification = require('./lib/tx-notification.js') const configManager = require('./lib/config-manager-singleton') const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex const HostStore = require('./lib/remote-store.js').HostStore +const Web3 = require('web3') // // connect to other contexts @@ -51,6 +52,7 @@ function setupTrustedCommunication(connectionStream){ var providerConfig = configManager.getProvider() var idStore = new IdentityStore() + var providerOpts = { rpcUrl: configManager.getCurrentRpcAddress(), getAccounts: function(cb){ @@ -62,6 +64,9 @@ var providerOpts = { signTransaction: idStore.signTransaction.bind(idStore), } var provider = MetaMaskProvider(providerOpts) +var web3 = new Web3(provider) +idStore.web3 = web3 +idStore.getNetwork(3) // log new blocks provider.on('block', function(block){ @@ -222,6 +227,7 @@ function addUnconfirmedTx(txParams, cb){ function setRpcTarget(rpcTarget){ configManager.setRpcTarget(rpcTarget) chrome.runtime.reload() + idStore.getNetwork(3) // 3 retry attempts } function useEtherscanProvider() { diff --git a/app/scripts/lib/idStore.js b/app/scripts/lib/idStore.js index 92d0f9668..e9aaed82e 100644 --- a/app/scripts/lib/idStore.js +++ b/app/scripts/lib/idStore.js @@ -16,11 +16,11 @@ module.exports = IdentityStore inherits(IdentityStore, EventEmitter) -function IdentityStore(ethStore) { +function IdentityStore(opts = {}) { EventEmitter.call(this) // we just use the ethStore to auto-add accounts - this._ethStore = ethStore + this._ethStore = opts.ethStore // lightwallet key store this._keyStore = null // lightwallet wrapper @@ -110,6 +110,16 @@ IdentityStore.prototype.setSelectedAddress = function(address){ this._didUpdate() } +IdentityStore.prototype.getNetwork = function(tries) { + if (tries === 0) return + this.web3.version.getNetwork((err, network) => { + if (err) { + return this.getNetwork(tries - 1, cb) + } + this._currentState.network = network + }) +} + IdentityStore.prototype.setLocked = function(cb){ delete this._keyStore delete this._idmgmt @@ -137,6 +147,7 @@ IdentityStore.prototype.addUnconfirmedTransaction = function(txParams, cb){ var time = (new Date()).getTime() var txId = createId() txParams.metamaskId = txId + txParams.metamaskNetworkId = this._currentState.network var txData = { id: txId, txParams: txParams, diff --git a/app/scripts/popup.js b/app/scripts/popup.js index 6a39da661..e9ca7cd71 100644 --- a/app/scripts/popup.js +++ b/app/scripts/popup.js @@ -17,7 +17,7 @@ injectCss(css) async.parallel({ currentDomain: getCurrentDomain, accountManager: connectToAccountManager, -}, getNetworkVersion) +}, setupApp) function connectToAccountManager(cb){ // setup communication with background @@ -65,13 +65,6 @@ function getCurrentDomain(cb){ }) } -function getNetworkVersion(cb, results) { - web3.version.getNetwork(function(err, result) { - results.networkVersion = result - setupApp(err, results) - }) -} - function setupApp(err, opts){ if (err) { alert(err.stack) |