From 66a1a81c1410c6fb77b1ec0dec4b6ad6cbfa0e7e Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Wed, 12 Feb 2025 19:26:58 +0100 Subject: [PATCH] WIP: add knownDevices to storage --- packages/suite/src/actions/suite/storageActions.ts | 6 ++++++ .../suite/src/middlewares/wallet/storageMiddleware.ts | 4 ++++ packages/suite/src/storage/definitions.ts | 9 +++++++++ packages/suite/src/storage/index.ts | 2 +- packages/suite/src/storage/migrations/index.ts | 4 ++++ packages/suite/src/support/suite/preloadStore.ts | 2 ++ 6 files changed, 26 insertions(+), 1 deletion(-) diff --git a/packages/suite/src/actions/suite/storageActions.ts b/packages/suite/src/actions/suite/storageActions.ts index 67083862271..1ec655fb545 100644 --- a/packages/suite/src/actions/suite/storageActions.ts +++ b/packages/suite/src/actions/suite/storageActions.ts @@ -102,6 +102,12 @@ export const saveCoinjoinDebugSettings = () => async (_dispatch: Dispatch, getSt db.addItem('coinjoinDebugSettings', debug || {}, 'debug', true); }; +export const saveKnownDevices = () => async (_dispatch: Dispatch, getState: GetState) => { + if (!(await db.isAccessible())) return; + const { pairedDevices } = getState().bluetooth; + db.addItem('knownDevices', { bluetooth: pairedDevices }, 'devices', true); +}; + export const saveFormDraft = async (key: string, draft: FieldValues) => { if (!(await db.isAccessible())) return; diff --git a/packages/suite/src/middlewares/wallet/storageMiddleware.ts b/packages/suite/src/middlewares/wallet/storageMiddleware.ts index 189c08876b9..3391c814c78 100644 --- a/packages/suite/src/middlewares/wallet/storageMiddleware.ts +++ b/packages/suite/src/middlewares/wallet/storageMiddleware.ts @@ -202,6 +202,10 @@ const storageMiddleware = (api: MiddlewareAPI) => { } } + if (deviceActions.connectDevice.match(action)) { + api.dispatch(storageActions.saveKnownDevices()); + } + if (sendFormActions.storeDraft.match(action)) { const device = selectSelectedDevice(api.getState()); const { formState, accountKey } = action.payload; diff --git a/packages/suite/src/storage/definitions.ts b/packages/suite/src/storage/definitions.ts index c5cc9eca643..bb7437ee17c 100644 --- a/packages/suite/src/storage/definitions.ts +++ b/packages/suite/src/storage/definitions.ts @@ -68,6 +68,15 @@ export interface SuiteDBSchema extends DBSchema { key: string; value: DeviceWithEmptyPath; }; + knownDevices: { + key: string; // device_id + value: { + bluetooth: any[]; + // thp: any[]; + // entropy_check_keys: any[]; + // validation_errors: any; // errors from onboarding? + }; + }; accounts: { key: string[]; value: Account; diff --git a/packages/suite/src/storage/index.ts b/packages/suite/src/storage/index.ts index a0bc06218c5..79c1baefbc6 100644 --- a/packages/suite/src/storage/index.ts +++ b/packages/suite/src/storage/index.ts @@ -5,7 +5,7 @@ import { reloadApp } from 'src/utils/suite/reload'; import type { SuiteDBSchema } from './definitions'; import { migrate } from './migrations'; -const VERSION = 52; // don't forget to add migration and CHANGELOG when changing versions! +const VERSION = 53; // don't forget to add migration and CHANGELOG when changing versions! /** * If the object stores don't already exist then creates them. diff --git a/packages/suite/src/storage/migrations/index.ts b/packages/suite/src/storage/migrations/index.ts index 2f1ee73f68b..74988c6f2a6 100644 --- a/packages/suite/src/storage/migrations/index.ts +++ b/packages/suite/src/storage/migrations/index.ts @@ -1251,6 +1251,10 @@ export const migrate: OnUpgradeFunc = async ( }); } + if (oldVersion < 53) { + db.createObjectStore('knownDevices'); + } + await migrationCoinmarketToTrading(db, oldVersion, newVersion, transaction); db.createObjectStore('security'); diff --git a/packages/suite/src/support/suite/preloadStore.ts b/packages/suite/src/support/suite/preloadStore.ts index 308eafa1123..a0f2e20d9d3 100644 --- a/packages/suite/src/support/suite/preloadStore.ts +++ b/packages/suite/src/support/suite/preloadStore.ts @@ -27,6 +27,7 @@ export const preloadStore = async () => { // load state from database const suiteSettings = await db.getItemByPK('suiteSettings', 'suite'); const devices = await db.getItemsExtended('devices'); + const knownDevices = await db.getItemByPK('knownDevices', 'devices'); const accounts = await db.getItemsExtended('accounts'); const discovery = await db.getItemsExtended('discovery'); const walletSettings = await db.getItemByPK('walletSettings', 'wallet'); @@ -52,6 +53,7 @@ export const preloadStore = async () => { suiteSettings, walletSettings, devices, + knownDevices, accounts, discovery, txs,