/** * 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 { getSwapProviders, watchSwapProviders } from '@ton/appkit'; import type { GetSwapProvidersReturnType } from '@ton/appkit'; import { useAppKit } from '../../settings/hooks/use-app-kit'; export type UseSwapProvidersReturnType = GetSwapProvidersReturnType; /** * Hook to get all registered swap providers. */ export const useSwapProviders = (): UseSwapProvidersReturnType => { const appKit = useAppKit(); const subscribe = useCallback( (onChange: () => void) => { return watchSwapProviders(appKit, { onChange }); }, [appKit], ); const getSnapshot = useCallback(() => { return getSwapProviders(appKit); }, [appKit]); return useSyncExternalStore(subscribe, getSnapshot, getSnapshot); };