Skip to content

Commit 252f660

Browse files
committed
Fix walletStore re-encryption when record is unchanged
1 parent 6f9a8a7 commit 252f660

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/background/Wallet/Wallet.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,10 @@ export class Wallet {
306306
newCredentials,
307307
});
308308
this.userCredentials = newCredentials;
309-
// TODO: we need "updateWalletStore" to re-encrypt the record even if it's not changed
310-
await this.updateWalletStore(this.record);
309+
310+
const { encryptionKey } = this.userCredentials;
311+
await this.walletStore.encryptAndSave(this.id, encryptionKey, this.record);
312+
311313
this.setExpirationForSeedPhraseEncryptionKey(1000 * 120);
312314
}
313315

src/background/Wallet/persistence.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ export class WalletStore extends PersistentStore<WalletStoreState> {
4141
return this.lastRecord;
4242
}
4343

44-
async save(id: string, encryptionKey: string, record: WalletRecord) {
45-
if (this.lastRecord === record) {
46-
return;
47-
}
44+
/** Prefer WalletStore['save'] unless necessary */
45+
async encryptAndSave(
46+
id: string,
47+
encryptionKey: string,
48+
record: WalletRecord
49+
) {
4850
const encryptedRecord = await Model.encryptRecord(encryptionKey, record);
4951
this.setState((state) =>
5052
produce(state, (draft) => {
@@ -54,6 +56,13 @@ export class WalletStore extends PersistentStore<WalletStoreState> {
5456
this.lastRecord = record;
5557
}
5658

59+
async save(id: string, encryptionKey: string, record: WalletRecord) {
60+
if (this.lastRecord === record) {
61+
return;
62+
}
63+
await this.encryptAndSave(id, encryptionKey, record);
64+
}
65+
5766
deleteMany(keys: string[]) {
5867
this.setState((state) =>
5968
produce(state, (draft) => {

0 commit comments

Comments
 (0)