import type { RostrumParams } from "../../types/rostrum.types"; import { isNullOrEmpty, isTestnet } from "../../utils/common"; export abstract class KVStore { public abstract getValue(key: string): Promise; public abstract setValue(key: string, value: string): Promise; public abstract removeValue(key: string): Promise; public abstract clearData(): Promise; protected getPrefix(): string { return isTestnet() ? 'testnet-' : ''; } public async getEncryptedSeed(): Promise { return this.getValue("seed"); } public async saveEncryptedSeed(seed: string): Promise { return this.setValue('seed', seed); } public async getVersionCode(): Promise { return this.getValue("version-code"); } public async setVersionCode(code: string): Promise { return this.setValue('version-code', code); } public async getReleaseNumber(): Promise { return this.getValue("release-number"); } public async setReleaseNumber(release: string): Promise { return this.setValue('release-number', release); } public async getRostrumParams(): Promise { const params = await this.getValue(this.getPrefix() + "rostrum-params"); if (params) { return JSON.parse(params); } } public async saveRostrumParams(params: RostrumParams): Promise { return this.setValue(this.getPrefix() + "rostrum-params", JSON.stringify(params)); } public async removeRostrumParams(): Promise { return this.removeValue(this.getPrefix() + "rostrum-params"); } public async setHideZeroTokenConfig(hide: boolean): Promise { return this.setValue("zero-tokens", JSON.stringify(hide)); } public async getHideZeroTokenConfig(): Promise { const hide = await this.getValue("zero-tokens"); return hide === "true"; } public async setHideZeroVaultsConfig(hide: boolean): Promise { return this.setValue("zero-vaults", JSON.stringify(hide)); } public async getHideZeroVaultsConfig(): Promise { const hide = await this.getValue("zero-vaults"); return hide === "true"; } public async getSelectedCurrency(): Promise { const value = await this.getValue('selectedCurrency'); return value || 'usd'; } public async setSelectedCurrency(currency: string): Promise { return this.setValue('selectedCurrency', currency); } public async getUseBiometric(): Promise { const value = await this.getValue('biometrics'); return value === "true"; } public async setUseBiometric(useBiometric: boolean): Promise { return this.setValue('biometrics', JSON.stringify(useBiometric)); } public async getRequireAuth(): Promise { const value = await this.getValue('auth'); return isNullOrEmpty(value) || value === "true"; } public async setRequireAuth(requireAuth: boolean): Promise { await this.setValue('auth', JSON.stringify(requireAuth)); } public async getReleaseNotesTime(): Promise { const value = await this.getValue('show-notes'); return value ? Number(value) : undefined; } public async setReleaseNotesTime(time: string): Promise { if (isNullOrEmpty(time)) { await this.removeValue('show-notes'); } else { await this.setValue('show-notes', time); } } public async getIsTestnet(): Promise { const value = await this.getValue('testnet'); return value === "1"; } public async setIsTestnet(isTestnet: boolean): Promise { await this.setValue('testnet', isTestnet ? "1" : "0"); } public async getAutoLockSeconds(): Promise { const value = await this.getValue('auto-lock'); return value ? parseInt(value) : 60; } public async setAutoLockSeconds(autoLock: number): Promise { await this.setValue('auto-lock', `${autoLock}`); } }