import localForage from 'localforage'; import { PrexStorage } from './PrexStorage'; export class LocalForageStorage implements PrexStorage { private store: LocalForage; constructor() { this.store = localForage.createInstance({ name: 'prex', version: 1.0, storeName: 'prex_address', // Should be alphanumeric, with underscores. description: 'address store', }); } async getItem(key: string): Promise { return this.store.getItem(key); } async setItem(key: string, value: T): Promise { await this.store.setItem(key, value); } async removeItem(key: string): Promise { await this.store.removeItem(key); } async getItemFromSessionStorage(key: string): Promise { const encoded = sessionStorage.getItem(key); if (!encoded) { return null; } return JSON.parse(encoded) as T; } async setItemToSessionStorage(key: string, value: T): Promise { sessionStorage.setItem( key, JSON.stringify(value, (_key, value) => { if (typeof value === 'bigint') { return value.toString(); } return value; }) ); } async removeItemFromSessionStorage(key: string): Promise { sessionStorage.removeItem(key); } }