@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
39 lines • 1.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.selectCurrencyForMetaId = selectCurrencyForMetaId;
exports.selectCurrency = selectCurrency;
/**
* Selects the best currency for a given meta-currency ID based on priority:
* 1. Main currency (matching metaCurrencyId)
* 2. CryptoCurrency type
* 3. First available network
*/
function selectCurrencyForMetaId(metaCurrencyId, data) {
const assetsIds = data.cryptoAssets[metaCurrencyId]?.assetsIds;
if (!assetsIds)
return undefined;
let fallback;
let crypto;
for (const id of Object.values(assetsIds)) {
const currency = data.cryptoOrTokenCurrencies[id];
if (!currency)
continue;
if (currency.id === metaCurrencyId)
return currency;
if (!fallback)
fallback = currency;
if (!crypto && currency.type === "CryptoCurrency")
crypto = currency;
}
return crypto ?? fallback;
}
/**
* Selects the best currency from the first meta-currency in the asset data result.
*/
function selectCurrency(result) {
const metaCurrencyId = result.currenciesOrder.metaCurrencyIds?.[0];
if (!metaCurrencyId)
return undefined;
return selectCurrencyForMetaId(metaCurrencyId, result);
}
//# sourceMappingURL=currencySelection.js.map