1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 01:39:44 +01:00

Merge pull request #152 from MetaMask/FilterTransactionList

Filter transaction list for current network
This commit is contained in:
Dan Finlay 2016-04-27 18:46:12 -07:00
commit 9b524b4f28
7 changed files with 45 additions and 16 deletions

View File

@ -11,6 +11,7 @@ const createTxNotification = require('./lib/tx-notification.js')
const configManager = require('./lib/config-manager-singleton') const configManager = require('./lib/config-manager-singleton')
const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex
const HostStore = require('./lib/remote-store.js').HostStore const HostStore = require('./lib/remote-store.js').HostStore
const Web3 = require('web3')
// //
// connect to other contexts // connect to other contexts
@ -51,6 +52,7 @@ function setupTrustedCommunication(connectionStream){
var providerConfig = configManager.getProvider() var providerConfig = configManager.getProvider()
var idStore = new IdentityStore() var idStore = new IdentityStore()
var providerOpts = { var providerOpts = {
rpcUrl: configManager.getCurrentRpcAddress(), rpcUrl: configManager.getCurrentRpcAddress(),
getAccounts: function(cb){ getAccounts: function(cb){
@ -62,6 +64,9 @@ var providerOpts = {
signTransaction: idStore.signTransaction.bind(idStore), signTransaction: idStore.signTransaction.bind(idStore),
} }
var provider = MetaMaskProvider(providerOpts) var provider = MetaMaskProvider(providerOpts)
var web3 = new Web3(provider)
idStore.web3 = web3
idStore.getNetwork(3)
// log new blocks // log new blocks
provider.on('block', function(block){ provider.on('block', function(block){
@ -222,6 +227,7 @@ function addUnconfirmedTx(txParams, cb){
function setRpcTarget(rpcTarget){ function setRpcTarget(rpcTarget){
configManager.setRpcTarget(rpcTarget) configManager.setRpcTarget(rpcTarget)
chrome.runtime.reload() chrome.runtime.reload()
idStore.getNetwork(3) // 3 retry attempts
} }
function useEtherscanProvider() { function useEtherscanProvider() {

View File

@ -16,11 +16,11 @@ module.exports = IdentityStore
inherits(IdentityStore, EventEmitter) inherits(IdentityStore, EventEmitter)
function IdentityStore(ethStore) { function IdentityStore(opts = {}) {
EventEmitter.call(this) EventEmitter.call(this)
// we just use the ethStore to auto-add accounts // we just use the ethStore to auto-add accounts
this._ethStore = ethStore this._ethStore = opts.ethStore
// lightwallet key store // lightwallet key store
this._keyStore = null this._keyStore = null
// lightwallet wrapper // lightwallet wrapper
@ -110,6 +110,16 @@ IdentityStore.prototype.setSelectedAddress = function(address){
this._didUpdate() 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){ IdentityStore.prototype.setLocked = function(cb){
delete this._keyStore delete this._keyStore
delete this._idmgmt delete this._idmgmt
@ -137,6 +147,7 @@ IdentityStore.prototype.addUnconfirmedTransaction = function(txParams, cb){
var time = (new Date()).getTime() var time = (new Date()).getTime()
var txId = createId() var txId = createId()
txParams.metamaskId = txId txParams.metamaskId = txId
txParams.metamaskNetworkId = this._currentState.network
var txData = { var txData = {
id: txId, id: txId,
txParams: txParams, txParams: txParams,

View File

@ -17,7 +17,7 @@ injectCss(css)
async.parallel({ async.parallel({
currentDomain: getCurrentDomain, currentDomain: getCurrentDomain,
accountManager: connectToAccountManager, accountManager: connectToAccountManager,
}, getNetworkVersion) }, setupApp)
function connectToAccountManager(cb){ function connectToAccountManager(cb){
// setup communication with background // 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){ function setupApp(err, opts){
if (err) { if (err) {
alert(err.stack) alert(err.stack)

View File

@ -0,0 +1,11 @@
var assert = require('assert')
var linkGen = require('../../ui/lib/explorer-link')
describe('explorer-link', function() {
it('adds testnet prefix to morden test network', function() {
var result = linkGen('hash', '2')
assert.notEqual(result.indexOf('testnet'), -1, 'testnet injected')
})
})

View File

@ -15,7 +15,9 @@ describe('IdentityStore', function() {
window.localStorage = {} // Hacking localStorage support into JSDom window.localStorage = {} // Hacking localStorage support into JSDom
idStore = new IdentityStore({ idStore = new IdentityStore({
addAccount(acct) { accounts.push(acct) }, ethStore: {
addAccount(acct) { accounts.push(acct) },
},
}) })
idStore.createNewVault(password, entropy, (err, seeds) => { idStore.createNewVault(password, entropy, (err, seeds) => {
@ -32,7 +34,9 @@ describe('IdentityStore', function() {
window.localStorage = {} // Hacking localStorage support into JSDom window.localStorage = {} // Hacking localStorage support into JSDom
idStore = new IdentityStore({ idStore = new IdentityStore({
addAccount(acct) { newAccounts.push(acct) }, ethStore: {
addAccount(acct) { newAccounts.push(acct) },
},
}) })
}) })
@ -61,8 +65,8 @@ describe('IdentityStore', function() {
window.localStorage = {} // Hacking localStorage support into JSDom window.localStorage = {} // Hacking localStorage support into JSDom
idStore = new IdentityStore({ idStore = new IdentityStore({
addAccount(acct) { ethStore: {
accounts.push(acct) addAccount(acct) { accounts.push(acct) },
}, },
}) })
}) })

View File

@ -16,7 +16,7 @@ function mapStateToProps(state) {
address: state.appState.currentView.context, address: state.appState.currentView.context,
accountDetail: state.appState.accountDetail, accountDetail: state.appState.accountDetail,
transactions: state.metamask.transactions, transactions: state.metamask.transactions,
networkVersion: state.networkVersion, networkVersion: state.metamask.network,
} }
} }
@ -79,6 +79,7 @@ AccountDetailScreen.prototype.render = function() {
transactionList(transactions transactionList(transactions
.filter(tx => tx.txParams.from === state.address) .filter(tx => tx.txParams.from === state.address)
.filter(tx => tx.txParams.metamaskNetworkId === state.networkVersion)
.sort((a, b) => b.time - a.time), state.networkVersion), .sort((a, b) => b.time - a.time), state.networkVersion),
this.exportedAccount(accountDetail), this.exportedAccount(accountDetail),

View File

@ -1,10 +1,13 @@
module.exports = function(hash, network) { module.exports = function(hash, network) {
const net = parseInt(network)
let prefix let prefix
switch (network) { switch (net) {
case 1: // main net case 1: // main net
prefix = '' prefix = ''
break
case 2: // morden test net case 2: // morden test net
prefix = 'testnet.' prefix = 'testnet.'
break
default: default:
prefix = '' prefix = ''
} }