UNPKG

@particle-network/auth-core-modal

Version:

Auth Core provides MPC (Multi-Party Computation)-based threshold signatures.

102 lines (100 loc) 3.34 kB
"use client"; import { useAuthCore, useConnect, useEthereum, useModalOptions, useParticleAuth, useSolana } from "./chunk-LKAVNLWK.js"; import "./chunk-LQ53OFQ3.js"; // src/context/iframeWalletPlugin.tsx import { AuthCoreEvent, getUserInfo, isConnected } from "@particle-network/auth-core"; import React, { useCallback, useEffect } from "react"; var IframeWalletPlugin = () => { const { provider } = useEthereum(); const { wallet } = useSolana(); const { openAccountAndSecurity } = useAuthCore(); const { modalOptions } = useModalOptions(); const { connected } = useConnect(); const { walletEntryPlugin } = useParticleAuth(); const customEventHandler = useCallback( async (messageType) => { if (messageType === "open-account-and-security" /* OpenAccountAndSecurity */) { openAccountAndSecurity(); } else if (messageType === "get-user-info" /* GetUserInfo */) { return getUserInfo(); } }, [openAccountAndSecurity] ); useEffect(() => { var _a, _b; if (modalOptions.wallet !== false && walletEntryPlugin) { const walletOptions = { ...modalOptions.wallet, erc4337: modalOptions.erc4337, language: modalOptions.language }; walletEntryPlugin.init( { projectId: modalOptions.projectId, clientKey: modalOptions.clientKey, appId: modalOptions.appId }, walletOptions ); const onConnected = () => { walletEntryPlugin.walletEntryCreate(); }; const onDisconnect = () => { walletEntryPlugin.walletEntryDestroy(); }; if (typeof window !== "undefined") { (_a = window.particleAuth) == null ? void 0 : _a.on(AuthCoreEvent.ParticleAuthDisconnect, onDisconnect); (_b = window.particleAuth) == null ? void 0 : _b.on(AuthCoreEvent.ParticleAuthConnect, onConnected); } if (isConnected()) { walletEntryPlugin.setWalletCore({ ethereum: provider, solana: wallet, customEventHandler }); walletEntryPlugin.walletEntryCreate(); } return () => { var _a2, _b2; if (typeof window !== "undefined") { (_a2 = window.particleAuth) == null ? void 0 : _a2.off(AuthCoreEvent.ParticleAuthDisconnect, onDisconnect); (_b2 = window.particleAuth) == null ? void 0 : _b2.off(AuthCoreEvent.ParticleAuthConnect, onConnected); } }; } }, [ modalOptions.projectId, modalOptions.clientKey, modalOptions.appId, modalOptions.wallet, modalOptions.erc4337, modalOptions.language, provider, wallet, customEventHandler, walletEntryPlugin ]); useEffect(() => { if (connected && modalOptions.wallet !== false && walletEntryPlugin) { walletEntryPlugin.setWalletCore({ ethereum: provider, solana: wallet, customEventHandler }); } }, [connected, provider, wallet, modalOptions.wallet, customEventHandler, walletEntryPlugin]); return /* @__PURE__ */ React.createElement("div", { id: "auth-core-modal-wallet-plugin", style: { display: "none" } }, "Wallet Plugin"); }; var iframeWalletPlugin_default = IframeWalletPlugin; export { iframeWalletPlugin_default as default }; //# sourceMappingURL=iframeWalletPlugin-SAU3FVC6.js.map