aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2016-11-24 06:35:29 +0800
committerDan Finlay <dan@danfinlay.com>2016-11-24 06:35:29 +0800
commitd9dc2eac6305abda8da1113f16868bd362283582 (patch)
treef223b460c66da245520c8a47a6d00a361415aa66 /app
parent230a0ab876df82edc8147fd3c0ba18f10ffc4e3c (diff)
downloadtangerine-wallet-browser-d9dc2eac6305abda8da1113f16868bd362283582.tar
tangerine-wallet-browser-d9dc2eac6305abda8da1113f16868bd362283582.tar.gz
tangerine-wallet-browser-d9dc2eac6305abda8da1113f16868bd362283582.tar.bz2
tangerine-wallet-browser-d9dc2eac6305abda8da1113f16868bd362283582.tar.lz
tangerine-wallet-browser-d9dc2eac6305abda8da1113f16868bd362283582.tar.xz
tangerine-wallet-browser-d9dc2eac6305abda8da1113f16868bd362283582.tar.zst
tangerine-wallet-browser-d9dc2eac6305abda8da1113f16868bd362283582.zip
Fix more async usage of KeyringController
Diffstat (limited to 'app')
-rw-r--r--app/scripts/keyring-controller.js57
1 files changed, 32 insertions, 25 deletions
diff --git a/app/scripts/keyring-controller.js b/app/scripts/keyring-controller.js
index f93202523..4981c49df 100644
--- a/app/scripts/keyring-controller.js
+++ b/app/scripts/keyring-controller.js
@@ -98,9 +98,11 @@ module.exports = class KeyringController extends EventEmitter {
this.addNewKeyring('HD Key Tree', {
mnemonic: seed,
numberOfAccounts: 1,
- }, (err) => {
+ }).then(() => {
const firstKeyring = this.keyrings[0]
- const accounts = firstKeyring.getAccounts()
+ return firstKeyring.getAccounts()
+ })
+ .then((accounts) => {
const firstAccount = accounts[0]
const hexAccount = normalize(firstAccount)
this.configManager.setSelectedAccount(hexAccount)
@@ -108,7 +110,7 @@ module.exports = class KeyringController extends EventEmitter {
this.persistAllKeyrings()
.then(() => {
this.emit('update')
- cb(err)
+ cb(err, this.getState())
})
})
})
@@ -129,7 +131,6 @@ module.exports = class KeyringController extends EventEmitter {
this.configManager.setSelectedAccount(accounts[0])
return this.persistAllKeyrings()
})
-
} else {
return Promise.resolve()
}
@@ -154,15 +155,17 @@ module.exports = class KeyringController extends EventEmitter {
this.clearKeyrings()
this.addNewKeyring('HD Key Tree', {numberOfAccounts: 1}, (err) => {
if (err) return cb(err)
- const accounts = this.keyrings[0].getAccounts()
- const firstAccount = accounts[0]
- const hexAccount = normalize(firstAccount)
- this.configManager.setSelectedAccount(firstAccount)
+ this.keyrings[0].getAccounts()
+ .then((accounts) => {
+ const firstAccount = accounts[0]
+ const hexAccount = normalize(firstAccount)
+ this.configManager.setSelectedAccount(firstAccount)
- this.placeSeedWords()
- this.emit('newAccount', hexAccount)
- this.setupAccounts(accounts)
- this.persistAllKeyrings()
+ this.placeSeedWords()
+ this.emit('newAccount', hexAccount)
+ this.setupAccounts(accounts)
+ return this.persistAllKeyrings()
+ })
.then(() => {
cb()
})
@@ -176,7 +179,6 @@ module.exports = class KeyringController extends EventEmitter {
const firstKeyring = this.keyrings[0]
firstKeyring.serialize()
.then((serialized) => {
-
const seedWords = serialized.mnemonic
this.configManager.setSeedWords(seedWords)
@@ -207,16 +209,23 @@ module.exports = class KeyringController extends EventEmitter {
addNewKeyring (type, opts, cb) {
const Keyring = this.getKeyringClassForType(type)
const keyring = new Keyring(opts)
- const accounts = keyring.getAccounts()
-
- this.keyrings.push(keyring)
- this.setupAccounts(accounts)
- this.persistAllKeyrings()
- .then(() => {
- cb()
+ return keyring.getAccounts()
+ .then((accounts) => {
+ this.keyrings.push(keyring)
+ return this.setupAccounts(accounts)
+ }).then(() => {
+ return this.persistAllKeyrings()
+ }).then(() => {
+ if (cb) {
+ cb(null, keyring)
+ }
+ return keyring
})
.catch((reason) => {
- cb(reason)
+ if (cb) {
+ cb(reason)
+ }
+ return reason
})
}
@@ -240,8 +249,7 @@ module.exports = class KeyringController extends EventEmitter {
setupAccounts (accounts) {
return this.getAccounts()
.then((loadedAccounts) => {
- var arr = accounts || loadedAccounts
-
+ const arr = accounts || loadedAccounts
arr.forEach((account) => {
this.getBalanceAndNickname(account)
})
@@ -544,7 +552,7 @@ module.exports = class KeyringController extends EventEmitter {
txParams.gasLimit = normalize(txParams.gasLimit || txParams.gas)
txParams.nonce = normalize(txParams.nonce)
- let tx = new Transaction(txParams)
+ const tx = new Transaction(txParams)
keyring.signTransaction(address, tx)
.then((tx) => {
// Add the tx hash to the persisted meta-tx object
@@ -557,7 +565,6 @@ module.exports = class KeyringController extends EventEmitter {
var rawTx = ethUtil.bufferToHex(tx.serialize())
cb(null, rawTx)
})
-
} catch (e) {
cb(e)
}