@shift-code/cli
Version:
Redeem Gearbox SHiFT codes automatically
43 lines • 1.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.metaCacheExists = metaCacheExists;
exports.loadMetaCache = loadMetaCache;
exports.saveMetaCache = saveMetaCache;
exports.saveMetaActiveAccount = saveMetaActiveAccount;
exports.saveMetaAccount = saveMetaAccount;
exports.clearMetaActiveAccount = clearMetaActiveAccount;
const store_1 = require("../store");
async function metaCacheExists() {
const exists = await (0, store_1.storeExists)(store_1.META_CACHE, store_1.META_FILE);
return exists;
}
async function loadMetaCache() {
const cache = await (0, store_1.loadContents)(store_1.META_CACHE, store_1.META_FILE, {});
// Bug caused id to be empty, clear it
if (cache.activeAccountID === '') {
clearMetaActiveAccount('');
}
return cache;
}
async function saveMetaCache(data) {
await (0, store_1.storeContents)(store_1.META_CACHE, store_1.META_FILE, data);
}
async function saveMetaActiveAccount(accountID) {
const cache = await loadMetaCache();
cache.activeAccountID = accountID;
await saveMetaCache(cache);
}
async function saveMetaAccount(accountID) {
const cache = await loadMetaCache();
if (!cache.accounts)
cache.accounts = [];
cache.accounts = Array.from(new Set([...cache.accounts, accountID]));
await saveMetaCache(cache);
}
async function clearMetaActiveAccount(accountID) {
const cache = await loadMetaCache();
delete cache.activeAccountID;
cache.accounts = cache.accounts?.filter((id) => id !== accountID);
await saveMetaCache(cache);
}
//# sourceMappingURL=meta.js.map