@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
23 lines • 992 B
JavaScript
import { useEffect, useState } from "react";
import { findCryptoCurrencyById } from "@ledgerhq/cryptoassets";
import { getCryptoAssetsStore } from "@ledgerhq/cryptoassets/state";
export const useSelectableCurrencies = ({ allCurrencies, }) => {
const [currencies, setCurrencies] = useState([]);
useEffect(() => {
const loadCurrencies = async () => {
const results = await Promise.all(allCurrencies.map(async (id) => {
// Try token first, then crypto currency
const token = await getCryptoAssetsStore().findTokenById(id);
if (token)
return token;
const crypto = findCryptoCurrencyById(id);
return crypto;
}));
const validCurrencies = results.filter(Boolean);
setCurrencies(validCurrencies);
};
loadCurrencies();
}, [allCurrencies]);
return currencies;
};
//# sourceMappingURL=useSelectableCurrencies.js.map