"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPlatformTransactionSignFlowInfos = exports.currencyToPlatformCurrency = exports.accountToPlatformAccount = void 0;
const account_1 = require("../account");
const platformAdapter_1 = __importDefault(require("../generated/platformAdapter"));
const types_1 = require("./types");
const store_1 = require("@ledgerhq/live-wallet/store");
function accountToPlatformAccount(walletState, account, parentAccount) {
    if ((0, account_1.isTokenAccount)(account)) {
        if (!parentAccount) {
            throw new Error("No 'parentAccount' account provided for token account");
        }
        const parentName = (0, store_1.accountNameWithDefaultSelector)(walletState, parentAccount);
        return {
            id: account.id,
            balance: account.balance,
            address: parentAccount.freshAddress,
            blockHeight: parentAccount.blockHeight,
            lastSyncDate: parentAccount.lastSyncDate,
            name: `${parentName} (${account.token.ticker})`,
            currency: account.token.id,
            spendableBalance: account.spendableBalance,
        };
    }
    const name = (0, store_1.accountNameWithDefaultSelector)(walletState, account);
    return {
        id: account.id,
        name,
        address: account.freshAddress,
        currency: account.currency.id,
        balance: account.balance,
        spendableBalance: account.spendableBalance,
        blockHeight: account.blockHeight,
        lastSyncDate: account.lastSyncDate,
    };
}
exports.accountToPlatformAccount = accountToPlatformAccount;
function currencyToPlatformCurrency(currency) {
    if (currency.type === "TokenCurrency") {
        return {
            type: types_1.PlatformCurrencyType.TokenCurrency,
            standard: types_1.PlatformTokenStandard.ERC20,
            id: currency.id,
            ticker: currency.ticker,
            contract: currency.contractAddress,
            name: currency.name,
            parent: currency.parentCurrency.id,
            color: currency.parentCurrency.color,
            units: currency.units.map(unit => ({
                name: unit.name,
                code: unit.code,
                magnitude: unit.magnitude,
            })),
        };
    }
    return {
        type: types_1.PlatformCurrencyType.CryptoCurrency,
        id: currency.id,
        ticker: currency.ticker,
        name: currency.name,
        family: types_1.FAMILIES_MAPPING_LL_TO_PLATFORM[currency.family] ?? currency.family,
        color: currency.color,
        units: currency.units.map(unit => ({
            name: unit.name,
            code: unit.code,
            magnitude: unit.magnitude,
        })),
    };
}
exports.currencyToPlatformCurrency = currencyToPlatformCurrency;
const getPlatformTransactionSignFlowInfos = (platformTx) => {
    const liveFamily = types_1.FAMILIES_MAPPING_PLATFORM_TO_LL[platformTx.family] ?? platformTx.family;
    const familyModule = platformAdapter_1.default[liveFamily];
    if (familyModule) {
        return familyModule.getPlatformTransactionSignFlowInfos(platformTx);
    }
    return {
        canEditFees: false,
        liveTx: { ...platformTx },
        hasFeesProvided: false,
    };
};
exports.getPlatformTransactionSignFlowInfos = getPlatformTransactionSignFlowInfos;
//# sourceMappingURL=converters.js.map