import { useMemo } from "react"; import { useAssets } from "../useAssets"; import { useMarketFilters } from "../useMarketFilters"; import { useMarkets } from "../useMarkets"; import { useStepSize } from "../useStepSize"; import { ConvertContext } from "./context"; export const useConvertConfigMarket = ({ mode, type, }: { mode: "from" | "to"; type: "market" | "limit"; }) => { const { marketsSymbols } = useMarkets(); const { allAssets } = useAssets(); const { toAsset, fromAsset } = ConvertContext.useWatch(); const { selectedCurrency, isFromFiat } = useMemo(() => { const selectedCurrency = allAssets?.find( ({ symbol }) => symbol === (mode === "from" ? fromAsset : toAsset), ); const isFromFiat = selectedCurrency?.currencyType === "Fiat"; return { selectedCurrency, isFromFiat, }; }, [allAssets, fromAsset, mode, toAsset]); const market = useMemo(() => { return marketsSymbols?.find((i) => isFromFiat ? i.quoteAsset === selectedCurrency?.symbol : i.baseAsset === selectedCurrency?.symbol, ); }, [isFromFiat, marketsSymbols, selectedCurrency?.symbol]); const { filterLotSize, filterPrice } = useMarketFilters({ selectedMarket: market, type, }); const { toTickSize, toStepSize } = useStepSize(market?.name, type); const getMaxSize = marketsSymbols?.find( ({ quoteAsset }) => quoteAsset === selectedCurrency?.symbol, ) ? toTickSize : toStepSize; return { filterLotSize, filterPrice, getMaxSize, selectedCurrency, }; };