aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/metamask-controller.js
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2017-09-30 02:19:54 +0800
committerDan Finlay <dan@danfinlay.com>2017-09-30 02:19:54 +0800
commit861bd877f3bf1c0c71a00f1b90048e93dec03488 (patch)
treee8947c07f7e4f38bbb64b9b2e72daec1230f1967 /app/scripts/metamask-controller.js
parentcdf41c28573822c7c4d50efe7dfa34a062825d7f (diff)
downloadtangerine-wallet-browser-861bd877f3bf1c0c71a00f1b90048e93dec03488.tar
tangerine-wallet-browser-861bd877f3bf1c0c71a00f1b90048e93dec03488.tar.gz
tangerine-wallet-browser-861bd877f3bf1c0c71a00f1b90048e93dec03488.tar.bz2
tangerine-wallet-browser-861bd877f3bf1c0c71a00f1b90048e93dec03488.tar.lz
tangerine-wallet-browser-861bd877f3bf1c0c71a00f1b90048e93dec03488.tar.xz
tangerine-wallet-browser-861bd877f3bf1c0c71a00f1b90048e93dec03488.tar.zst
tangerine-wallet-browser-861bd877f3bf1c0c71a00f1b90048e93dec03488.zip
Ensure selected account is always set if possible
Fixes #2218 Subscribes to keyringController, and if only one account exists, sets it as selected.
Diffstat (limited to 'app/scripts/metamask-controller.js')
-rw-r--r--app/scripts/metamask-controller.js9
1 files changed, 9 insertions, 0 deletions
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index 5b3161bc6..b28f2738a 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -100,6 +100,14 @@ module.exports = class MetamaskController extends EventEmitter {
encryptor: opts.encryptor || undefined,
})
+ // If only one account exists, make sure it is selected.
+ this.keyringController.store.subscribe((state) => {
+ const addresses = Object.keys(state.walletNicknames || {})
+ if (addresses.length === 1) {
+ const address = addresses[0]
+ this.preferencesController.setSelectedAddress(address)
+ }
+ })
this.keyringController.on('newAccount', (address) => {
this.preferencesController.setSelectedAddress(address)
this.accountTracker.addAccount(address)
@@ -222,6 +230,7 @@ module.exports = class MetamaskController extends EventEmitter {
const isUnlocked = this.keyringController.memStore.getState().isUnlocked
const result = []
const selectedAddress = this.preferencesController.getSelectedAddress()
+
// only show address if account is unlocked
if (isUnlocked && selectedAddress) {
result.push(selectedAddress)