"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sendFeatures = exports.supportsNewFlows = exports.getSendDescriptor = exports.getDescriptor = exports.newFlowsConfig = void 0;
const impl_1 = require("./impl");
const index_1 = require("../config/index");
const descriptor_1 = require("../families/algorand/descriptor");
const descriptor_2 = require("../families/aptos/descriptor");
const descriptor_3 = require("../families/bitcoin/descriptor");
const descriptor_4 = require("../families/canton/descriptor");
const descriptor_5 = require("../families/cardano/descriptor");
const descriptor_6 = require("../families/casper/descriptor");
const descriptor_7 = require("../families/celo/descriptor");
const descriptor_8 = require("../families/cosmos/descriptor");
const descriptor_9 = require("../families/evm/descriptor");
const descriptor_10 = require("../families/filecoin/descriptor");
const descriptor_11 = require("../families/hedera/descriptor");
const descriptor_12 = require("../families/icon/descriptor");
const descriptor_13 = require("../families/internet_computer/descriptor");
const descriptor_14 = require("../families/kaspa/descriptor");
const descriptor_15 = require("../families/mina/descriptor");
const descriptor_16 = require("../families/multiversx/descriptor");
const descriptor_17 = require("../families/near/descriptor");
const descriptor_18 = require("../families/polkadot/descriptor");
const descriptor_19 = require("../families/solana/descriptor");
const descriptor_20 = require("../families/stacks/descriptor");
const descriptor_21 = require("../families/stellar/descriptor");
const descriptor_22 = require("../families/sui/descriptor");
const descriptor_23 = require("../families/tezos/descriptor");
const descriptor_24 = require("../families/ton/descriptor");
const descriptor_25 = require("../families/tron/descriptor");
const descriptor_26 = require("../families/vechain/descriptor");
const descriptor_27 = require("../families/xrp/descriptor");
exports.newFlowsConfig = {
    algorand: { send: false },
    aptos: { send: false },
    bitcoin: { send: false },
    canton: { send: false },
    cardano: { send: false },
    casper: { send: false },
    celo: { send: false },
    cosmos: { send: false },
    evm: { send: false },
    filecoin: { send: false },
    hedera: { send: false },
    icon: { send: false },
    internet_computer: { send: false },
    kaspa: { send: false },
    mina: { send: false },
    multiversx: { send: false },
    near: { send: false },
    polkadot: { send: false },
    solana: { send: false },
    stacks: { send: false },
    stellar: { send: false },
    sui: { send: false },
    tezos: { send: false },
    ton: { send: false },
    tron: { send: false },
    vechain: { send: false },
    xrp: { send: false },
};
const descriptorRegistry = {
    algorand: descriptor_1.descriptor,
    aptos: descriptor_2.descriptor,
    bitcoin: descriptor_3.descriptor,
    canton: descriptor_4.descriptor,
    cardano: descriptor_5.descriptor,
    casper: descriptor_6.descriptor,
    celo: descriptor_7.descriptor,
    cosmos: descriptor_8.descriptor,
    evm: descriptor_9.descriptor,
    filecoin: descriptor_10.descriptor,
    hedera: descriptor_11.descriptor,
    icon: descriptor_12.descriptor,
    internet_computer: descriptor_13.descriptor,
    kaspa: descriptor_14.descriptor,
    mina: descriptor_15.descriptor,
    multiversx: descriptor_16.descriptor,
    near: descriptor_17.descriptor,
    polkadot: descriptor_18.descriptor,
    solana: descriptor_19.descriptor,
    stacks: descriptor_20.descriptor,
    stellar: descriptor_21.descriptor,
    sui: descriptor_22.descriptor,
    tezos: descriptor_23.descriptor,
    ton: descriptor_24.descriptor,
    tron: descriptor_25.descriptor,
    vechain: descriptor_26.descriptor,
    xrp: descriptor_27.descriptor,
};
function isFeatureActive(currency, featureId) {
    try {
        const currencyConfig = (0, index_1.getCurrencyConfiguration)(currency);
        if (currencyConfig.status.type !== "active") {
            return false;
        }
        // Type guard
        const features = currencyConfig.status
            .features;
        return features?.find(f => f.id === featureId)?.status === "active";
    }
    catch {
        return false;
    }
}
/**
 * Get the full descriptor for a given currency via the CurrencyBridge
 */
function getDescriptor(currency) {
    if (!currency) {
        return null;
    }
    const cryptoCurrency = currency.type === "TokenCurrency" ? currency.parentCurrency : currency;
    const bridge = (0, impl_1.getCurrencyBridge)(cryptoCurrency);
    // Check if bridge implements getDescriptor directly
    if ("getDescriptor" in bridge && typeof bridge.getDescriptor === "function") {
        return bridge.getDescriptor(cryptoCurrency);
    }
    // Fallback: use the descriptor registry and check feature flags
    const fullDescriptor = descriptorRegistry[cryptoCurrency.family];
    if (!fullDescriptor) {
        return null;
    }
    if (fullDescriptor.send && isFeatureActive(cryptoCurrency, "blockchain_txs")) {
        return fullDescriptor;
    }
    return null;
}
exports.getDescriptor = getDescriptor;
/**
 * Get the send flow descriptor for a given currency
 */
function getSendDescriptor(currency) {
    const descriptor = getDescriptor(currency);
    return descriptor?.send ?? null;
}
exports.getSendDescriptor = getSendDescriptor;
/*
 * Check if the currency supports the new flows
 */
function supportsNewFlows(currency, flow) {
    const cryptoCurrency = currency.type === "TokenCurrency" ? currency.parentCurrency : currency;
    return exports.newFlowsConfig[cryptoCurrency.family]?.[flow] ?? false;
}
exports.supportsNewFlows = supportsNewFlows;
/**
 * Helper functions to check send flow capabilities
 */
exports.sendFeatures = {
    hasMemo: (currency) => {
        const descriptor = getSendDescriptor(currency);
        return descriptor?.inputs.memo !== undefined;
    },
    hasFeePresets: (currency) => {
        const descriptor = getSendDescriptor(currency);
        return descriptor?.fees.hasPresets ?? false;
    },
    hasCustomFees: (currency) => {
        const descriptor = getSendDescriptor(currency);
        return descriptor?.fees.hasCustom ?? false;
    },
    hasCoinControl: (currency) => {
        const descriptor = getSendDescriptor(currency);
        return descriptor?.fees.hasCoinControl ?? false;
    },
    getMemoType: (currency) => {
        const descriptor = getSendDescriptor(currency);
        return descriptor?.inputs.memo?.type;
    },
    getMemoMaxLength: (currency) => {
        const descriptor = getSendDescriptor(currency);
        return descriptor?.inputs.memo?.maxLength;
    },
    getMemoMaxValue: (currency) => {
        const descriptor = getSendDescriptor(currency);
        return descriptor?.inputs.memo?.maxValue;
    },
    getMemoOptions: (currency) => {
        const descriptor = getSendDescriptor(currency);
        return descriptor?.inputs.memo?.options;
    },
    supportsDomain: (currency) => {
        const descriptor = getSendDescriptor(currency);
        return descriptor?.inputs.recipientSupportsDomain ?? false;
    },
};
//# sourceMappingURL=descriptor.js.map