refactor: use centralized DATABASE_CONFIG for all store names in service.ts and wallet-setup.ts
This commit is contained in:
parent
09b34f7e07
commit
42f6e9ed05
@ -226,9 +226,9 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|||||||
console.log('🔄 IndexedDB upgrade needed, checking wallet store...');
|
console.log('🔄 IndexedDB upgrade needed, checking wallet store...');
|
||||||
|
|
||||||
// Créer le store wallet seulement s'il n'existe pas
|
// Créer le store wallet seulement s'il n'existe pas
|
||||||
if (!db.objectStoreNames.contains('wallet')) {
|
if (!db.objectStoreNames.contains(DATABASE_CONFIG.stores.wallet.name)) {
|
||||||
const store = db.createObjectStore('wallet', { keyPath: 'pre_id' });
|
const store = db.createObjectStore(DATABASE_CONFIG.stores.wallet.name, { keyPath: DATABASE_CONFIG.stores.wallet.keyPath as string });
|
||||||
console.log('✅ Wallet store created with keyPath: pre_id');
|
console.log(`✅ Wallet store created with keyPath: ${DATABASE_CONFIG.stores.wallet.keyPath}`);
|
||||||
} else {
|
} else {
|
||||||
console.log('✅ Wallet store already exists');
|
console.log('✅ Wallet store already exists');
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,6 +24,7 @@ import Database from './database.service';
|
|||||||
import { storeData, retrieveData } from './storage.service';
|
import { storeData, retrieveData } from './storage.service';
|
||||||
// import { testData } from './storage.service'; // Unused import
|
// import { testData } from './storage.service'; // Unused import
|
||||||
import { BackUp } from '../models/backup.model';
|
import { BackUp } from '../models/backup.model';
|
||||||
|
import { DATABASE_CONFIG } from './database-config';
|
||||||
|
|
||||||
export const U32_MAX = 4294967295;
|
export const U32_MAX = 4294967295;
|
||||||
|
|
||||||
@ -1160,11 +1161,11 @@ export default class Services {
|
|||||||
|
|
||||||
// Clear all stores
|
// Clear all stores
|
||||||
const db = await Database.getInstance();
|
const db = await Database.getInstance();
|
||||||
await db.clearStore('wallet');
|
await db.clearStore(DATABASE_CONFIG.stores.wallet.name);
|
||||||
await db.clearStore('shared_secrets');
|
await db.clearStore(DATABASE_CONFIG.stores.shared_secrets.name);
|
||||||
await db.clearStore('unconfirmed_secrets');
|
await db.clearStore(DATABASE_CONFIG.stores.unconfirmed_secrets.name);
|
||||||
await db.clearStore('processes');
|
await db.clearStore(DATABASE_CONFIG.stores.processes.name);
|
||||||
await db.clearStore('diffs');
|
await db.clearStore(DATABASE_CONFIG.stores.diffs.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
sendNewTxMessage(message: string) {
|
sendNewTxMessage(message: string) {
|
||||||
@ -1811,7 +1812,7 @@ export default class Services {
|
|||||||
|
|
||||||
async saveDeviceInDatabase(device: Device): Promise<void> {
|
async saveDeviceInDatabase(device: Device): Promise<void> {
|
||||||
const db = await Database.getInstance();
|
const db = await Database.getInstance();
|
||||||
const walletStore = 'wallet';
|
const walletStore = DATABASE_CONFIG.stores.wallet.name;
|
||||||
try {
|
try {
|
||||||
const prevDevice = await this.getDeviceFromDatabase();
|
const prevDevice = await this.getDeviceFromDatabase();
|
||||||
if (prevDevice) {
|
if (prevDevice) {
|
||||||
@ -1829,7 +1830,7 @@ export default class Services {
|
|||||||
|
|
||||||
async getDeviceFromDatabase(): Promise<Device | null> {
|
async getDeviceFromDatabase(): Promise<Device | null> {
|
||||||
const db = await Database.getInstance();
|
const db = await Database.getInstance();
|
||||||
const walletStore = 'wallet';
|
const walletStore = DATABASE_CONFIG.stores.wallet.name;
|
||||||
try {
|
try {
|
||||||
const dbRes = await db.getObject(walletStore, '1');
|
const dbRes = await db.getObject(walletStore, '1');
|
||||||
if (!dbRes) {
|
if (!dbRes) {
|
||||||
@ -1895,13 +1896,13 @@ export default class Services {
|
|||||||
const db = await Database.getInstance();
|
const db = await Database.getInstance();
|
||||||
try {
|
try {
|
||||||
// Clear all stores
|
// Clear all stores
|
||||||
await db.clearStore('wallet');
|
await db.clearStore(DATABASE_CONFIG.stores.wallet.name);
|
||||||
await db.clearStore('processes');
|
await db.clearStore(DATABASE_CONFIG.stores.processes.name);
|
||||||
await db.clearStore('shared_secrets');
|
await db.clearStore(DATABASE_CONFIG.stores.shared_secrets.name);
|
||||||
await db.clearStore('unconfirmed_secrets');
|
await db.clearStore(DATABASE_CONFIG.stores.unconfirmed_secrets.name);
|
||||||
await db.clearStore('diffs');
|
await db.clearStore(DATABASE_CONFIG.stores.diffs.name);
|
||||||
await db.clearStore('data');
|
await db.clearStore(DATABASE_CONFIG.stores.data.name);
|
||||||
await db.clearStore('labels');
|
await db.clearStore(DATABASE_CONFIG.stores.labels.name);
|
||||||
|
|
||||||
// Clear localStorage
|
// Clear localStorage
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user