Skip to content

Commit

Permalink
feat(trading): show fees paid across whole market (#5154)
Browse files Browse the repository at this point in the history
  • Loading branch information
MadalinaRaicu authored Oct 31, 2023
1 parent 4c95db5 commit 61aa45a
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 4 deletions.
56 changes: 52 additions & 4 deletions apps/trading/components/liquidity-header/liquidity-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,28 @@ import {
formatNumberPercentage,
} from '@vegaprotocol/utils';
import { t } from '@vegaprotocol/i18n';
import { ExternalLink, Indicator } from '@vegaprotocol/ui-toolkit';
import {
CopyWithTooltip,
ExternalLink,
Indicator,
VegaIcon,
VegaIconNames,
truncateMiddle,
} from '@vegaprotocol/ui-toolkit';
import { DocsLinks } from '@vegaprotocol/environment';
import { useCheckLiquidityStatus } from '@vegaprotocol/liquidity';
import {
useCheckLiquidityStatus,
usePaidFeesQuery,
} from '@vegaprotocol/liquidity';
import { useParams } from 'react-router-dom';

export const LiquidityHeader = () => {
const { marketId } = useParams();
const { data: market } = useMarket(marketId);
const { data: marketData } = useStaticMarketData(marketId);
const { data: feesPaidRes } = usePaidFeesQuery({
variables: { marketId: marketId || '' },
});
const targetStake = marketData?.targetStake;
const suppliedStake = marketData?.suppliedStake;

Expand All @@ -36,6 +49,10 @@ export const LiquidityHeader = () => {
triggeringRatio,
});

const feesObject = feesPaidRes?.paidLiquidityFees?.edges?.find(
(e) => e?.node.marketId === marketId
);

return (
<Header
title={
Expand Down Expand Up @@ -82,9 +99,40 @@ export const LiquidityHeader = () => {
<HeaderStat heading={t('Liquidity supplied')} testId="liquidity-supplied">
<Indicator variant={status} /> {formatNumberPercentage(percentage, 2)}
</HeaderStat>
<HeaderStat heading={t('Market ID')} testId="liquidity-market-id">
<div className="break-word">{marketId}</div>
<HeaderStat
heading={t('Fees paid')}
description={t(
'The amount of fees paid to liquidity providers across the whole market during the last epoch %s.',
feesObject?.node.epoch.toString() || '-'
)}
testId="fees-paid"
>
<div>
{feesObject?.node.totalFeesPaid
? `${addDecimalsFormatNumber(
feesObject?.node.totalFeesPaid,
assetDecimalPlaces ?? 0
)} ${symbol}`
: '-'}
</div>
</HeaderStat>
{marketId && (
<HeaderStat heading={t('Market ID')} testId="liquidity-market-id">
<div className="break-word">
<CopyWithTooltip text={marketId}>
<button
data-testid="copy-eth-oracle-address"
className="uppercase text-right"
>
<span className="flex gap-1">
{truncateMiddle(marketId)}
<VegaIcon name={VegaIconNames.COPY} size={16} />
</span>
</button>
</CopyWithTooltip>
</div>
</HeaderStat>
)}
<HeaderStat heading={t('Learn more')} testId="liquidity-learn-more">
{DocsLinks ? (
<ExternalLink href={DocsLinks.LIQUIDITY}>
Expand Down
13 changes: 13 additions & 0 deletions libs/liquidity/src/lib/MarketLiquidity.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ fragment LiquidityProvisionFields on LiquidityProvision {
status
}

query PaidFees($marketId: ID) {
paidLiquidityFees(marketId: $marketId) {
edges {
node {
marketId
assetId
epoch
totalFeesPaid
}
}
}
}

query LiquidityProvisions($marketId: ID!) {
market(id: $marketId) {
liquiditySLAParameters {
Expand Down
49 changes: 49 additions & 0 deletions libs/liquidity/src/lib/__generated__/MarketLiquidity.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 61aa45a

Please sign in to comment.