UNPKG

@0xsequence/connect

Version:
47 lines 1.63 kB
"use strict"; 'use client'; Object.defineProperty(exports, "__esModule", { value: true }); exports.useSignInEmail = void 0; const react_1 = require("react"); const wagmi_1 = require("wagmi"); const localStorage_js_1 = require("../constants/localStorage.js"); /** * Hook to retrieve the email address associated with the currently connected wallet. * * This hook monitors the connection status and retrieves the stored email address when a wallet * is connected. It works with both WaaS (Wallet-as-a-Service) and universal wallet types. * The email is cleared when the wallet is disconnected. * * @see {@link https://docs.sequence.xyz/sdk/web/hooks/useSignInEmail} for more detailed documentation. * * @returns {string | null} The email address of the connected wallet user, or null if not connected * or no email is associated * * @example * ```tsx * const email = useSignInEmail() * if (email) { * console.log('Connected user email:', email) * } * ``` */ const useSignInEmail = () => { const { storage } = (0, wagmi_1.useConfig)(); const { isConnected } = (0, wagmi_1.useAccount)(); const [email, setEmail] = (0, react_1.useState)(null); const storeEmail = async () => { const storedEmail = await storage?.getItem(localStorage_js_1.LocalStorageKey.WaasSignInEmail); setEmail(storedEmail); }; (0, react_1.useEffect)(() => { if (isConnected) { storeEmail(); } else { setEmail(null); } }, [isConnected]); return email; }; exports.useSignInEmail = useSignInEmail; //# sourceMappingURL=useSignInEmail.js.map