firefox-sync-no-handler.ts raw
1 /* eslint-disable @typescript-eslint/no-explicit-any */
2 import {
3 EncryptedVault,
4 StoredCashuMint,
5 StoredIdentity,
6 StoredNwcConnection,
7 StoredPermission,
8 BrowserSyncHandler,
9 StoredRelay,
10 } from '@common';
11 import browser from 'webextension-polyfill';
12
13 /**
14 * Handles the browser sync operations when the browser sync is enabled.
15 * If it's not enabled, it behaves like the local extension storage (which is fine).
16 */
17 export class FirefoxSyncNoHandler extends BrowserSyncHandler {
18 async loadUnmigratedData(): Promise<Partial<Record<string, any>>> {
19 const data = await browser.storage.local.get(null);
20
21 // Remove any available "ignore properties".
22 this.ignoreProperties.forEach((property) => {
23 delete data[property];
24 });
25 return data;
26 }
27
28 async saveAndSetFullData(data: EncryptedVault): Promise<void> {
29 await browser.storage.local.set(data as Record<string, any>);
30 this.setFullData(data);
31 }
32
33 async saveAndSetPartialData_Permissions(data: {
34 permissions: StoredPermission[];
35 }): Promise<void> {
36 await browser.storage.local.set(data);
37 this.setPartialData_Permissions(data);
38 }
39
40 async saveAndSetPartialData_Identities(data: {
41 identities: StoredIdentity[];
42 }): Promise<void> {
43 await browser.storage.local.set(data);
44 this.setPartialData_Identities(data);
45 }
46
47 async saveAndSetPartialData_SelectedIdentityId(data: {
48 selectedIdentityId: string | null;
49 }): Promise<void> {
50 await browser.storage.local.set(data);
51 this.setPartialData_SelectedIdentityId(data);
52 }
53
54 async saveAndSetPartialData_Relays(data: {
55 relays: StoredRelay[];
56 }): Promise<void> {
57 await browser.storage.local.set(data);
58 this.setPartialData_Relays(data);
59 }
60
61 async saveAndSetPartialData_NwcConnections(data: {
62 nwcConnections: StoredNwcConnection[];
63 }): Promise<void> {
64 await browser.storage.local.set(data);
65 this.setPartialData_NwcConnections(data);
66 }
67
68 async saveAndSetPartialData_CashuMints(data: {
69 cashuMints: StoredCashuMint[];
70 }): Promise<void> {
71 await browser.storage.local.set(data);
72 this.setPartialData_CashuMints(data);
73 }
74
75 async clearData(): Promise<void> {
76 const props = Object.keys(await this.loadUnmigratedData());
77 await browser.storage.local.remove(props);
78 }
79 }
80