aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorfrankiebee <frankie.diamond@gmail.com>2017-03-08 09:59:03 +0800
committerfrankiebee <frankie.diamond@gmail.com>2017-03-08 09:59:03 +0800
commit3e8b584c9811b06526e69203a5e03f8eb82e8211 (patch)
tree2e41de93a20356f584994cdeacde986050c5f3d0 /app
parentf162a11585392df5e593018a02549f8b03018d22 (diff)
downloadtangerine-wallet-browser-3e8b584c9811b06526e69203a5e03f8eb82e8211.tar
tangerine-wallet-browser-3e8b584c9811b06526e69203a5e03f8eb82e8211.tar.gz
tangerine-wallet-browser-3e8b584c9811b06526e69203a5e03f8eb82e8211.tar.bz2
tangerine-wallet-browser-3e8b584c9811b06526e69203a5e03f8eb82e8211.tar.lz
tangerine-wallet-browser-3e8b584c9811b06526e69203a5e03f8eb82e8211.tar.xz
tangerine-wallet-browser-3e8b584c9811b06526e69203a5e03f8eb82e8211.tar.zst
tangerine-wallet-browser-3e8b584c9811b06526e69203a5e03f8eb82e8211.zip
fix issue where account import allows for duplicates
Diffstat (limited to 'app')
-rw-r--r--app/scripts/keyring-controller.js23
1 files changed, 22 insertions, 1 deletions
diff --git a/app/scripts/keyring-controller.js b/app/scripts/keyring-controller.js
index e1b1c4335..7669b9f8f 100644
--- a/app/scripts/keyring-controller.js
+++ b/app/scripts/keyring-controller.js
@@ -164,8 +164,11 @@ class KeyringController extends EventEmitter {
return keyring.getAccounts()
})
.then((accounts) => {
+ return this.checkForDuplicate(type, accounts)
+ })
+ .then((checkedAccounts) => {
this.keyrings.push(keyring)
- return this.setupAccounts(accounts)
+ return this.setupAccounts(checkedAccounts)
})
.then(() => this.persistAllKeyrings())
.then(() => this.fullUpdate())
@@ -175,6 +178,24 @@ class KeyringController extends EventEmitter {
})
}
+ // For now just checks for simple key pairs
+ // but in the future
+ // should possibly add HD and other types
+ //
+ checkForDuplicate (type, newAccount) {
+ return this.getAccounts()
+ .then((accounts) => {
+ switch (type) {
+ case 'Simple Key Pair':
+ let isNotIncluded = !accounts.find((key) => key === newAccount[0] || key === ethUtil.stripHexPrefix(newAccount[0]))
+ return (isNotIncluded) ? Promise.resolve(newAccount) : Promise.reject(new Error('The account your are trying to import is a duplicate'))
+ default:
+ return Promise.resolve(newAccount)
+ }
+ })
+ }
+
+
// Add New Account
// @number keyRingNum
//