UNPKG

@sky-mavis/tanto-widget

Version:
73 lines 2.9 kB
import {jsx}from'@emotion/react/jsx-runtime';import {MotionConfig,LazyMotion,domAnimation}from'motion/react';import {useMemo,useEffect}from'react';import {useChains}from'wagmi';import {analytic}from'../../analytic.mjs';import {RONIN_WALLET_APP_DEEPLINK}from'../../constants/index.mjs';import {useConnectCallback}from'../../hooks/useConnectCallback.mjs';import {useConnectorRequestAnalyticInterceptor}from'../../hooks/useConnectorRequestAnalyticInterceptor.mjs';import {usePreloadTantoImages}from'../../hooks/usePreloadImages.mjs';import {useSolveRoninConnectionConflict}from'../../hooks/useSolveRoninConnectionConflict.mjs';import {useWalletConnectListener}from'../../hooks/useWalletConnectListener.mjs';import {isMobile}from'../../utils/index.mjs';import {openWindow}from'../../utils/openWindow.mjs';import {ThemeProvider}from'../theme/ThemeProvider.mjs';import {WidgetModalProvider}from'../widget-modal/WidgetModalProvider.mjs';import {TantoContext}from'./TantoContext.mjs';function TantoProvider({ config: customConfig, theme, customThemeToken, onConnect, onDisconnect, children }) { useSolveRoninConnectionConflict(); usePreloadTantoImages(); useConnectCallback({ onConnect: data => { onConnect?.(data); analytic.updateSession({ userAddress: data.address, force: true }); analytic.sendEvent('wallet_connect_success', { wallet_id: data.connectorId, address: data.address, chain_id: data.chainId }); }, onDisconnect: () => { onDisconnect?.(); analytic.sendEvent('sdk_disconnect').then(() => { analytic.updateSession({ userAddress: undefined, force: true }); }); } }); useWalletConnectListener({ onSignRequest: () => { if (isMobile()) openWindow(RONIN_WALLET_APP_DEEPLINK); } }); useConnectorRequestAnalyticInterceptor(); const chains = useChains(); const defaultTantoConfig = { reducedMotion: false, disableProfile: false, hideConnectSuccessPrompt: false, initialChainId: chains?.[0]?.id }; const config = useMemo(() => Object.assign({}, defaultTantoConfig, customConfig), [customConfig]); const contextValue = useMemo(() => ({ config }), [config]); /* Start Analytic Session */ useEffect(() => { analytic.updateSession({}); analytic.sendEvent('sdk_init'); }, []); return jsx(TantoContext.Provider, { value: contextValue, children: jsx(ThemeProvider, { theme: theme, customThemeToken: customThemeToken, children: jsx(MotionConfig, { reducedMotion: config.reducedMotion ? 'always' : 'never', children: jsx(LazyMotion, { features: domAnimation, strict: true, children: jsx(WidgetModalProvider, { children: children }) }) }) }) }); }export{TantoProvider};