UNPKG

@ledgerhq/live-common

Version:
41 lines 1.85 kB
import { useEffect, useRef, useState } from "react"; import { useFeature } from "../featureFlags/index"; import { INTERNAL_APP_IDS } from "../wallet-api/constants"; import { useInternalAppIds } from "./useInternalAppIds"; export function useShowProviderLoadingTransition({ isLoading, manifest, }) { const isEnabled = useProviderInterstitalEnabled({ manifest }); const [extendedInitialLoading, setExtendedInitialLoading] = useState(false); const timeoutRef = useRef(null); const buySellLoaderFF = useFeature("buySellLoader"); const durationMs = buySellLoaderFF?.params?.durationMs ?? 0; const internalAppIds = useInternalAppIds() || INTERNAL_APP_IDS; const isAppInternal = internalAppIds.includes(manifest.id); useEffect(() => { if (isEnabled && isLoading && !extendedInitialLoading) { setExtendedInitialLoading(true); if (timeoutRef.current) clearTimeout(timeoutRef.current); timeoutRef.current = setTimeout(() => { setExtendedInitialLoading(false); }, durationMs); } }, [durationMs, extendedInitialLoading, isAppInternal, isEnabled, isLoading]); useEffect(() => { return () => { if (timeoutRef.current) clearTimeout(timeoutRef.current); }; }, []); return isEnabled && (isLoading || extendedInitialLoading); } export function useProviderInterstitalEnabled({ manifest }) { const buySellLoaderFF = useFeature("buySellLoader"); const internalAppIds = useInternalAppIds() || INTERNAL_APP_IDS; if (!manifest) { return false; } const isAppInternal = internalAppIds.includes(manifest.id); const isEnabled = buySellLoaderFF?.enabled && !isAppInternal; return isEnabled; } //# sourceMappingURL=useShowProviderLoadingTransition.js.map