UNPKG

@salad-labs/loopz-typescript

Version:
48 lines 2.3 kB
"use client"; import React, { useEffect, useMemo, useRef, useState } from "react"; import { Loopz } from "../../loopz"; import { PrivyProvider } from "@privy-io/react-auth"; import { PrivyWrapper } from "./privywrapper"; import { LoopzContext } from "../context/loopzcontext"; import { LoopzAuthProvider } from "./loopzauthprovider"; import { LoopzChatProvider } from "./loopzchatprovider"; export const LoopzProvider = ({ config, authConfig, chatConfig, devMode = false, enableStorage, children, }) => { const initialized = useRef(false); const [loopz, setLoopz] = useState({ initialized: false, instance: { auth: null, order: null, proposal: null, oracle: null, chat: null, notification: null, }, }); const privyConfig = useMemo(() => { const { privyClientConfig } = config; return Object.assign({ embeddedWallets: { createOnLogin: "users-without-wallets", } }, privyClientConfig); }, [config]); useEffect(() => { if (initialized.current) return; initialized.current = true; //Loopz.boot(config, { runAdapter: false }) -> runAdapter arg is false. Why? //It is false because we are executing Loopz in a React context and there is no need to inject a React component in the DOM. //in this way we are sure we will handle all the Privy interaction directly from the components defined in this file. Loopz.boot(config, { devMode, runAdapter: false, enableStorage, }).then((loopz) => setLoopz({ initialized: true, instance: loopz.init() })); }, [config, devMode, enableStorage]); if (!loopz.initialized) return null; return (React.createElement(LoopzContext.Provider, { value: loopz }, React.createElement(PrivyProvider, { appId: config.privyAppId, config: privyConfig }, React.createElement(PrivyWrapper, null, React.createElement(LoopzAuthProvider, Object.assign({}, authConfig), chatConfig ? (React.createElement(LoopzChatProvider, Object.assign({}, chatConfig), children)) : (React.createElement(React.Fragment, null, children))))))); }; //# sourceMappingURL=loopzprovider.js.map