aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/controllers/preferences.js
diff options
context:
space:
mode:
authorEsteban MIno <efmino@uc.cl>2018-08-04 02:56:02 +0800
committerEsteban MIno <efmino@uc.cl>2018-08-04 02:56:02 +0800
commit21a61f2987ae83a48bb1f7256ec9c34978413eb2 (patch)
tree3bc9ef3d342f17269942cd3fe58da1f3b97ef214 /app/scripts/controllers/preferences.js
parent0481335dda447ba4c228d146834952bac0ad641b (diff)
parentfa4423bab2886017996955f809b6e3102cbf1781 (diff)
downloadtangerine-wallet-browser-21a61f2987ae83a48bb1f7256ec9c34978413eb2.tar.gz
tangerine-wallet-browser-21a61f2987ae83a48bb1f7256ec9c34978413eb2.tar.zst
tangerine-wallet-browser-21a61f2987ae83a48bb1f7256ec9c34978413eb2.zip
merge develop
Diffstat (limited to 'app/scripts/controllers/preferences.js')
-rw-r--r--app/scripts/controllers/preferences.js30
1 files changed, 27 insertions, 3 deletions
diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js
index f1bd66889..8a4a63bb6 100644
--- a/app/scripts/controllers/preferences.js
+++ b/app/scripts/controllers/preferences.js
@@ -127,6 +127,30 @@ class PreferencesController {
}
/**
+ * Removes an address from state
+ *
+ * @param {string} address A hex address
+ * @returns {string} the address that was removed
+ */
+ removeAddress (address) {
+ const identities = this.store.getState().identities
+ if (!identities[address]) {
+ throw new Error(`${address} can't be deleted cause it was not found`)
+ }
+ delete identities[address]
+ this.store.updateState({ identities })
+
+ // If the selected account is no longer valid,
+ // select an arbitrary other account:
+ if (address === this.getSelectedAddress()) {
+ const selected = Object.keys(identities)[0]
+ this.setSelectedAddress(selected)
+ }
+ return address
+ }
+
+
+ /**
* Adds addresses to the identities object without removing identities
*
* @param {string[]} addresses An array of hex addresses
@@ -152,9 +176,9 @@ class PreferencesController {
* @returns {Promise<string>} selectedAddress the selected address.
*/
syncAddresses (addresses) {
- let { identities, lostIdentities } = this.store.getState()
+ const { identities, lostIdentities } = this.store.getState()
- let newlyLost = {}
+ const newlyLost = {}
Object.keys(identities).forEach((identity) => {
if (!addresses.includes(identity)) {
newlyLost[identity] = identities[identity]
@@ -169,7 +193,7 @@ class PreferencesController {
if (this.diagnostics) this.diagnostics.reportOrphans(newlyLost)
// store lost accounts
- for (let key in newlyLost) {
+ for (const key in newlyLost) {
lostIdentities[key] = newlyLost[key]
}
}