"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useFilteredProviders = void 0;
const live_env_1 = require("@ledgerhq/live-env");
const react_1 = require("react");
const swap_1 = require("../../../providers/swap");
const featureFlags_1 = require("../../../../featureFlags");
const useFilteredProviders = () => {
    const [providers, setProviders] = (0, react_1.useState)([]);
    const [loading, setLoading] = (0, react_1.useState)(true);
    const [error, setError] = (0, react_1.useState)(null);
    const ptxSwapMoonpayProviderFlag = (0, featureFlags_1.useFeature)("ptxSwapMoonpayProvider");
    const ptxSwapExodusProviderFlag = (0, featureFlags_1.useFeature)("ptxSwapExodusProvider");
    const fetchProviders = (0, react_1.useCallback)(async () => {
        try {
            const ledgerSignatureEnv = (0, live_env_1.getEnv)("MOCK_EXCHANGE_TEST_CONFIG") ? "test" : "prod";
            const partnerSignatureEnv = (0, live_env_1.getEnv)("MOCK_EXCHANGE_TEST_PARTNER") ? "test" : "prod";
            const data = await (0, swap_1.fetchAndMergeProviderData)({ ledgerSignatureEnv, partnerSignatureEnv });
            let filteredProviders = Object.keys(data);
            if (!ptxSwapMoonpayProviderFlag?.enabled) {
                filteredProviders = filteredProviders.filter(provider => provider !== "moonpay");
            }
            if (!ptxSwapExodusProviderFlag?.enabled) {
                filteredProviders = filteredProviders.filter(provider => provider !== "exodus");
            }
            setProviders(filteredProviders);
        }
        catch (error) {
            setError(error);
        }
        finally {
            setLoading(false);
        }
    }, [ptxSwapMoonpayProviderFlag, ptxSwapExodusProviderFlag]);
    (0, react_1.useEffect)(() => {
        fetchProviders();
    }, [fetchProviders]);
    return { providers, loading, error };
};
exports.useFilteredProviders = useFilteredProviders;
//# sourceMappingURL=useFilteredProviders.js.map