Skip to content

Commit

Permalink
fix import secret of watched wallet (#659)
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-schrammel authored Jun 15, 2023
1 parent ce340e1 commit 18608e8
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/core/keychain/KeychainManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 18608e8

Please sign in to comment.