mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Persist selected account
When selecting an account, we now persist the selection to the `configManager`, so the selection can be restored when re-unlocking Metamask. Also found the bug where `rawtestrpc` was still being used as a default, and fixed it!
This commit is contained in:
parent
88ed546a9a
commit
1025eb3b4f
@ -102,6 +102,17 @@ ConfigManager.prototype.setWallet = function(wallet) {
|
|||||||
this.setData(data)
|
this.setData(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConfigManager.prototype.getSelectedAccount = function() {
|
||||||
|
var config = this.getConfig()
|
||||||
|
return config.selectedAccount
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfigManager.prototype.setSelectedAccount = function(address) {
|
||||||
|
var config = this.getConfig()
|
||||||
|
config.selectedAccount = address
|
||||||
|
this.setConfig(config)
|
||||||
|
}
|
||||||
|
|
||||||
ConfigManager.prototype.getWallet = function() {
|
ConfigManager.prototype.getWallet = function() {
|
||||||
return this.migrator.getData().wallet
|
return this.migrator.getData().wallet
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ const extend = require('xtend')
|
|||||||
const createId = require('web3-provider-engine/util/random-id')
|
const createId = require('web3-provider-engine/util/random-id')
|
||||||
const autoFaucet = require('./auto-faucet')
|
const autoFaucet = require('./auto-faucet')
|
||||||
const configManager = require('./config-manager-singleton')
|
const configManager = require('./config-manager-singleton')
|
||||||
const DEFAULT_RPC = 'https://rawtestrpc.metamask.io/'
|
const DEFAULT_RPC = 'https://testrpc.metamask.io/'
|
||||||
|
|
||||||
|
|
||||||
module.exports = IdentityStore
|
module.exports = IdentityStore
|
||||||
@ -72,8 +72,7 @@ IdentityStore.prototype.setStore = function(store){
|
|||||||
|
|
||||||
IdentityStore.prototype.clearSeedWordCache = function(cb) {
|
IdentityStore.prototype.clearSeedWordCache = function(cb) {
|
||||||
configManager.setShowSeedWords(false)
|
configManager.setShowSeedWords(false)
|
||||||
var accounts = this._loadIdentities()
|
cb(null, configManager.getSelectedAccount())
|
||||||
cb(null, accounts)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IdentityStore.prototype.getState = function(){
|
IdentityStore.prototype.getState = function(){
|
||||||
@ -85,6 +84,7 @@ IdentityStore.prototype.getState = function(){
|
|||||||
seedWords: seedWords,
|
seedWords: seedWords,
|
||||||
unconfTxs: configManager.unconfirmedTxs(),
|
unconfTxs: configManager.unconfirmedTxs(),
|
||||||
transactions: configManager.getTxList(),
|
transactions: configManager.getTxList(),
|
||||||
|
selectedAddress: configManager.getSelectedAccount(),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ IdentityStore.prototype.getSeedIfUnlocked = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
IdentityStore.prototype.getSelectedAddress = function(){
|
IdentityStore.prototype.getSelectedAddress = function(){
|
||||||
return this._currentState.selectedAddress
|
return configManager.getSelectedAccount()
|
||||||
}
|
}
|
||||||
|
|
||||||
IdentityStore.prototype.setSelectedAddress = function(address){
|
IdentityStore.prototype.setSelectedAddress = function(address){
|
||||||
@ -106,7 +106,7 @@ IdentityStore.prototype.setSelectedAddress = function(address){
|
|||||||
address = addresses[0]
|
address = addresses[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
this._currentState.selectedAddress = address
|
configManager.setSelectedAccount(address)
|
||||||
this._didUpdate()
|
this._didUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,8 +120,8 @@ IdentityStore.prototype.submitPassword = function(password, cb){
|
|||||||
this._tryPassword(password, (err) => {
|
this._tryPassword(password, (err) => {
|
||||||
if (err) return cb(err)
|
if (err) return cb(err)
|
||||||
// load identities before returning...
|
// load identities before returning...
|
||||||
var accounts = this._loadIdentities()
|
this._loadIdentities()
|
||||||
cb(null, accounts)
|
cb(null, configManager.getSelectedAccount())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,7 +213,6 @@ IdentityStore.prototype._loadIdentities = function(){
|
|||||||
if (!this._isUnlocked()) throw new Error('not unlocked')
|
if (!this._isUnlocked()) throw new Error('not unlocked')
|
||||||
|
|
||||||
var addresses = this._getAddresses()
|
var addresses = this._getAddresses()
|
||||||
var accountArray = []
|
|
||||||
addresses.forEach((address, i) => {
|
addresses.forEach((address, i) => {
|
||||||
// // add to ethStore
|
// // add to ethStore
|
||||||
this._ethStore.addAccount(address)
|
this._ethStore.addAccount(address)
|
||||||
@ -225,10 +224,8 @@ IdentityStore.prototype._loadIdentities = function(){
|
|||||||
mayBeFauceting: this._mayBeFauceting(i),
|
mayBeFauceting: this._mayBeFauceting(i),
|
||||||
}
|
}
|
||||||
this._currentState.identities[address] = identity
|
this._currentState.identities[address] = identity
|
||||||
accountArray.push(identity)
|
|
||||||
})
|
})
|
||||||
this._didUpdate()
|
this._didUpdate()
|
||||||
return accountArray
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// mayBeFauceting
|
// mayBeFauceting
|
||||||
|
@ -105,13 +105,13 @@ function goHome() {
|
|||||||
function tryUnlockMetamask(password) {
|
function tryUnlockMetamask(password) {
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
dispatch(this.unlockInProgress())
|
dispatch(this.unlockInProgress())
|
||||||
_accountManager.submitPassword(password, (err, accounts) => {
|
_accountManager.submitPassword(password, (err, selectedAccount) => {
|
||||||
dispatch(this.hideLoadingIndication())
|
dispatch(this.hideLoadingIndication())
|
||||||
if (err) {
|
if (err) {
|
||||||
dispatch(this.unlockFailed())
|
dispatch(this.unlockFailed())
|
||||||
} else {
|
} else {
|
||||||
dispatch(this.unlockMetamask())
|
dispatch(this.unlockMetamask())
|
||||||
dispatch(this.showAccountDetail(accounts[0].address))
|
dispatch(this.showAccountDetail(selectedAccount))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -130,7 +130,7 @@ function recoverFromSeed(password, seed) {
|
|||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
// dispatch(this.createNewVaultInProgress())
|
// dispatch(this.createNewVaultInProgress())
|
||||||
dispatch(this.showLoadingIndication())
|
dispatch(this.showLoadingIndication())
|
||||||
_accountManager.recoverFromSeed(password, seed, (err, accounts) => {
|
_accountManager.recoverFromSeed(password, seed, (err, selectedAccount) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
dispatch(this.hideLoadingIndication())
|
dispatch(this.hideLoadingIndication())
|
||||||
var message = err.message
|
var message = err.message
|
||||||
@ -138,7 +138,7 @@ function recoverFromSeed(password, seed) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dispatch(this.unlockMetamask())
|
dispatch(this.unlockMetamask())
|
||||||
dispatch(this.showAccountDetail(accounts[0].address))
|
dispatch(this.showAccountDetail(selectedAccount))
|
||||||
dispatch(this.hideLoadingIndication())
|
dispatch(this.hideLoadingIndication())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -281,9 +281,13 @@ function lockMetamask() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function showAccountDetail(address) {
|
function showAccountDetail(address) {
|
||||||
return {
|
return (dispatch) => {
|
||||||
|
_accountManager.setSelectedAddress(address)
|
||||||
|
|
||||||
|
dispatch({
|
||||||
type: this.SHOW_ACCOUNT_DETAIL,
|
type: this.SHOW_ACCOUNT_DETAIL,
|
||||||
value: address,
|
value: address,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ AccountPanel.prototype.render = function() {
|
|||||||
style: {
|
style: {
|
||||||
flex: '1 0 auto',
|
flex: '1 0 auto',
|
||||||
},
|
},
|
||||||
onClick: state.onShowDetail && state.onShowDetail.bind(null, identity.address),
|
onClick: (event) => state.onShowDetail(identity.address, event),
|
||||||
}, [
|
}, [
|
||||||
|
|
||||||
// account identicon
|
// account identicon
|
||||||
@ -53,9 +53,7 @@ AccountPanel.prototype.render = function() {
|
|||||||
|
|
||||||
// navigate to account detail
|
// navigate to account detail
|
||||||
!state.onShowDetail ? null :
|
!state.onShowDetail ? null :
|
||||||
h('.arrow-right.cursor-pointer', {
|
h('.arrow-right.cursor-pointer', [
|
||||||
onClick: state.onShowDetail && state.onShowDetail.bind(null, identity.address),
|
|
||||||
}, [
|
|
||||||
h('i.fa.fa-chevron-right.fa-lg'),
|
h('i.fa.fa-chevron-right.fa-lg'),
|
||||||
]),
|
]),
|
||||||
])
|
])
|
||||||
|
@ -7,12 +7,10 @@ module.exports = reduceApp
|
|||||||
function reduceApp(state, action) {
|
function reduceApp(state, action) {
|
||||||
|
|
||||||
// clone and defaults
|
// clone and defaults
|
||||||
var accounts = valuesFor(state.metamask.accounts)
|
|
||||||
var account = accounts.length ? valuesFor(state.metamask.accounts)[0].address : null
|
|
||||||
var defaultView = {
|
var defaultView = {
|
||||||
name: 'accountDetail',
|
name: 'accountDetail',
|
||||||
detailView: null,
|
detailView: null,
|
||||||
context: account,
|
context: state.metamask.selectedAccount,
|
||||||
}
|
}
|
||||||
|
|
||||||
// confirm seed words
|
// confirm seed words
|
||||||
|
Loading…
Reference in New Issue
Block a user