UNPKG

@wallet-ui/core

Version:
97 lines (91 loc) 2.37 kB
import { persistentAtom } from '@nanostores/persistent'; import { computed } from 'nanostores'; // src/clusters.ts function createSolanaCluster(props, { id, label, url }) { if (typeof props === "string") { return { id, label, url: props }; } return { id, label: props.label ?? label, url: props.url ?? url }; } function createSolanaDevnet(props = {}) { return createSolanaCluster(props, { id: "solana:devnet", label: "Devnet", url: "devnet" }); } function createSolanaLocalnet(props = {}) { return createSolanaCluster(props, { id: "solana:localnet", label: "Localnet", url: "localnet" }); } function createSolanaMainnet(props = {}) { return createSolanaCluster(props, { id: "solana:mainnet", label: "Mainnet", url: "mainnet" }); } function createSolanaTestnet(props = {}) { return createSolanaCluster(props, { id: "solana:testnet", label: "Testnet", url: "testnet" }); } var Storage = class { constructor(key, initial) { this.key = key; this.initial = initial; this.atom = persistentAtom(key, initial, { decode: JSON.parse, encode: JSON.stringify }); } atom; get() { return this.atom.get(); } set(value) { this.atom.set(value); } get value() { return computed(this.atom, (value) => value); } }; // src/create-storage.ts function createStorage({ initial, key }) { return new Storage(key, initial); } // src/create-storage-account.ts function createStorageAccount({ initial, key } = {}) { return createStorage({ initial, key: key ?? "wallet-ui:account" }); } // src/create-storage-cluster.ts function createStorageCluster({ initial, key } = {}) { return createStorage({ initial: initial ?? "solana:devnet", key: key ?? "wallet-ui:cluster" }); } // src/handle-copy-text.ts function handleCopyText(text) { if (!text) { return; } if (typeof globalThis === "undefined" || !globalThis.navigator || !globalThis.navigator.clipboard || !globalThis.navigator.clipboard.writeText) { return; } void globalThis.navigator.clipboard.writeText(text); } export { Storage, createSolanaDevnet, createSolanaLocalnet, createSolanaMainnet, createSolanaTestnet, createStorage, createStorageAccount, createStorageCluster, handleCopyText }; //# sourceMappingURL=index.browser.mjs.map //# sourceMappingURL=index.browser.mjs.map