UNPKG

@ledgerhq/live-common

Version:
45 lines 2.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useShowProviderLoadingTransition = useShowProviderLoadingTransition; exports.useProviderInterstitalEnabled = useProviderInterstitalEnabled; const react_1 = require("react"); const index_1 = require("../featureFlags/index"); const constants_1 = require("../wallet-api/constants"); const useInternalAppIds_1 = require("./useInternalAppIds"); function useShowProviderLoadingTransition({ isLoading, manifest, }) { const isEnabled = useProviderInterstitalEnabled({ manifest }); const [extendedInitialLoading, setExtendedInitialLoading] = (0, react_1.useState)(false); const timeoutRef = (0, react_1.useRef)(null); const buySellLoaderFF = (0, index_1.useFeature)("buySellLoader"); const durationMs = buySellLoaderFF?.params?.durationMs ?? 0; const internalAppIds = (0, useInternalAppIds_1.useInternalAppIds)() || constants_1.INTERNAL_APP_IDS; const isAppInternal = internalAppIds.includes(manifest.id); (0, react_1.useEffect)(() => { if (isEnabled && isLoading && !extendedInitialLoading) { setExtendedInitialLoading(true); if (timeoutRef.current) clearTimeout(timeoutRef.current); timeoutRef.current = setTimeout(() => { setExtendedInitialLoading(false); }, durationMs); } }, [durationMs, extendedInitialLoading, isAppInternal, isEnabled, isLoading]); (0, react_1.useEffect)(() => { return () => { if (timeoutRef.current) clearTimeout(timeoutRef.current); }; }, []); return isEnabled && (isLoading || extendedInitialLoading); } function useProviderInterstitalEnabled({ manifest }) { const buySellLoaderFF = (0, index_1.useFeature)("buySellLoader"); const internalAppIds = (0, useInternalAppIds_1.useInternalAppIds)() || constants_1.INTERNAL_APP_IDS; if (!manifest) { return false; } const isAppInternal = internalAppIds.includes(manifest.id); const isEnabled = buySellLoaderFF?.enabled && !isAppInternal; return isEnabled; } //# sourceMappingURL=useShowProviderLoadingTransition.js.map