"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getNoticeType = exports.getProviderName = exports.isRegistrationRequired = exports.getAvailableAccountsById = exports.getAccountTuplesForCurrency = exports.FILTER = void 0;
const ledger_cal_service_1 = require("@ledgerhq/ledger-cal-service");
const account_1 = require("../../../account");
const swap_1 = require("../../providers/swap");
exports.FILTER = {
    centralised: "centralised",
    decentralised: "decentralised",
    float: "float",
    fixed: "fixed",
};
function getAccountTuplesForCurrency(currency, allAccounts, hideEmpty) {
    if (currency.type === "TokenCurrency") {
        return allAccounts
            .filter(account => account.currency.id === currency.parentCurrency.id)
            .map(account => ({
            account,
            subAccount: (account.subAccounts &&
                account.subAccounts.find((subAcc) => subAcc.type === "TokenAccount" && subAcc.token.id === currency.id)) ||
                (0, account_1.makeEmptyTokenAccount)(account, currency),
        }))
            .filter(a => (hideEmpty ? a.subAccount?.balance.gt(0) : true));
    }
    return allAccounts
        .filter(account => account.currency.id === currency.id)
        .map(account => ({
        account,
        subAccount: null,
    }))
        .filter(a => (hideEmpty ? a.account?.balance.gt(0) : true));
}
exports.getAccountTuplesForCurrency = getAccountTuplesForCurrency;
const getAvailableAccountsById = (id, accounts) => accounts
    .filter(acc => (0, account_1.getAccountCurrency)(acc)?.id === id && !acc.disabled)
    .sort((a, b) => b.balance.minus(a.balance).toNumber());
exports.getAvailableAccountsById = getAvailableAccountsById;
const isRegistrationRequired = async (provider) => {
    const { needsBearerToken, needsKYC } = await (0, swap_1.getSwapProvider)(provider);
    return needsBearerToken || needsKYC;
};
exports.isRegistrationRequired = isRegistrationRequired;
const getProviderName = (provider) => {
    const { displayName } = ledger_cal_service_1.SWAP_DATA_CDN[provider] ?? { displayName: "" };
    return displayName;
};
exports.getProviderName = getProviderName;
const getNoticeType = (provider) => {
    switch (provider) {
        case "cic":
            return { message: "provider", learnMore: false };
        case "changelly":
            return {
                message: "provider",
                learnMore: false,
            };
        default:
            return { message: "default", learnMore: true };
    }
};
exports.getNoticeType = getNoticeType;
//# sourceMappingURL=index.js.map