web3-wallets-kit
Version:
Package for connecting with Ethereum wallets for dApp
42 lines • 1.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
function checkLSAvailability() {
var testKey = '__web3wm_test__';
try {
localStorage.setItem(testKey, '__web3wm_test-value__');
localStorage.removeItem(testKey);
return true;
}
catch (_a) {
return false;
}
}
var LocalStorage = /** @class */ (function () {
function LocalStorage() {
this.isLocalStorageAvailable = null;
this.isLocalStorageAvailable = checkLSAvailability();
}
LocalStorage.prototype.set = function (key, value) {
this.isLocalStorageAvailable && localStorage.setItem(key, JSON.stringify(value));
};
LocalStorage.prototype.get = function (key, fallback) {
var defaultValue = fallback || null;
if (!this.isLocalStorageAvailable) {
return defaultValue;
}
var data = localStorage.getItem(key);
try {
return data ? JSON.parse(data) : defaultValue;
}
catch (e) {
localStorage.removeItem(key);
return defaultValue;
}
};
LocalStorage.prototype.remove = function (key) {
this.isLocalStorageAvailable && localStorage.removeItem(key);
};
return LocalStorage;
}());
exports.LocalStorage = LocalStorage;
//# sourceMappingURL=index.js.map