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

Minimize repeated code.

This commit is contained in:
Kevin Serrano 2016-11-15 11:07:15 -08:00
parent 7de6b12aad
commit a4666de0ce
No known key found for this signature in database
GPG Key ID: 7CC862A58D2889B4
2 changed files with 7 additions and 8 deletions

View File

@ -153,13 +153,12 @@ module.exports = class KeyringController extends EventEmitter {
createFirstKeyTree (password, cb) { createFirstKeyTree (password, cb) {
this.clearKeyrings() this.clearKeyrings()
this.addNewKeyring('HD Key Tree', {numberOfAccounts: 1}, (err) => { this.addNewKeyring('HD Key Tree', {numberOfAccounts: 1}, (err) => {
const firstKeyring = this.keyrings[0] const accounts = this.keyrings[0].getAccounts()
const accounts = firstKeyring.getAccounts()
const firstAccount = accounts[0] const firstAccount = accounts[0]
const hexAccount = normalize(firstAccount) const hexAccount = normalize(firstAccount)
const seedWords = firstKeyring.serialize().mnemonic
this.configManager.setSelectedAccount(firstAccount) this.configManager.setSelectedAccount(firstAccount)
this.configManager.setSeedWords(seedWords)
this.placeSeedWords()
autoFaucet(hexAccount) autoFaucet(hexAccount)
this.setupAccounts(accounts) this.setupAccounts(accounts)
this.persistAllKeyrings() this.persistAllKeyrings()
@ -172,7 +171,7 @@ module.exports = class KeyringController extends EventEmitter {
}) })
} }
placeSeedWords (cb) { placeSeedWords () {
const firstKeyring = this.keyrings[0] const firstKeyring = this.keyrings[0]
const seedWords = firstKeyring.serialize().mnemonic const seedWords = firstKeyring.serialize().mnemonic
this.configManager.setSeedWords(seedWords) this.configManager.setSeedWords(seedWords)
@ -237,13 +236,13 @@ module.exports = class KeyringController extends EventEmitter {
setupAccounts (accounts) { setupAccounts (accounts) {
var arr = accounts || this.getAccounts() var arr = accounts || this.getAccounts()
arr.forEach((account) => { arr.forEach((account) => {
this.loadBalanceAndNickname(account) this.getBalanceAndNickname(account)
}) })
} }
// Takes an account address and an iterator representing // Takes an account address and an iterator representing
// the current number of named accounts. // the current number of named accounts.
loadBalanceAndNickname (account) { getBalanceAndNickname (account) {
const address = normalize(account) const address = normalize(account)
this.ethStore.addAccount(address) this.ethStore.addAccount(address)
this.createNickname(address) this.createNickname(address)

View File

@ -72,7 +72,7 @@ describe('KeyringController', function() {
} }
const mock = this.sinon.mock(keyringController) const mock = this.sinon.mock(keyringController)
mock.expects('loadBalanceAndNickname') mock.expects('getBalanceAndNickname')
.exactly(1) .exactly(1)
var keyring = keyringController.restoreKeyring(mockSerialized) var keyring = keyringController.restoreKeyring(mockSerialized)