"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getBalanceAndFiatValueByAssets = void 0;
const groupAccountsByAsset_1 = require("./groupAccountsByAsset");
const bignumber_js_1 = __importDefault(require("bignumber.js"));
const getBalanceAndFiatValueByAssets = (accounts, assets, counterValuesState, targetCurrency) => {
    const groupedAccountsByAsset = (0, groupAccountsByAsset_1.groupAccountsByAsset)(accounts, counterValuesState, targetCurrency);
    return assets.map(asset => {
        const assetGroup = groupedAccountsByAsset[asset.id];
        if (assetGroup) {
            return yieldAssetDetails(assetGroup, asset);
        }
        return {
            id: asset.id,
            name: asset.name,
            ticker: asset.ticker,
            currency: asset,
            balance: new bignumber_js_1.default(0),
            fiatValue: 0,
        };
    });
};
exports.getBalanceAndFiatValueByAssets = getBalanceAndFiatValueByAssets;
const yieldAssetDetails = (assetGroup, asset) => {
    // Use the reference currency for consistent magnitude
    const assetDetails = assetGroup.referenceCurrency;
    return {
        id: asset.id,
        name: asset.name,
        ticker: asset.ticker,
        currency: assetDetails,
        balance: assetGroup.totalBalance,
        fiatValue: assetGroup.totalFiatValue.toNumber(),
    };
};
//# sourceMappingURL=getBalanceAndFiatValueByAssets.js.map