From 18608e8c499e2f34fcdb5abe9b9b7680f6da295b Mon Sep 17 00:00:00 2001 From: gregs Date: Thu, 15 Jun 2023 13:33:19 -0300 Subject: [PATCH] fix import secret of watched wallet (#659) --- src/core/keychain/KeychainManager.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/core/keychain/KeychainManager.ts b/src/core/keychain/KeychainManager.ts index 2c4da0ebf8..15d5c0619f 100644 --- a/src/core/keychain/KeychainManager.ts +++ b/src/core/keychain/KeychainManager.ts @@ -149,6 +149,7 @@ class KeychainManager { default: throw new Error('Keychain type not recognized.'); } + await this.overrideReadOnlyKeychains(keychain); await this.checkForDuplicateInKeychain(keychain); this.state.keychains.push(keychain as Keychain); return keychain; @@ -257,6 +258,22 @@ class KeychainManager { return false; } + async overrideReadOnlyKeychains(incomingKeychain: Keychain) { + if (incomingKeychain.type === KeychainType.ReadOnlyKeychain) return; + const currentAccounts = await this.getAccounts(); + const incomingAccounts = await incomingKeychain.getAccounts(); + const conflictingAccounts = incomingAccounts.filter((acc) => + currentAccounts.includes(acc), + ); + await Promise.all( + conflictingAccounts.map(async (acc) => { + const wallet = await this.getWallet(acc); + const isReadOnly = wallet.type === KeychainType.ReadOnlyKeychain; + if (isReadOnly) this.removeAccount(acc); + }), + ); + } + async checkForDuplicateInKeychain(keychain: Keychain) { const existingAccounts = await this.getAccounts(); const newAccounts = await keychain.getAccounts();