UNPKG

@sky-mavis/tanto-widget

Version:
31 lines 885 B
import {useRef}from'react';import {useAccountEffect as useAccountEffect$1}from'wagmi';import {useAuth}from'../contexts/auth/useAuth.mjs';import {useAuthEffect}from'./useAuthEffect.mjs';function useAccountEffect({ onConnect, onDisconnect }) { const { enable: enableAuth } = useAuth(); const pendingConnectionRef = useRef(null); useAccountEffect$1({ onConnect: data => { if (!enableAuth) { onConnect?.(data); return; } pendingConnectionRef.current = data; }, onDisconnect: () => { pendingConnectionRef.current = null; onDisconnect?.(); } }); useAuthEffect({ onSuccess: () => { const pendingConnection = pendingConnectionRef.current; if (pendingConnection) { onConnect?.(pendingConnection); pendingConnectionRef.current = null; } } }); }export{useAccountEffect};