/** * Copyright (c) TonTech. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * */ import { useSyncExternalStore, useCallback } from 'react'; import { getConnectors, watchConnectors } from '@ton/appkit'; import type { GetConnectorsReturnType } from '@ton/appkit'; import { useAppKit } from '../../settings'; export type UseConnectorsReturnType = GetConnectorsReturnType; export const useConnectors = (): UseConnectorsReturnType => { const appKit = useAppKit(); const subscribe = useCallback( (onChange: () => void) => { return watchConnectors(appKit, { onChange }); }, [appKit], ); const getSnapshot = useCallback(() => { return getConnectors(appKit); }, [appKit]); return useSyncExternalStore(subscribe, getSnapshot, getSnapshot); };