aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/scripts/keyring-controller.js68
-rw-r--r--app/scripts/metamask-controller.js51
-rw-r--r--mock-dev.js16
-rw-r--r--test/unit/idStore-migration-test.js14
-rw-r--r--test/unit/keyring-controller-test.js6
-rw-r--r--ui/app/account-detail.js2
6 files changed, 75 insertions, 82 deletions
diff --git a/app/scripts/keyring-controller.js b/app/scripts/keyring-controller.js
index 111f679c8..12e3d2844 100644
--- a/app/scripts/keyring-controller.js
+++ b/app/scripts/keyring-controller.js
@@ -26,11 +26,16 @@ class KeyringController extends EventEmitter {
constructor (opts) {
super()
const initState = opts.initState || {}
+ this.keyringTypes = keyringTypes
this.store = new ObservableStore(initState)
+ this.memStore = new ObservableStore({
+ keyringTypes: this.keyringTypes.map(krt => krt.type),
+ keyrings: [],
+ identities: {},
+ })
this.configManager = opts.configManager
this.ethStore = opts.ethStore
this.encryptor = encryptor
- this.keyringTypes = keyringTypes
this.keyrings = []
this.identities = {} // Essentially a name hash
this.getNetwork = opts.getNetwork
@@ -66,28 +71,21 @@ class KeyringController extends EventEmitter {
// in this class, but will need to be Promisified when we move our
// persistence to an async model.
getState () {
- return Promise.all(this.keyrings.map(this.displayForKeyring))
- .then((displayKeyrings) => {
- const state = this.store.getState()
- // old wallet
- const wallet = this.configManager.getWallet()
- return {
- // computed
- isInitialized: (!!wallet || !!state.vault),
- isUnlocked: (!!this.password),
- keyrings: displayKeyrings,
- // hard coded
- keyringTypes: this.keyringTypes.map(krt => krt.type),
- // memStore
- identities: this.identities,
- // configManager
- seedWords: this.configManager.getSeedWords(),
- isDisclaimerConfirmed: this.configManager.getConfirmedDisclaimer(),
- currentFiat: this.configManager.getCurrentFiat(),
- conversionRate: this.configManager.getConversionRate(),
- conversionDate: this.configManager.getConversionDate(),
- }
- })
+
+ // old wallet
+ const memState = this.memStore.getState()
+ const result = {
+ // computed
+ isUnlocked: (!!this.password),
+ // memStore
+ keyringTypes: memState.keyringTypes,
+ identities: memState.identities,
+ keyrings: memState.keyrings,
+ // configManager
+ seedWords: this.configManager.getSeedWords(),
+ isDisclaimerConfirmed: this.configManager.getConfirmedDisclaimer(),
+ }
+ return result
}
// Create New Vault And Keychain
@@ -164,6 +162,7 @@ class KeyringController extends EventEmitter {
setLocked () {
this.password = null
this.keyrings = []
+ this._updateMemStoreKeyrings()
return this.fullUpdate()
}
@@ -245,7 +244,9 @@ class KeyringController extends EventEmitter {
walletNicknames[hexAddress] = label
this.store.updateState({ walletNicknames })
// update state on memStore
- this.identities[hexAddress].name = label
+ const identities = this.memStore.getState().identities
+ identities[hexAddress].name = label
+ this.memStore.updateState({ identities })
return Promise.resolve(label)
} catch (err) {
return Promise.reject(err)
@@ -372,14 +373,16 @@ class KeyringController extends EventEmitter {
// Takes an address, and assigns it an incremented nickname, persisting it.
createNickname (address) {
const hexAddress = normalizeAddress(address)
- const currentIdentityCount = Object.keys(this.identities).length + 1
+ const identities = this.memStore.getState().identities
+ const currentIdentityCount = Object.keys(identities).length + 1
const nicknames = this.store.getState().walletNicknames || {}
const existingNickname = nicknames[hexAddress]
const name = existingNickname || `Account ${currentIdentityCount}`
- this.identities[hexAddress] = {
+ identities[hexAddress] = {
address: hexAddress,
name,
}
+ this.memStore.updateState({ identities })
return this.saveAccountLabel(hexAddress, name)
}
@@ -568,8 +571,19 @@ class KeyringController extends EventEmitter {
this.ethStore.removeAccount(address)
})
+ // clear keyrings from memory
this.keyrings = []
- this.identities = {}
+ this.memStore.updateState({
+ keyrings: [],
+ identities: {},
+ })
+ }
+
+ _updateMemStoreKeyrings() {
+ Promise.all(this.keyrings.map(this.displayForKeyring))
+ .then((keyrings) => {
+ this.memStore.updateState({ keyrings })
+ })
}
}
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index 84ac2130e..fb5234c24 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -166,23 +166,31 @@ module.exports = class MetamaskController extends EventEmitter {
//
getState () {
- return this.keyringController.getState()
- .then((keyringControllerState) => {
- return extend(
- this.state,
- this.ethStore.getState(),
- this.configManager.getConfig(),
- this.txManager.getState(),
- this.messageManager.getState(),
- keyringControllerState,
- this.preferencesController.store.getState(),
- this.noticeController.getState(),
- {
- shapeShiftTxList: this.configManager.getShapeShiftTxList(),
- lostAccounts: this.configManager.getLostAccounts(),
- }
- )
- })
+
+ const wallet = this.configManager.getWallet()
+ const vault = this.keyringController.store.getState().vault
+ const isInitialized = (!!wallet || !!vault)
+ return extend(
+ {
+ isInitialized,
+ },
+ this.state,
+ this.ethStore.getState(),
+ this.txManager.getState(),
+ this.messageManager.getState(),
+ this.keyringController.getState(),
+ this.preferencesController.store.getState(),
+ this.noticeController.getState(),
+ // config manager
+ this.configManager.getConfig(),
+ {
+ shapeShiftTxList: this.configManager.getShapeShiftTxList(),
+ lostAccounts: this.configManager.getLostAccounts(),
+ currentFiat: this.configManager.getCurrentFiat(),
+ conversionRate: this.configManager.getConversionRate(),
+ conversionDate: this.configManager.getConversionDate(),
+ }
+ )
}
//
@@ -198,7 +206,7 @@ module.exports = class MetamaskController extends EventEmitter {
return {
// etc
- getState: nodeify(this.getState.bind(this)),
+ getState: (cb) => cb(null, this.getState()),
setRpcTarget: this.setRpcTarget.bind(this),
setProviderType: this.setProviderType.bind(this),
useEtherscanProvider: this.useEtherscanProvider.bind(this),
@@ -294,11 +302,8 @@ module.exports = class MetamaskController extends EventEmitter {
)
}
- sendUpdate () {
- this.getState()
- .then((state) => {
- this.emit('update', state)
- })
+ sendUpdate () {
+ this.emit('update', this.getState())
}
//
diff --git a/mock-dev.js b/mock-dev.js
index bd3a1ad77..b20c3be3a 100644
--- a/mock-dev.js
+++ b/mock-dev.js
@@ -16,7 +16,6 @@ const extend = require('xtend')
const render = require('react-dom').render
const h = require('react-hyperscript')
const pipe = require('mississippi').pipe
-const LocalStorageStore = require('obs-store/lib/localStorage')
const Root = require('./ui/app/root')
const configureStore = require('./ui/app/store')
const actions = require('./ui/app/actions')
@@ -27,7 +26,6 @@ const firstTimeState = require('./app/scripts/first-time-state')
const extension = require('./development/mockExtension')
const noop = function () {}
-const STORAGE_KEY = 'metamask-config'
//
// Query String
@@ -56,27 +54,15 @@ const injectCss = require('inject-css')
// MetaMask Controller
//
-let dataStore = new LocalStorageStore({ storageKey: STORAGE_KEY })
-// initial state for first time users
-if (!dataStore.getState()) {
- dataStore.putState(firstTimeState)
-}
-
const controller = new MetamaskController({
// User confirmation callbacks:
showUnconfirmedMessage: noop,
unlockAccountMessage: noop,
showUnapprovedTx: noop,
// initial state
- initState: dataStore.getState(),
+ initState: firstTimeState,
})
-// setup state persistence
-pipe(
- controller.store,
- dataStore
-)
-
//
// User Interface
//
diff --git a/test/unit/idStore-migration-test.js b/test/unit/idStore-migration-test.js
index 3aaf4bb94..81a99ef63 100644
--- a/test/unit/idStore-migration-test.js
+++ b/test/unit/idStore-migration-test.js
@@ -80,18 +80,4 @@ describe('IdentityStore to KeyringController migration', function() {
})
})
- describe('entering a password', function() {
- it('should identify an old wallet as an initialized keyring', function(done) {
- keyringController.configManager.setWallet('something')
- keyringController.getState()
- .then((state) => {
- assert(state.isInitialized, 'old vault counted as initialized.')
- assert(!state.lostAccounts, 'no lost accounts')
- done()
- })
- .catch((err) => {
- done(err)
- })
- })
- })
})
diff --git a/test/unit/keyring-controller-test.js b/test/unit/keyring-controller-test.js
index 347aa2bdf..aae4cdfd6 100644
--- a/test/unit/keyring-controller-test.js
+++ b/test/unit/keyring-controller-test.js
@@ -104,7 +104,7 @@ describe('KeyringController', function() {
it('should add the address to the identities hash', function() {
const fakeAddress = '0x12345678'
keyringController.createNickname(fakeAddress)
- const identities = keyringController.identities
+ const identities = keyringController.memStore.getState().identities
const identity = identities[fakeAddress]
assert.equal(identity.address, fakeAddress)
})
@@ -114,7 +114,9 @@ describe('KeyringController', function() {
it ('sets the nickname', function(done) {
const account = addresses[0]
var nick = 'Test nickname'
- keyringController.identities[ethUtil.addHexPrefix(account)] = {}
+ const identities = keyringController.memStore.getState().identities
+ identities[ethUtil.addHexPrefix(account)] = {}
+ keyringController.memStore.updateState({ identities })
keyringController.saveAccountLabel(account, nick)
.then((label) => {
try {
diff --git a/ui/app/account-detail.js b/ui/app/account-detail.js
index 1763c5374..514be7f25 100644
--- a/ui/app/account-detail.js
+++ b/ui/app/account-detail.js
@@ -29,7 +29,7 @@ function mapStateToProps (state) {
network: state.metamask.network,
unapprovedMsgs: valuesFor(state.metamask.unapprovedMsgs),
shapeShiftTxList: state.metamask.shapeShiftTxList,
- transactions: state.metamask.selectedAccountTxList || [],
+ transactions: state.metamask.selectedAddressTxList || [],
}
}