"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getProviderId = void 0;
/* eslint-disable camelcase */
// Higher level cache on top of Manager
const semver_1 = __importDefault(require("semver"));
const chunk_1 = __importDefault(require("lodash/chunk"));
const api_1 = __importDefault(require("./api"));
const provider_1 = require("./provider");
Object.defineProperty(exports, "getProviderId", { enumerable: true, get: function () { return provider_1.getProviderId; } });
const ICONS_FALLBACK = {
    bitcoin_testnet: "bitcoin",
};
const oldAppsInstallDisabled = [
    "Crypto.com Chain",
    "ZenCash",
    "Ripple",
    "Ontology",
    "Zcoin",
    "Elrond",
];
const canHandleInstall = (app) => !oldAppsInstallDisabled.includes(app.name);
const CacheAPI = {
    // TODO: Move to new ManagerAPI
    // When ready, the manager api will return an icon url instead of a name
    getIconUrl: (icon) => {
        const icn = ICONS_FALLBACK[icon] || icon;
        return `https://cdn.live.ledger.com/icons/${icn}.png`;
    },
    getFirmwareVersion: (firmware) => firmware.name.replace("-osu", ""),
    // TO BE CONFIRMED – LL-2568
    firmwareUpdateNeedsLegacyBlueResetInstructions: (deviceInfo, deviceModelId) => deviceModelId === "blue" &&
        semver_1.default.lt(semver_1.default.valid(semver_1.default.coerce(deviceInfo.version)) || "", "2.1.1"),
    // TO BE CONFIRMED – LL-2564
    firmwareUpdateWillResetSeed: (deviceInfo, deviceModelId, _firmware) => deviceModelId === "blue" &&
        semver_1.default.lt(semver_1.default.valid(semver_1.default.coerce(deviceInfo.version)) || "", "2.1.1"),
    firmwareUpdateWillUninstallApps: (_deviceInfo, _deviceModelId) => true,
    // true for all? TO BE CONFIRMED – LL-2710
    firmwareUpdateRequiresUserToUninstallApps: (deviceModel, deviceInfo) => deviceModel === "nanoS" &&
        semver_1.default.lte(semver_1.default.valid(semver_1.default.coerce(deviceInfo.version)) || "", "1.4.2"),
    firmwareUnsupported: (deviceModel, deviceInfo) => deviceModel === "nanoS" &&
        semver_1.default.lt(semver_1.default.valid(semver_1.default.coerce(deviceInfo.version)) || "", "1.3.0"),
    formatHashName: (input, deviceModel, deviceInfo) => {
        const shouldEllipsis = deviceModel && deviceInfo
            ? deviceModel === "blue" ||
                (deviceModel === "nanoS" &&
                    semver_1.default.lt(semver_1.default.valid(semver_1.default.coerce(deviceInfo.version)) || "", "1.6.0"))
            : true;
        const shouldSplit = deviceInfo && deviceModel
            ? (deviceModel === "nanoS" &&
                semver_1.default.gte(semver_1.default.valid(semver_1.default.coerce(deviceInfo.version)) || "", "1.6.0")) ||
                deviceModel === "nanoX"
            : false;
        const hash = (input || "").toUpperCase();
        const splitLength = deviceModel === "nanoS" ? 16 : 17;
        return shouldSplit
            ? (0, chunk_1.default)(hash.split(""), splitLength).map(item => item.join(""))
            : hash.length > 8 && shouldEllipsis
                ? [`${hash.slice(0, 4)}...${hash.substr(-4)}`]
                : [hash];
    },
    canHandleInstall,
    // get list of available languages for a given deviceInfo
    getAvailableLanguagesDevice: async (deviceInfo) => {
        const languagePackages = await api_1.default.getLanguagePackagesForDevice(deviceInfo);
        const languages = languagePackages.map(pack => pack.language);
        if (!languages.includes("english")) {
            languages.push("english"); // english is always available
        }
        return languages;
    },
};
exports.default = CacheAPI;
//# sourceMappingURL=index.js.map