import { LiquidityTable, useLiquidityProvision } from '@vegaprotocol/liquidity'; import { addDecimalsFormatNumber, t } from '@vegaprotocol/react-helpers'; import { LiquidityProvisionStatus } from '@vegaprotocol/types'; import { AsyncRenderer, Tab, Tabs, Link as UiToolkitLink, } from '@vegaprotocol/ui-toolkit'; import { useVegaWallet } from '@vegaprotocol/wallet'; import type { AgGridReact } from 'ag-grid-react'; import { Header, HeaderStat } from '../../components/header'; import { useRouter } from 'next/router'; import { useRef, useMemo } from 'react'; import { tooltipMapping } from '@vegaprotocol/market-info'; import Link from 'next/link'; const LiquidityPage = ({ id }: { id?: string }) => { const { query } = useRouter(); const { keypair } = useVegaWallet(); const gridRef = useRef(null); const partyId = keypair?.pub; // Default to first marketId query item if found const marketId = id || (Array.isArray(query.marketId) ? query.marketId[0] : query.marketId); const { data: { liquidityProviders, suppliedStake, targetStake, name, symbol, assetDecimalPlaces, }, loading, error, } = useLiquidityProvision({ marketId }); const myLpEdges = useMemo( () => liquidityProviders.filter((e) => e.party === partyId), [liquidityProviders, partyId] ); const activeEdges = useMemo( () => liquidityProviders.filter( (e) => e.status === LiquidityProvisionStatus.STATUS_ACTIVE ), [liquidityProviders] ); const inactiveEdges = useMemo( () => liquidityProviders.filter( (e) => e.status !== LiquidityProvisionStatus.STATUS_ACTIVE ), [liquidityProviders] ); const enum LiquidityTabs { Active = 'active', Inactive = 'inactive', MyLiquidityProvision = 'myLP', } const getActiveDefaultId = () => { if (myLpEdges?.length > 0) return LiquidityTabs.MyLiquidityProvision; if (activeEdges?.length) return LiquidityTabs.Active; else if (inactiveEdges?.length > 0) return LiquidityTabs.Inactive; return LiquidityTabs.Active; }; return (
{`${name} ${t('liquidity provision')}`} } >
{targetStake ? `${addDecimalsFormatNumber( targetStake, assetDecimalPlaces ?? 0 )} ${symbol}` : '-'}
{suppliedStake ? `${addDecimalsFormatNumber( suppliedStake, assetDecimalPlaces ?? 0 )} ${symbol}` : '-'}
{marketId}
); }; LiquidityPage.getInitialProps = () => ({ page: 'liquidity', }); export default LiquidityPage;