UNPKG

@salad-labs/loopz-typescript

Version:
46 lines 2.24 kB
"use client"; import React, { useEffect, useMemo, useRef, useState } from "react"; import { Loopz } from "../../loopz"; import { LoopzContext } from "../context/loopzcontext"; import { LoopzAuthProvider } from "./loopzauthprovider"; import { LoopzChatProvider } from "./loopzchatprovider"; import { LoopzAuth } from "./loopzauth"; export const LoopzProvider = ({ config, 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(LoopzAuth, { devMode: devMode, intl: config.intl, apiKey: config.apiKey, logoURL: config.logoURL, tosURL: config.tosURL, privacyURL: config.privacyURL }, React.createElement(LoopzAuthProvider, null, chatConfig ? (React.createElement(LoopzChatProvider, Object.assign({}, chatConfig), children)) : (React.createElement(React.Fragment, null, children)))))); }; //# sourceMappingURL=loopzprovider.js.map