mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Minimize dispatches by using emitters and relying on state updates.
This commit is contained in:
parent
e18109f1ea
commit
5bfb700fa8
@ -108,7 +108,7 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
this.setupAccounts(accounts)
|
this.setupAccounts(accounts)
|
||||||
|
|
||||||
this.emit('update')
|
this.emit('update')
|
||||||
cb(null, this.getState())
|
cb()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -163,7 +163,7 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
this.setupAccounts(accounts)
|
this.setupAccounts(accounts)
|
||||||
this.persistAllKeyrings()
|
this.persistAllKeyrings()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
cb(err, this.getState())
|
cb(err)
|
||||||
})
|
})
|
||||||
.catch((reason) => {
|
.catch((reason) => {
|
||||||
cb(reason)
|
cb(reason)
|
||||||
@ -173,9 +173,7 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
|
|
||||||
placeSeedWords () {
|
placeSeedWords () {
|
||||||
const firstKeyring = this.keyrings[0]
|
const firstKeyring = this.keyrings[0]
|
||||||
console.log(firstKeyring)
|
|
||||||
const seedWords = firstKeyring.serialize().mnemonic
|
const seedWords = firstKeyring.serialize().mnemonic
|
||||||
console.log(seedWords)
|
|
||||||
this.configManager.setSeedWords(seedWords)
|
this.configManager.setSeedWords(seedWords)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,7 +186,7 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
this.keyrings = keyrings
|
this.keyrings = keyrings
|
||||||
this.setupAccounts()
|
this.setupAccounts()
|
||||||
this.emit('update')
|
this.emit('update')
|
||||||
cb(null, this.getState())
|
cb()
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
@ -215,7 +213,7 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
this.setupAccounts(accounts)
|
this.setupAccounts(accounts)
|
||||||
this.persistAllKeyrings()
|
this.persistAllKeyrings()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
cb(null, this.getState())
|
cb()
|
||||||
})
|
})
|
||||||
.catch((reason) => {
|
.catch((reason) => {
|
||||||
cb(reason)
|
cb(reason)
|
||||||
@ -228,7 +226,7 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
this.setupAccounts(accounts)
|
this.setupAccounts(accounts)
|
||||||
this.persistAllKeyrings()
|
this.persistAllKeyrings()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
cb(null, this.getState())
|
cb()
|
||||||
})
|
})
|
||||||
.catch((reason) => {
|
.catch((reason) => {
|
||||||
cb(reason)
|
cb(reason)
|
||||||
@ -521,6 +519,7 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
setLocked (cb) {
|
setLocked (cb) {
|
||||||
this.key = null
|
this.key = null
|
||||||
this.keyrings = []
|
this.keyrings = []
|
||||||
|
this.emit('update')
|
||||||
cb()
|
cb()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,12 +161,11 @@ function tryUnlockMetamask (password) {
|
|||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
dispatch(actions.showLoadingIndication())
|
dispatch(actions.showLoadingIndication())
|
||||||
dispatch(actions.unlockInProgress())
|
dispatch(actions.unlockInProgress())
|
||||||
background.submitPassword(password, (err, newState) => {
|
background.submitPassword(password, (err) => {
|
||||||
dispatch(actions.hideLoadingIndication())
|
dispatch(actions.hideLoadingIndication())
|
||||||
if (err) {
|
if (err) {
|
||||||
dispatch(actions.unlockFailed(err.message))
|
dispatch(actions.unlockFailed(err.message))
|
||||||
} else {
|
} else {
|
||||||
dispatch(this.updateMetamaskState(newState))
|
|
||||||
let selectedAccount
|
let selectedAccount
|
||||||
try {
|
try {
|
||||||
selectedAccount = newState.metamask.selectedAccount
|
selectedAccount = newState.metamask.selectedAccount
|
||||||
@ -195,23 +194,19 @@ function confirmSeedWords () {
|
|||||||
function createNewVaultAndRestore (password, seed) {
|
function createNewVaultAndRestore (password, seed) {
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
dispatch(actions.showLoadingIndication())
|
dispatch(actions.showLoadingIndication())
|
||||||
background.createNewVaultAndRestore(password, seed, (err, newState) => {
|
background.createNewVaultAndRestore(password, seed, (err) => {
|
||||||
dispatch(actions.hideLoadingIndication())
|
dispatch(actions.hideLoadingIndication())
|
||||||
if (err) return dispatch(actions.displayWarning(err.message))
|
if (err) return dispatch(actions.displayWarning(err.message))
|
||||||
dispatch(this.updateMetamaskState(newState))
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function createNewVaultAndKeychain (password, entropy) {
|
function createNewVaultAndKeychain (password, entropy) {
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
background.createNewVaultAndKeychain(password, entropy, (err, newState) => {
|
background.createNewVaultAndKeychain(password, entropy, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return dispatch(actions.showWarning(err.message))
|
return dispatch(actions.showWarning(err.message))
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch(this.updateMetamaskState(newState))
|
|
||||||
dispatch(this.showNewVaultSeed())
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -225,11 +220,10 @@ function revealSeedConfirmation () {
|
|||||||
function requestRevealSeed (password) {
|
function requestRevealSeed (password) {
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
dispatch(actions.showLoadingIndication())
|
dispatch(actions.showLoadingIndication())
|
||||||
background.submitPassword(password, (err, newState) => {
|
background.submitPassword(password, (err) => {
|
||||||
dispatch(actions.hideLoadingIndication())
|
dispatch(actions.hideLoadingIndication())
|
||||||
if (err) return dispatch(actions.displayWarning(err.message))
|
if (err) return dispatch(actions.displayWarning(err.message))
|
||||||
background.placeSeedWords()
|
background.placeSeedWords()
|
||||||
dispatch(actions.showNewVaultSeed())
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -238,13 +232,11 @@ function requestRevealSeed (password) {
|
|||||||
function addNewKeyring (type, opts) {
|
function addNewKeyring (type, opts) {
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
dispatch(actions.showLoadingIndication())
|
dispatch(actions.showLoadingIndication())
|
||||||
background.addNewKeyring(type, opts, (err, newState) => {
|
background.addNewKeyring(type, opts, (err) => {
|
||||||
dispatch(this.hideLoadingIndication())
|
dispatch(this.hideLoadingIndication())
|
||||||
if (err) {
|
if (err) {
|
||||||
return dispatch(actions.showWarning(err))
|
return dispatch(actions.showWarning(err))
|
||||||
}
|
}
|
||||||
dispatch(this.updateMetamaskState(newState))
|
|
||||||
dispatch(this.showAccountsPage())
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -252,12 +244,11 @@ function addNewKeyring (type, opts) {
|
|||||||
function addNewAccount (ringNumber = 0) {
|
function addNewAccount (ringNumber = 0) {
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
dispatch(actions.showLoadingIndication())
|
dispatch(actions.showLoadingIndication())
|
||||||
background.addNewAccount(ringNumber, (err, newState) => {
|
background.addNewAccount(ringNumber, (err) => {
|
||||||
dispatch(this.hideLoadingIndication())
|
dispatch(this.hideLoadingIndication())
|
||||||
if (err) {
|
if (err) {
|
||||||
return dispatch(actions.showWarning(err))
|
return dispatch(actions.showWarning(err))
|
||||||
}
|
}
|
||||||
dispatch(this.updateMetamaskState(newState))
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -457,10 +448,6 @@ function lockMetamask () {
|
|||||||
if (err) {
|
if (err) {
|
||||||
return dispatch(actions.displayWarning(err.message))
|
return dispatch(actions.displayWarning(err.message))
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch({
|
|
||||||
type: actions.LOCK_METAMASK,
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user