fix: #1537 add 3 lp data providers

This commit is contained in:
Madalina Raicu 2022-10-04 17:25:05 +01:00
parent 4bd905d083
commit c325becce1
No known key found for this signature in database
GPG Key ID: 688B7B31149C1DCD
3 changed files with 57 additions and 4 deletions

View File

@ -1,3 +1,7 @@
import type {
LiquidityProvisionFieldsFragment,
LiquidityProvisionsSubscription,
} from '@vegaprotocol/liquidity';
import { marketLiquidityDataProvider } from '@vegaprotocol/liquidity'; import { marketLiquidityDataProvider } from '@vegaprotocol/liquidity';
import { import {
liquidityProvisionsDataProvider, liquidityProvisionsDataProvider,
@ -25,6 +29,7 @@ import { useRef, useMemo } from 'react';
import { tooltipMapping } from '@vegaprotocol/market-info'; import { tooltipMapping } from '@vegaprotocol/market-info';
import Link from 'next/link'; import Link from 'next/link';
import { Schema } from '@vegaprotocol/types'; import { Schema } from '@vegaprotocol/types';
import BigNumber from 'bignumber.js';
const LiquidityPage = ({ id }: { id?: string }) => { const LiquidityPage = ({ id }: { id?: string }) => {
const { query } = useRouter(); const { query } = useRouter();
@ -45,7 +50,10 @@ const LiquidityPage = ({ id }: { id?: string }) => {
data: liquidityProviders, data: liquidityProviders,
loading, loading,
error, error,
} = useDataProvider({ } = useDataProvider<
LiquidityProvisionFieldsFragment[],
LiquidityProvisionsSubscription['liquidityProvisions']
>({
dataProvider: liquidityProvisionsDataProvider, dataProvider: liquidityProvisionsDataProvider,
update, update,
variables: { marketId, pubKey }, variables: { marketId, pubKey },
@ -156,6 +164,7 @@ const LiquidityPage = ({ id }: { id?: string }) => {
ref={gridRef} ref={gridRef}
data={myLpEdges} data={myLpEdges}
symbol={symbol} symbol={symbol}
stakeToCcySiskas={new BigNumber(stakeToCcySiska ?? 1)}
assetDecimalPlaces={assetDecimalPlaces} assetDecimalPlaces={assetDecimalPlaces}
/> />
)} )}
@ -167,6 +176,7 @@ const LiquidityPage = ({ id }: { id?: string }) => {
data={activeEdges} data={activeEdges}
symbol={symbol} symbol={symbol}
assetDecimalPlaces={assetDecimalPlaces} assetDecimalPlaces={assetDecimalPlaces}
stakeToCcySiskas={new BigNumber(stakeToCcySiska ?? 1)}
/> />
)} )}
</Tab> </Tab>
@ -178,6 +188,7 @@ const LiquidityPage = ({ id }: { id?: string }) => {
data={inactiveEdges} data={inactiveEdges}
symbol={symbol} symbol={symbol}
assetDecimalPlaces={assetDecimalPlaces} assetDecimalPlaces={assetDecimalPlaces}
stakeToCcySiskas={new BigNumber(stakeToCcySiska ?? 1)}
/> />
)} )}
</Tab> </Tab>

View File

@ -1,7 +1,11 @@
import { makeDataProvider } from '@vegaprotocol/react-helpers'; import {
makeDataProvider,
makeDerivedDataProvider,
} from '@vegaprotocol/react-helpers';
import produce from 'immer'; import produce from 'immer';
import type { IterableElement } from 'type-fest'; import type { IterableElement } from 'type-fest';
import type { import type {
LiquidityProviderFeeShareFieldsFragment,
LiquidityProvisionFieldsFragment, LiquidityProvisionFieldsFragment,
LiquidityProvisionsSubscription, LiquidityProvisionsSubscription,
MarketLiquidityQuery, MarketLiquidityQuery,
@ -97,3 +101,40 @@ export const marketLiquidityDataProvider = makeDataProvider<
return delta; return delta;
}, },
}); });
export const liquidityFeeShareDataProvider = makeDataProvider<
MarketLiquidityQuery,
LiquidityProviderFeeShareFieldsFragment[],
LiquidityProviderFeeShareFieldsFragment,
LiquidityProviderFeeShareFieldsFragment[]
>({
query: MarketLiquidityDocument,
subscriptionQuery: LiquidityProvisionsDocument,
update: (data, delta) => {
return delta;
},
getData: (data) => {
return data.market?.data?.liquidityProviderFeeShare || [];
},
getDelta: (delta) => {
return [delta];
},
});
export const lpAggregatedDataProvider = makeDerivedDataProvider<
LiquidityProvisionFieldsFragment[],
never
>(
[
liquidityProvisionsDataProvider,
marketLiquidityDataProvider,
liquidityFeeShareDataProvider,
],
(parts) => {
// TODO add fee share and liquidity provision party merge
console.log('liquidityProvisionsDataProvider', parts[0]);
console.log('marketLiquidityDataProvider', parts[1]);
console.log('liquidityFeeShareDataProvider', parts[2]);
return [parts[0], parts[1], parts[2]];
}
);

View File

@ -33,10 +33,11 @@ export interface LiquidityTableProps {
data?: LiquidityProvisionFieldsFragment[]; data?: LiquidityProvisionFieldsFragment[];
symbol?: string; symbol?: string;
assetDecimalPlaces?: number; assetDecimalPlaces?: number;
stakeToCcySiskas: BigNumber;
} }
export const LiquidityTable = forwardRef<AgGridReact, LiquidityTableProps>( export const LiquidityTable = forwardRef<AgGridReact, LiquidityTableProps>(
({ data, symbol = '', assetDecimalPlaces }, ref) => { ({ data, symbol = '', assetDecimalPlaces, stakeToCcySiskas }, ref) => {
const assetDecimalsFormatter = ({ value }: ValueFormatterParams) => { const assetDecimalsFormatter = ({ value }: ValueFormatterParams) => {
if (!value) return '-'; if (!value) return '-';
return `${addDecimalsFormatNumber(value, assetDecimalPlaces ?? 0, 5)}`; return `${addDecimalsFormatNumber(value, assetDecimalPlaces ?? 0, 5)}`;
@ -61,7 +62,7 @@ export const LiquidityTable = forwardRef<AgGridReact, LiquidityTableProps>(
> >
<AgGridColumn <AgGridColumn
headerName={t('Party')} headerName={t('Party')}
field="party" field="party.id"
headerTooltip={t( headerTooltip={t(
'The public key of the party making this commitment.' 'The public key of the party making this commitment.'
)} )}