@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
35 lines • 1.17 kB
JavaScript
/**
* 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
*/
export 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.
*/
export function selectCurrency(result) {
const metaCurrencyId = result.currenciesOrder.metaCurrencyIds?.[0];
if (!metaCurrencyId)
return undefined;
return selectCurrencyForMetaId(metaCurrencyId, result);
}
//# sourceMappingURL=currencySelection.js.map