2023-10-25 21:59:30 +00:00
|
|
|
import compact from 'lodash/compact';
|
|
|
|
import type { MarketMaybeWithDataAndCandles } from '@vegaprotocol/markets';
|
|
|
|
import { AgGrid } from '@vegaprotocol/datagrid';
|
|
|
|
import { formatPercentage, getAdjustedFee } from './utils';
|
|
|
|
import { MarketCodeCell } from '../../client-pages/markets/market-code-cell';
|
|
|
|
import BigNumber from 'bignumber.js';
|
2023-10-26 15:38:52 +00:00
|
|
|
import { useNavigateWithMeta } from '../../lib/hooks/use-market-click-handler';
|
|
|
|
import { Links } from '../../lib/links';
|
2023-11-16 03:10:39 +00:00
|
|
|
import { useT } from '../../lib/use-t';
|
|
|
|
import { useMemo } from 'react';
|
2024-01-02 15:50:04 +00:00
|
|
|
import { type ColDef } from 'ag-grid-community/dist/lib/entities/colDef';
|
2023-10-25 21:59:30 +00:00
|
|
|
|
2024-01-02 15:50:04 +00:00
|
|
|
const useFeesTableColumnDefs = (): ColDef[] => {
|
2023-11-16 03:10:39 +00:00
|
|
|
const t = useT();
|
|
|
|
return useMemo(
|
2024-01-02 15:50:04 +00:00
|
|
|
() =>
|
|
|
|
[
|
|
|
|
{
|
|
|
|
field: 'code',
|
|
|
|
cellRenderer: 'MarketCodeCell',
|
|
|
|
pinned: 'left',
|
|
|
|
width: 150,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'feeAfterDiscount',
|
|
|
|
headerName: t('Total fee after discount'),
|
|
|
|
valueFormatter: ({ value }: { value: number }) => value + '%',
|
|
|
|
},
|
|
|
|
{
|
2024-02-29 10:25:56 +00:00
|
|
|
field: 'liquidityFee',
|
2024-01-02 15:50:04 +00:00
|
|
|
valueFormatter: ({ value }: { value: number }) => value + '%',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'infraFee',
|
|
|
|
valueFormatter: ({ value }: { value: number }) => value + '%',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'makerFee',
|
|
|
|
valueFormatter: ({ value }: { value: number }) => value + '%',
|
|
|
|
},
|
2024-02-29 10:25:56 +00:00
|
|
|
{
|
|
|
|
field: 'totalFee',
|
|
|
|
headerName: t('Total fee before discount'),
|
|
|
|
valueFormatter: ({ value }: { value: number }) => value + '%',
|
|
|
|
},
|
2024-01-02 15:50:04 +00:00
|
|
|
] as ColDef[],
|
2023-11-16 03:10:39 +00:00
|
|
|
[t]
|
|
|
|
);
|
|
|
|
};
|
2023-10-25 21:59:30 +00:00
|
|
|
|
|
|
|
const feesTableDefaultColDef = {
|
|
|
|
flex: 1,
|
2024-01-02 15:50:04 +00:00
|
|
|
minWidth: 62,
|
2023-10-25 21:59:30 +00:00
|
|
|
resizable: true,
|
|
|
|
sortable: true,
|
2024-01-02 15:50:04 +00:00
|
|
|
suppressMovable: true,
|
|
|
|
pinned: false,
|
2023-10-25 21:59:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const components = {
|
|
|
|
MarketCodeCell,
|
|
|
|
};
|
|
|
|
|
|
|
|
export const MarketFees = ({
|
|
|
|
markets,
|
|
|
|
referralDiscount,
|
|
|
|
volumeDiscount,
|
|
|
|
}: {
|
|
|
|
markets: MarketMaybeWithDataAndCandles[] | null;
|
|
|
|
referralDiscount: number;
|
|
|
|
volumeDiscount: number;
|
|
|
|
}) => {
|
2023-10-26 15:38:52 +00:00
|
|
|
const navigateWithMeta = useNavigateWithMeta();
|
|
|
|
|
2024-01-02 15:50:04 +00:00
|
|
|
const colDef = useFeesTableColumnDefs();
|
|
|
|
|
2023-10-25 21:59:30 +00:00
|
|
|
const rows = compact(markets || []).map((m) => {
|
|
|
|
const infraFee = new BigNumber(m.fees.factors.infrastructureFee);
|
|
|
|
const makerFee = new BigNumber(m.fees.factors.makerFee);
|
|
|
|
const liquidityFee = new BigNumber(m.fees.factors.liquidityFee);
|
|
|
|
const totalFee = infraFee.plus(makerFee).plus(liquidityFee);
|
|
|
|
|
|
|
|
const feeAfterDiscount = getAdjustedFee(
|
|
|
|
[infraFee, makerFee, liquidityFee],
|
|
|
|
[new BigNumber(referralDiscount), new BigNumber(volumeDiscount)]
|
|
|
|
);
|
|
|
|
|
|
|
|
return {
|
2023-10-26 15:38:52 +00:00
|
|
|
id: m.id,
|
2023-10-25 21:59:30 +00:00
|
|
|
code: m.tradableInstrument.instrument.code,
|
|
|
|
productType: m.tradableInstrument.instrument.product.__typename,
|
|
|
|
infraFee: formatPercentage(infraFee.toNumber()),
|
|
|
|
makerFee: formatPercentage(makerFee.toNumber()),
|
|
|
|
liquidityFee: formatPercentage(liquidityFee.toNumber()),
|
|
|
|
totalFee: formatPercentage(totalFee.toNumber()),
|
|
|
|
feeAfterDiscount: formatPercentage(feeAfterDiscount),
|
|
|
|
parentMarketID: m.parentMarketID,
|
|
|
|
successorMarketID: m.successorMarketID,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
2024-01-02 15:50:04 +00:00
|
|
|
<div className="border rounded-lg md:rounded-sm overflow-hidden border-default">
|
2023-10-25 21:59:30 +00:00
|
|
|
<AgGrid
|
2024-01-02 15:50:04 +00:00
|
|
|
columnDefs={colDef}
|
2023-10-25 21:59:30 +00:00
|
|
|
rowData={rows}
|
2023-10-26 15:38:52 +00:00
|
|
|
getRowId={({ data }) => data.id}
|
2023-10-25 21:59:30 +00:00
|
|
|
defaultColDef={feesTableDefaultColDef}
|
|
|
|
domLayout="autoHeight"
|
|
|
|
components={components}
|
|
|
|
rowHeight={45}
|
2023-10-26 15:38:52 +00:00
|
|
|
rowClass="cursor-pointer"
|
|
|
|
onRowClicked={({ data, event }) => {
|
|
|
|
navigateWithMeta(
|
|
|
|
Links.MARKET(data.id),
|
|
|
|
// @ts-ignore metaKey and ctrlKey exist
|
|
|
|
event.metaKey || event.ctrlKey
|
|
|
|
);
|
|
|
|
}}
|
2023-10-25 21:59:30 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|