@exodus/walletconnect-keyvaluestorage
Version:
Isomorphic Key-Value Storage
36 lines (35 loc) • 1.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.KeyValueStorage = void 0;
const tslib_1 = require("tslib");
const react_native_async_storage_1 = tslib_1.__importDefault(require("@exodus/react-native-async-storage"));
const walletconnect_safe_json_1 = require("@exodus/walletconnect-safe-json");
const shared_1 = require("../shared");
class KeyValueStorage {
constructor() {
this.asyncStorage = react_native_async_storage_1.default;
}
async getKeys() {
return this.asyncStorage.getAllKeys();
}
async getEntries() {
const keys = await this.getKeys();
const entries = await this.asyncStorage.multiGet(keys);
return entries.map(shared_1.parseEntry);
}
async getItem(key) {
const item = await this.asyncStorage.getItem(key);
if (typeof item === "undefined" || item === null) {
return undefined;
}
return (0, walletconnect_safe_json_1.safeJsonParse)(item);
}
async setItem(key, value) {
await this.asyncStorage.setItem(key, (0, walletconnect_safe_json_1.safeJsonStringify)(value));
}
async removeItem(key) {
await this.asyncStorage.removeItem(key);
}
}
exports.KeyValueStorage = KeyValueStorage;
exports.default = KeyValueStorage;