aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/controllers
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2018-06-05 04:43:26 +0800
committerDan Finlay <dan@danfinlay.com>2018-06-05 04:43:26 +0800
commit7382bd0847145b58db8414ae015c41778e5ebb75 (patch)
treeb080fc09f8223c89c87c354ee5aeb8d8a3ae7add /app/scripts/controllers
parent797e63b37bc10b2aa3cb78e65024c4a68c099f0b (diff)
downloadtangerine-wallet-browser-7382bd0847145b58db8414ae015c41778e5ebb75.tar
tangerine-wallet-browser-7382bd0847145b58db8414ae015c41778e5ebb75.tar.gz
tangerine-wallet-browser-7382bd0847145b58db8414ae015c41778e5ebb75.tar.bz2
tangerine-wallet-browser-7382bd0847145b58db8414ae015c41778e5ebb75.tar.lz
tangerine-wallet-browser-7382bd0847145b58db8414ae015c41778e5ebb75.tar.xz
tangerine-wallet-browser-7382bd0847145b58db8414ae015c41778e5ebb75.tar.zst
tangerine-wallet-browser-7382bd0847145b58db8414ae015c41778e5ebb75.zip
Add identity synchronizing code
Addresses #4475, where entries in the identities object do not necessarily have corresponding accounts in the vault. On password submission, this change passes known accounts to the preferencesController (responsible for nickname management), and removes unknown entries. Includes "TODO" notes for where we could log the issue to sentry or notify the user.
Diffstat (limited to 'app/scripts/controllers')
-rw-r--r--app/scripts/controllers/preferences.js31
1 files changed, 31 insertions, 0 deletions
diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js
index 760868ddf..426ee5a02 100644
--- a/app/scripts/controllers/preferences.js
+++ b/app/scripts/controllers/preferences.js
@@ -98,6 +98,37 @@ class PreferencesController {
this.store.updateState({ identities })
}
+ /*
+ * Synchronizes identity entries with known accounts.
+ * Removes any unknown identities, and returns the resulting selected address.
+ *
+ * @param {Array<string>} addresses known to the vault.
+ * @returns {Promise<string>} selectedAddress the selected address.
+ */
+ syncAddresses (addresses) {
+ const identities = this.store.getState().identities
+
+ Object.keys(identities).forEach((identity) => {
+ if (!addresses.includes(identity)) {
+ delete identities[identity]
+
+ // TODO: Report the bug to Sentry including the now-lost identity.
+ // TODO: Inform the user of the lost identity.
+ }
+ })
+
+ this.store.updateState({ identities })
+ this.addAddresses(addresses)
+
+ let selected = this.getSelectedAddress()
+ if (!addresses.includes(selected)) {
+ selected = addresses[0]
+ this.setSelectedAddress(selected)
+ }
+
+ return selected
+ }
+
/**
* Setter for the `selectedAddress` property
*