Skip to content

Commit

Permalink
WIP: add knownDevices to storage
Browse files Browse the repository at this point in the history
  • Loading branch information
szymonlesisz committed Feb 18, 2025
1 parent c59120a commit 66a1a81
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/suite/src/actions/suite/storageActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 4 additions & 0 deletions packages/suite/src/middlewares/wallet/storageMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ const storageMiddleware = (api: MiddlewareAPI<Dispatch, AppState>) => {
}
}

if (deviceActions.connectDevice.match(action)) {
api.dispatch(storageActions.saveKnownDevices());
}

if (sendFormActions.storeDraft.match(action)) {
const device = selectSelectedDevice(api.getState());
const { formState, accountKey } = action.payload;
Expand Down
9 changes: 9 additions & 0 deletions packages/suite/src/storage/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/suite/src/storage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions packages/suite/src/storage/migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,10 @@ export const migrate: OnUpgradeFunc<SuiteDBSchema> = async (
});
}

if (oldVersion < 53) {
db.createObjectStore('knownDevices');
}

await migrationCoinmarketToTrading(db, oldVersion, newVersion, transaction);

db.createObjectStore('security');
Expand Down
2 changes: 2 additions & 0 deletions packages/suite/src/support/suite/preloadStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -52,6 +53,7 @@ export const preloadStore = async () => {
suiteSettings,
walletSettings,
devices,
knownDevices,
accounts,
discovery,
txs,
Expand Down

0 comments on commit 66a1a81

Please sign in to comment.