mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 09:57:02 +01:00
Filter transaction list for current blockchain network
When starting up, we now create a `web3` inside the `background.js` process, which we pass to the `idStore` and ask for the current `network`. We include the `network` on `app.metamask.network` in the state object. We re-request the network when changing provider. We filter the transaction list for transactions that match the current network.
This commit is contained in:
parent
29718a82b6
commit
d017c28441
@ -52,6 +52,7 @@ function setupTrustedCommunication(connectionStream){
|
||||
|
||||
var providerConfig = configManager.getProvider()
|
||||
var idStore = new IdentityStore()
|
||||
|
||||
var providerOpts = {
|
||||
rpcUrl: configManager.getCurrentRpcAddress(),
|
||||
getAccounts: function(cb){
|
||||
@ -64,6 +65,8 @@ var providerOpts = {
|
||||
}
|
||||
var provider = MetaMaskProvider(providerOpts)
|
||||
var web3 = new Web3(provider)
|
||||
idStore.web3 = web3
|
||||
idStore.getNetwork(3)
|
||||
|
||||
// log new blocks
|
||||
provider.on('block', function(block){
|
||||
@ -207,18 +210,12 @@ function updateBadge(state){
|
||||
//
|
||||
|
||||
function addUnconfirmedTx(txParams, cb){
|
||||
|
||||
web3.version.getNetwork(function(err, network) {
|
||||
if (err) return cb(err)
|
||||
|
||||
txParams.metamaskNetworkId = network
|
||||
var txId = idStore.addUnconfirmedTransaction(txParams, cb)
|
||||
createTxNotification({
|
||||
title: 'New Unsigned Transaction',
|
||||
txParams: txParams,
|
||||
confirm: idStore.approveTransaction.bind(idStore, txId, noop),
|
||||
cancel: idStore.cancelTransaction.bind(idStore, txId),
|
||||
})
|
||||
var txId = idStore.addUnconfirmedTransaction(txParams, cb)
|
||||
createTxNotification({
|
||||
title: 'New Unsigned Transaction',
|
||||
txParams: txParams,
|
||||
confirm: idStore.approveTransaction.bind(idStore, txId, noop),
|
||||
cancel: idStore.cancelTransaction.bind(idStore, txId),
|
||||
})
|
||||
}
|
||||
|
||||
@ -230,6 +227,7 @@ function addUnconfirmedTx(txParams, cb){
|
||||
function setRpcTarget(rpcTarget){
|
||||
configManager.setRpcTarget(rpcTarget)
|
||||
chrome.runtime.reload()
|
||||
idStore.getNetwork(3) // 3 retry attempts
|
||||
}
|
||||
|
||||
function useEtherscanProvider() {
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
|
@ -16,7 +16,7 @@ function mapStateToProps(state) {
|
||||
address: state.appState.currentView.context,
|
||||
accountDetail: state.appState.accountDetail,
|
||||
transactions: state.metamask.transactions,
|
||||
networkVersion: state.networkVersion,
|
||||
networkVersion: state.metamask.network,
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,6 +79,7 @@ AccountDetailScreen.prototype.render = function() {
|
||||
|
||||
transactionList(transactions
|
||||
.filter(tx => tx.txParams.from === state.address)
|
||||
.filter(tx => tx.txParams.metamaskNetworkId === state.networkVersion)
|
||||
.sort((a, b) => b.time - a.time), state.networkVersion),
|
||||
this.exportedAccount(accountDetail),
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user