UNPKG

ribbit-wallet-connect

Version:

Next-generation multi-chain wallet and payments app that makes crypto simple, secure, and usable in daily life.

49 lines (48 loc) 1.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.clearWallet = exports.getWallet = exports.saveWallet = void 0; const KEY_PREFIX = 'ribbit_connected_wallet::'; function saveWallet(address, days = 10) { try { const expiry = Date.now() + days * 24 * 60 * 60 * 1000; localStorage.setItem(buildKey(), JSON.stringify({ address, expiry })); } catch (_a) { } } exports.saveWallet = saveWallet; function originKey() { return window.location.origin || window.location.hostname; } function buildKey() { const origin = originKey(); return `${KEY_PREFIX}${origin}`; } function getWallet() { try { const raw = localStorage.getItem(buildKey()); if (raw) { const { address, expiry } = JSON.parse(raw); if (Date.now() < expiry) { return address; } else { clearWallet(); return null; } } else { return null; } } catch (_a) { return null; } } exports.getWallet = getWallet; function clearWallet() { try { localStorage.removeItem(buildKey()); } catch (_a) { } } exports.clearWallet = clearWallet;