import { matchFilter, lpAggregatedDataProvider, useCheckLiquidityStatus, } from '@vegaprotocol/liquidity'; import { tooltipMapping } from '@vegaprotocol/markets'; import { addDecimalsFormatNumber, formatNumberPercentage, } from '@vegaprotocol/utils'; import { t } from '@vegaprotocol/i18n'; import { NetworkParams, useNetworkParams, } from '@vegaprotocol/network-parameters'; import { useDataProvider } from '@vegaprotocol/data-provider'; import { Tab, Tabs, Link as UiToolkitLink, Indicator, ExternalLink, } from '@vegaprotocol/ui-toolkit'; import { useVegaWallet } from '@vegaprotocol/wallet'; import { memo, useEffect, useState } from 'react'; import { Header, HeaderStat, HeaderTitle } from '../../components/header'; import { Link, useParams } from 'react-router-dom'; import { Links, Routes } from '../../pages/client-router'; import { useMarket, useStaticMarketData } from '@vegaprotocol/markets'; import { DocsLinks } from '@vegaprotocol/environment'; import { LiquidityContainer } from '../../components/liquidity-container'; const enum LiquidityTabs { Active = 'active', Inactive = 'inactive', MyLiquidityProvision = 'myLP', } export const Liquidity = () => { const params = useParams(); const marketId = params.marketId; return ; }; const LiquidityViewHeader = memo(({ marketId }: { marketId?: string }) => { const { data: market } = useMarket(marketId); const { data: marketData } = useStaticMarketData(marketId); const targetStake = marketData?.targetStake; const suppliedStake = marketData?.suppliedStake; const assetDecimalPlaces = market?.tradableInstrument.instrument.product.settlementAsset.decimals || 0; const symbol = market?.tradableInstrument.instrument.product.settlementAsset.symbol; const { params } = useNetworkParams([ NetworkParams.market_liquidity_stakeToCcyVolume, NetworkParams.market_liquidity_targetstake_triggering_ratio, ]); const triggeringRatio = params.market_liquidity_targetstake_triggering_ratio || '1'; const { percentage, status } = useCheckLiquidityStatus({ suppliedStake: suppliedStake || 0, targetStake: targetStake || 0, triggeringRatio, }); return ( {t('Go to trading')} } /> ) } > {targetStake ? `${addDecimalsFormatNumber( targetStake, assetDecimalPlaces ?? 0 )} ${symbol}` : '-'} {suppliedStake ? `${addDecimalsFormatNumber( suppliedStake, assetDecimalPlaces ?? 0 )} ${symbol}` : '-'} {formatNumberPercentage(percentage, 2)} {marketId} {DocsLinks ? ( {t('Providing liquidity')} ) : ( (null as React.ReactNode) )} ); }); LiquidityViewHeader.displayName = 'LiquidityViewHeader'; export const LiquidityViewContainer = ({ marketId, }: { marketId: string | undefined; }) => { const [tab, setTab] = useState(undefined); const { pubKey } = useVegaWallet(); const { data } = useDataProvider({ dataProvider: lpAggregatedDataProvider, skipUpdates: true, variables: { marketId: marketId || '' }, skip: !marketId, }); useEffect(() => { if (data) { if (pubKey && data.some((lp) => matchFilter({ partyId: pubKey }, lp))) { setTab(LiquidityTabs.MyLiquidityProvision); return; } if (data.some((lp) => matchFilter({ active: true }, lp))) { setTab(LiquidityTabs.Active); return; } setTab(LiquidityTabs.Inactive); } }, [data, pubKey]); return ( ); };