@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
27 lines (25 loc) • 1.01 kB
text/typescript
import { shallowEqual, useSelector } from "react-redux";
import { CryptoOrTokenCurrency } from "@ledgerhq/types-cryptoassets";
import { selectMarketByCurrency } from "../entities/marketSelectors";
import { ApiState } from "../entities/selectorUtils";
export const useMarketByCurrencies = (currencies: CryptoOrTokenCurrency[]) => {
return useSelector((state: ApiState) => {
const marketByCurrencies: Record<
string,
{ price?: number; priceChangePercentage24h?: number }
> = {};
for (const currency of currencies) {
const currencyMarket = selectMarketByCurrency(state, currency.id);
if (
currencyMarket?.price !== undefined &&
currencyMarket?.priceChangePercentage24h !== undefined
) {
marketByCurrencies[currency.id] = {
price: currencyMarket.price,
priceChangePercentage24h: Math.round(currencyMarket.priceChangePercentage24h * 100) / 100,
};
}
}
return marketByCurrencies;
}, shallowEqual);
};