UNPKG

@ledgerhq/live-common

Version:
41 lines 2.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useGroupedCurrenciesByProvider = void 0; const type_1 = require("./type"); const react_1 = require("react"); const currencies_1 = require("../currencies"); const helper_1 = require("./helper"); const useCurrenciesUnderFeatureFlag_1 = require("../modularDrawer/hooks/useCurrenciesUnderFeatureFlag"); // FIXME(LIVE-10505): bad performane & shared utility to move to coin-framework const listSupportedTokens = () => (0, currencies_1.listTokens)().filter(t => (0, currencies_1.isCurrencySupported)(t.parentCurrency)); const initialResult = { sortedCryptoCurrencies: [], currenciesByProvider: [], }; const useGroupedCurrenciesByProvider = (withLoading) => { const [result, setResult] = (0, react_1.useState)(initialResult); // the import is from MAD but as this hook will be removed, it's fine to keep it here const { deactivatedCurrencyIds } = (0, useCurrenciesUnderFeatureFlag_1.useCurrenciesUnderFeatureFlag)(); const [loadingStatus, setLoadingStatus] = (0, react_1.useState)(type_1.LoadingStatus.Idle); const coinsAndTokensSupported = (0, react_1.useMemo)(() => (0, currencies_1.listSupportedCurrencies)() .concat(listSupportedTokens()) .filter(c => !deactivatedCurrencyIds.has(c.id)), [deactivatedCurrencyIds]); // Get mapped assets filtered by supported & sorted currencies, grouped by provider id (0, react_1.useEffect)(() => { if (withLoading) { setLoadingStatus(type_1.LoadingStatus.Idle); (0, helper_1.loadCurrenciesByProvider)(coinsAndTokensSupported) .then(data => { setResult(data); setLoadingStatus(type_1.LoadingStatus.Success); }) .catch(() => setLoadingStatus(type_1.LoadingStatus.Error)); } else { (0, helper_1.loadCurrenciesByProvider)(coinsAndTokensSupported).then(setResult); } }, [coinsAndTokensSupported, withLoading]); return withLoading ? { result, loadingStatus } : result; }; exports.useGroupedCurrenciesByProvider = useGroupedCurrenciesByProvider; //# sourceMappingURL=useGroupedCurrenciesByProvider.hook.js.map