UNPKG

@particle-network/authkit

Version:

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

119 lines (117 loc) 4.1 kB
"use client"; import { useAuthCore, useConnect, useEthereum, useModalOptions, useParticleAuth, useSolana } from "./chunk-H5PUG6U3.mjs"; import "./chunk-55PCA22M.mjs"; // 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, _c; if (modalOptions.wallet !== false && walletEntryPlugin) { const walletOptions = { ...modalOptions.wallet, erc4337: modalOptions.erc4337, language: modalOptions.language, customStyle: { ...modalOptions.customStyle, supportChains: (_a = modalOptions.chains) == null ? void 0 : _a.map((item) => { var _a2; return { id: item.id, name: item.name, chainType: ((_a2 = item == null ? void 0 : item.custom) == null ? void 0 : _a2.chainType) || "evm" }; }) } }; walletEntryPlugin.init( { projectId: modalOptions.projectId, clientKey: modalOptions.clientKey, appId: modalOptions.appId }, walletOptions ); const onConnected = () => { walletEntryPlugin.setWalletCore({ ethereum: provider, solana: wallet, customEventHandler }); walletEntryPlugin.walletEntryCreate(); }; const onDisconnect = () => { walletEntryPlugin.walletEntryDestroy(); }; if (typeof window !== "undefined") { (_b = window.particleAuth) == null ? void 0 : _b.on(AuthCoreEvent.ParticleAuthDisconnect, onDisconnect); (_c = window.particleAuth) == null ? void 0 : _c.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, provider, wallet, customEventHandler, walletEntryPlugin]); useEffect(() => { console.log("modalOptions changed", modalOptions); }, [modalOptions]); useEffect(() => { console.log("provider changed", provider); }, [provider]); useEffect(() => { console.log("wallet changed", wallet); }, [wallet]); useEffect(() => { console.log("walletEntryPlugin changed", walletEntryPlugin); }, [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-XYANNNOQ.mjs.map