Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
824b1921e7 | ||
|
|
d4f5643799 | ||
|
|
72c49e62a8 | ||
|
|
0988edc129 | ||
|
|
4d266963ae | ||
|
|
ec12c7ecfd | ||
|
|
045dace274 | ||
|
|
2346b2f1a0 | ||
|
|
31859cb779 | ||
|
|
20507ecdd1 | ||
|
|
13ba661ea0 | ||
|
|
03f5b9fc7b | ||
|
|
b9fed65615 |
@@ -38,14 +38,16 @@ const DialogsContainer = () => {
|
||||
export const Layout = () => {
|
||||
const isHome = Boolean(useMatch(Routes.HOME));
|
||||
const { ANNOUNCEMENTS_CONFIG_URL } = useEnvironment();
|
||||
const fixedWidthClasses = 'w-full max-w-[1500px] mx-auto';
|
||||
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
className={classNames(
|
||||
'max-w-[1500px] min-h-[100vh]',
|
||||
'min-h-screen',
|
||||
'mx-auto my-0',
|
||||
'grid grid-rows-[auto_1fr_auto] grid-cols-1',
|
||||
'border-vega-light-200 dark:border-vega-dark-200 lg:border-l lg:border-r',
|
||||
'border-vega-light-200 dark:border-vega-dark-200',
|
||||
'antialiased text-black dark:text-white',
|
||||
'overflow-hidden relative'
|
||||
)}
|
||||
@@ -59,13 +61,13 @@ export const Layout = () => {
|
||||
)}
|
||||
<Header />
|
||||
</div>
|
||||
<div>
|
||||
<div className={fixedWidthClasses}>
|
||||
<main className="p-4">
|
||||
{!isHome && <BreadcrumbsContainer className="mb-4" />}
|
||||
<Outlet />
|
||||
</main>
|
||||
</div>
|
||||
<div>
|
||||
<div className={fixedWidthClasses}>
|
||||
<Footer />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
import classNames from 'classnames';
|
||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
||||
import type { ReactNode } from 'react';
|
||||
import { AnnouncementBanner } from '@vegaprotocol/announcements';
|
||||
import { Nav } from '../nav';
|
||||
import { Networks, useEnvironment } from '@vegaprotocol/environment';
|
||||
import React from 'react';
|
||||
|
||||
interface AppLayoutProps {
|
||||
children: ReactNode;
|
||||
}
|
||||
export const AppLayout = ({ children }: AppLayoutProps) => {
|
||||
const { VEGA_ENV, ANNOUNCEMENTS_CONFIG_URL } = useEnvironment();
|
||||
const { isReadOnly } = useVegaWallet();
|
||||
const AppLayoutClasses = classNames(
|
||||
'app w-full max-w-[1500px] mx-auto grid min-h-full',
|
||||
'border-neutral-700 lg:border-l lg:border-r',
|
||||
'app w-full max-w-[1500px] mx-auto grid',
|
||||
'lg:text-body-large',
|
||||
{
|
||||
'grid-rows-[repeat(2,min-content)_1fr_min-content]': !isReadOnly,
|
||||
@@ -17,5 +21,18 @@ export const AppLayout = ({ children }: AppLayoutProps) => {
|
||||
}
|
||||
);
|
||||
|
||||
return <div className={AppLayoutClasses}>{children}</div>;
|
||||
return (
|
||||
<div className="min-h-full">
|
||||
<div className="lg:text-body-large">
|
||||
{ANNOUNCEMENTS_CONFIG_URL && (
|
||||
<AnnouncementBanner
|
||||
app="governance"
|
||||
configUrl={ANNOUNCEMENTS_CONFIG_URL}
|
||||
/>
|
||||
)}
|
||||
<Nav theme={VEGA_ENV === Networks.TESTNET ? 'yellow' : 'dark'} />
|
||||
</div>
|
||||
<div className={AppLayoutClasses}>{children}</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,28 +1,16 @@
|
||||
import { Networks, useEnvironment } from '@vegaprotocol/environment';
|
||||
import { ViewingAsBanner } from '@vegaprotocol/ui-toolkit';
|
||||
import { AnnouncementBanner } from '@vegaprotocol/announcements';
|
||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
||||
import React from 'react';
|
||||
|
||||
import { Nav } from '../nav';
|
||||
|
||||
export interface TemplateSidebarProps {
|
||||
children: React.ReactNode;
|
||||
sidebar: React.ReactNode[];
|
||||
}
|
||||
|
||||
export function TemplateSidebar({ children, sidebar }: TemplateSidebarProps) {
|
||||
const { VEGA_ENV, ANNOUNCEMENTS_CONFIG_URL } = useEnvironment();
|
||||
const { isReadOnly, pubKey, disconnect } = useVegaWallet();
|
||||
return (
|
||||
<>
|
||||
{ANNOUNCEMENTS_CONFIG_URL && (
|
||||
<AnnouncementBanner
|
||||
app="governance"
|
||||
configUrl={ANNOUNCEMENTS_CONFIG_URL}
|
||||
/>
|
||||
)}
|
||||
<Nav theme={VEGA_ENV === Networks.TESTNET ? 'yellow' : 'dark'} />
|
||||
{isReadOnly ? (
|
||||
<ViewingAsBanner pubKey={pubKey} disconnect={disconnect} />
|
||||
) : null}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import type { ObservableQuery } from '@apollo/client';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
export const useRefreshAfterEpoch = (
|
||||
epochExpiry: string | undefined,
|
||||
refetch: ObservableQuery['refetch']
|
||||
refetch: () => void
|
||||
) => {
|
||||
return useEffect(() => {
|
||||
const epochInterval = setInterval(() => {
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
export const calculateEpochOffset = ({
|
||||
epochId,
|
||||
page,
|
||||
size,
|
||||
}: {
|
||||
epochId: number;
|
||||
page: number;
|
||||
size: number;
|
||||
}) => {
|
||||
// offset the epoch by the current page number times the page size while making sure it doesn't go below the minimum epoch value
|
||||
return {
|
||||
fromEpoch: Math.max(0, epochId - size * page) + 1,
|
||||
toEpoch: epochId - size * page + size,
|
||||
};
|
||||
};
|
||||
+1
-1
@@ -3,7 +3,7 @@ import { AppStateProvider } from '../../../contexts/app-state/app-state-provider
|
||||
import { EpochIndividualRewardsTable } from './epoch-individual-rewards-table';
|
||||
|
||||
const mockData = {
|
||||
epoch: '4441',
|
||||
epoch: 4441,
|
||||
rewards: [
|
||||
{
|
||||
asset: 'tDAI',
|
||||
|
||||
+68
-21
@@ -1,32 +1,43 @@
|
||||
import { useMemo } from 'react';
|
||||
import { useMemo, useEffect, useState, useCallback } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { AsyncRenderer } from '@vegaprotocol/ui-toolkit';
|
||||
import { AsyncRenderer, Pagination } from '@vegaprotocol/ui-toolkit';
|
||||
import { removePaginationWrapper } from '@vegaprotocol/utils';
|
||||
import type { EpochFieldsFragment } from '../home/__generated__/Rewards';
|
||||
import { useRewardsQuery } from '../home/__generated__/Rewards';
|
||||
import { ENV } from '../../../config';
|
||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
||||
import { EpochIndividualRewardsTable } from './epoch-individual-rewards-table';
|
||||
import { generateEpochIndividualRewardsList } from './generate-epoch-individual-rewards-list';
|
||||
import { calculateEpochOffset } from '../../../lib/epoch-pagination';
|
||||
|
||||
export const EpochIndividualRewards = () => {
|
||||
const EPOCHS_PAGE_SIZE = 10;
|
||||
|
||||
type EpochTotalRewardsProps = {
|
||||
currentEpoch: EpochFieldsFragment;
|
||||
};
|
||||
|
||||
export const EpochIndividualRewards = ({
|
||||
currentEpoch,
|
||||
}: EpochTotalRewardsProps) => {
|
||||
// we start from the previous epoch when displaying rewards data, because the current one has no calculated data while ongoing
|
||||
const epochId = Number(currentEpoch.id) - 1;
|
||||
const totalPages = Math.ceil(epochId / EPOCHS_PAGE_SIZE);
|
||||
const [page, setPage] = useState(1);
|
||||
const { t } = useTranslation();
|
||||
const { pubKey } = useVegaWallet();
|
||||
const { delegationsPagination } = ENV;
|
||||
|
||||
const { data, loading, error } = useRewardsQuery({
|
||||
const { data, loading, error, refetch } = useRewardsQuery({
|
||||
notifyOnNetworkStatusChange: true,
|
||||
variables: {
|
||||
partyId: pubKey || '',
|
||||
fromEpoch: epochId - EPOCHS_PAGE_SIZE,
|
||||
toEpoch: epochId,
|
||||
delegationsPagination: delegationsPagination
|
||||
? {
|
||||
first: Number(delegationsPagination),
|
||||
}
|
||||
: undefined,
|
||||
// we can use the same value for rewardsPagination as delegationsPagination
|
||||
rewardsPagination: delegationsPagination
|
||||
? {
|
||||
first: Number(delegationsPagination),
|
||||
}
|
||||
: undefined,
|
||||
},
|
||||
skip: !pubKey,
|
||||
});
|
||||
@@ -39,8 +50,37 @@ export const EpochIndividualRewards = () => {
|
||||
|
||||
const epochIndividualRewardSummaries = useMemo(() => {
|
||||
if (!data?.party) return [];
|
||||
return generateEpochIndividualRewardsList(rewards);
|
||||
}, [data?.party, rewards]);
|
||||
return generateEpochIndividualRewardsList({
|
||||
rewards,
|
||||
epochId,
|
||||
page,
|
||||
size: EPOCHS_PAGE_SIZE,
|
||||
});
|
||||
}, [data?.party, epochId, page, rewards]);
|
||||
|
||||
const refetchData = useCallback(
|
||||
async (toPage?: number) => {
|
||||
const targetPage = toPage ?? page;
|
||||
await refetch({
|
||||
partyId: pubKey || '',
|
||||
...calculateEpochOffset({ epochId, page, size: EPOCHS_PAGE_SIZE }),
|
||||
delegationsPagination: delegationsPagination
|
||||
? {
|
||||
first: Number(delegationsPagination),
|
||||
}
|
||||
: undefined,
|
||||
});
|
||||
setPage(targetPage);
|
||||
},
|
||||
[epochId, page, refetch, delegationsPagination, pubKey]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
// when the epoch changes, we want to refetch the data to update the current page
|
||||
if (data) {
|
||||
refetchData();
|
||||
}
|
||||
}, [epochId, data, refetchData]);
|
||||
|
||||
return (
|
||||
<AsyncRenderer
|
||||
@@ -53,17 +93,24 @@ export const EpochIndividualRewards = () => {
|
||||
{t('Connected Vega key')}:{' '}
|
||||
<span className="text-white">{pubKey}</span>
|
||||
</p>
|
||||
{epochIndividualRewardSummaries.length ? (
|
||||
epochIndividualRewardSummaries.map(
|
||||
(epochIndividualRewardSummary) => (
|
||||
<EpochIndividualRewardsTable
|
||||
data={epochIndividualRewardSummary}
|
||||
/>
|
||||
)
|
||||
{epochIndividualRewardSummaries.map(
|
||||
(epochIndividualRewardSummary) => (
|
||||
<EpochIndividualRewardsTable
|
||||
data={epochIndividualRewardSummary}
|
||||
/>
|
||||
)
|
||||
) : (
|
||||
<p>{t('noRewards')}</p>
|
||||
)}
|
||||
<Pagination
|
||||
isLoading={loading}
|
||||
hasPrevPage={page > 1}
|
||||
hasNextPage={page < totalPages}
|
||||
onBack={() => refetchData(page - 1)}
|
||||
onNext={() => refetchData(page + 1)}
|
||||
onFirst={() => refetchData(1)}
|
||||
onLast={() => refetchData(totalPages)}
|
||||
>
|
||||
{t('Page')} {page}
|
||||
</Pagination>
|
||||
</div>
|
||||
)}
|
||||
/>
|
||||
|
||||
+204
-15
@@ -43,6 +43,16 @@ describe('generateEpochIndividualRewardsList', () => {
|
||||
epoch: { id: '1' },
|
||||
};
|
||||
|
||||
const reward5: RewardFieldsFragment = {
|
||||
rewardType: AccountType.ACCOUNT_TYPE_FEES_LIQUIDITY,
|
||||
amount: '150',
|
||||
percentageOfTotal: '0.15',
|
||||
receivedAt: new Date(),
|
||||
asset: { id: 'usd', symbol: 'USD', name: 'USD' },
|
||||
party: { id: 'blah' },
|
||||
epoch: { id: '3' },
|
||||
};
|
||||
|
||||
const rewardWrongType: RewardFieldsFragment = {
|
||||
rewardType: AccountType.ACCOUNT_TYPE_INSURANCE,
|
||||
amount: '50',
|
||||
@@ -54,20 +64,38 @@ describe('generateEpochIndividualRewardsList', () => {
|
||||
};
|
||||
|
||||
it('should return an empty array if no rewards are provided', () => {
|
||||
expect(generateEpochIndividualRewardsList([])).toEqual([]);
|
||||
expect(
|
||||
generateEpochIndividualRewardsList({ rewards: [], epochId: 1 })
|
||||
).toEqual([
|
||||
{
|
||||
epoch: 1,
|
||||
rewards: [],
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('should filter out any rewards of the wrong type', () => {
|
||||
const result = generateEpochIndividualRewardsList([rewardWrongType]);
|
||||
const result = generateEpochIndividualRewardsList({
|
||||
rewards: [rewardWrongType],
|
||||
epochId: 1,
|
||||
});
|
||||
|
||||
expect(result).toEqual([]);
|
||||
expect(result).toEqual([
|
||||
{
|
||||
epoch: 1,
|
||||
rewards: [],
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('should return reward in the correct format', () => {
|
||||
const result = generateEpochIndividualRewardsList([reward1]);
|
||||
const result = generateEpochIndividualRewardsList({
|
||||
rewards: [reward1],
|
||||
epochId: 1,
|
||||
});
|
||||
|
||||
expect(result[0]).toEqual({
|
||||
epoch: '1',
|
||||
epoch: 1,
|
||||
rewards: [
|
||||
{
|
||||
asset: 'USD',
|
||||
@@ -105,21 +133,24 @@ describe('generateEpochIndividualRewardsList', () => {
|
||||
|
||||
it('should return an array sorted by epoch descending', () => {
|
||||
const rewards = [reward1, reward2, reward3, reward4];
|
||||
const result1 = generateEpochIndividualRewardsList(rewards);
|
||||
const result1 = generateEpochIndividualRewardsList({ rewards, epochId: 2 });
|
||||
|
||||
expect(result1[0].epoch).toEqual('2');
|
||||
expect(result1[1].epoch).toEqual('1');
|
||||
expect(result1[0].epoch).toEqual(2);
|
||||
expect(result1[1].epoch).toEqual(1);
|
||||
|
||||
const reorderedRewards = [reward4, reward3, reward2, reward1];
|
||||
const result2 = generateEpochIndividualRewardsList(reorderedRewards);
|
||||
const result2 = generateEpochIndividualRewardsList({
|
||||
rewards: reorderedRewards,
|
||||
epochId: 2,
|
||||
});
|
||||
|
||||
expect(result2[0].epoch).toEqual('2');
|
||||
expect(result2[1].epoch).toEqual('1');
|
||||
expect(result2[0].epoch).toEqual(2);
|
||||
expect(result2[1].epoch).toEqual(1);
|
||||
});
|
||||
|
||||
it('correctly calculates the total value of rewards for an asset', () => {
|
||||
const rewards = [reward1, reward4];
|
||||
const result = generateEpochIndividualRewardsList(rewards);
|
||||
const result = generateEpochIndividualRewardsList({ rewards, epochId: 1 });
|
||||
|
||||
expect(result[0].rewards[0].totalAmount).toEqual('200');
|
||||
});
|
||||
@@ -127,11 +158,11 @@ describe('generateEpochIndividualRewardsList', () => {
|
||||
it('returns data in the expected shape', () => {
|
||||
// Just sanity checking the whole structure here
|
||||
const rewards = [reward1, reward2, reward3, reward4];
|
||||
const result = generateEpochIndividualRewardsList(rewards);
|
||||
const result = generateEpochIndividualRewardsList({ rewards, epochId: 2 });
|
||||
|
||||
expect(result).toEqual([
|
||||
{
|
||||
epoch: '2',
|
||||
epoch: 2,
|
||||
rewards: [
|
||||
{
|
||||
asset: 'GBP',
|
||||
@@ -196,7 +227,165 @@ describe('generateEpochIndividualRewardsList', () => {
|
||||
],
|
||||
},
|
||||
{
|
||||
epoch: '1',
|
||||
epoch: 1,
|
||||
rewards: [
|
||||
{
|
||||
asset: 'USD',
|
||||
totalAmount: '200',
|
||||
rewardTypes: {
|
||||
[AccountType.ACCOUNT_TYPE_FEES_INFRASTRUCTURE]: {
|
||||
amount: '0',
|
||||
percentageOfTotal: '0',
|
||||
},
|
||||
[AccountType.ACCOUNT_TYPE_FEES_LIQUIDITY]: {
|
||||
amount: '100',
|
||||
percentageOfTotal: '0.1',
|
||||
},
|
||||
[AccountType.ACCOUNT_TYPE_GLOBAL_REWARD]: {
|
||||
amount: '100',
|
||||
percentageOfTotal: '0.1',
|
||||
},
|
||||
[AccountType.ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES]: {
|
||||
amount: '0',
|
||||
percentageOfTotal: '0',
|
||||
},
|
||||
[AccountType.ACCOUNT_TYPE_REWARD_MAKER_RECEIVED_FEES]: {
|
||||
amount: '0',
|
||||
percentageOfTotal: '0',
|
||||
},
|
||||
[AccountType.ACCOUNT_TYPE_REWARD_MARKET_PROPOSERS]: {
|
||||
amount: '0',
|
||||
percentageOfTotal: '0',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('returns data correctly for the requested epoch range', () => {
|
||||
const rewards = [reward1, reward2, reward3, reward4, reward5];
|
||||
const resultPageOne = generateEpochIndividualRewardsList({
|
||||
rewards,
|
||||
epochId: 3,
|
||||
page: 1,
|
||||
size: 2,
|
||||
});
|
||||
|
||||
expect(resultPageOne).toEqual([
|
||||
{
|
||||
epoch: 3,
|
||||
rewards: [
|
||||
{
|
||||
asset: 'USD',
|
||||
totalAmount: '150',
|
||||
rewardTypes: {
|
||||
[AccountType.ACCOUNT_TYPE_FEES_INFRASTRUCTURE]: {
|
||||
amount: '0',
|
||||
percentageOfTotal: '0',
|
||||
},
|
||||
[AccountType.ACCOUNT_TYPE_FEES_LIQUIDITY]: {
|
||||
amount: '150',
|
||||
percentageOfTotal: '0.15',
|
||||
},
|
||||
[AccountType.ACCOUNT_TYPE_GLOBAL_REWARD]: {
|
||||
amount: '0',
|
||||
percentageOfTotal: '0',
|
||||
},
|
||||
[AccountType.ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES]: {
|
||||
amount: '0',
|
||||
percentageOfTotal: '0',
|
||||
},
|
||||
[AccountType.ACCOUNT_TYPE_REWARD_MAKER_RECEIVED_FEES]: {
|
||||
amount: '0',
|
||||
percentageOfTotal: '0',
|
||||
},
|
||||
[AccountType.ACCOUNT_TYPE_REWARD_MARKET_PROPOSERS]: {
|
||||
amount: '0',
|
||||
percentageOfTotal: '0',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
epoch: 2,
|
||||
rewards: [
|
||||
{
|
||||
asset: 'GBP',
|
||||
totalAmount: '200',
|
||||
rewardTypes: {
|
||||
[AccountType.ACCOUNT_TYPE_FEES_INFRASTRUCTURE]: {
|
||||
amount: '0',
|
||||
percentageOfTotal: '0',
|
||||
},
|
||||
[AccountType.ACCOUNT_TYPE_FEES_LIQUIDITY]: {
|
||||
amount: '200',
|
||||
percentageOfTotal: '0.2',
|
||||
},
|
||||
[AccountType.ACCOUNT_TYPE_GLOBAL_REWARD]: {
|
||||
amount: '0',
|
||||
percentageOfTotal: '0',
|
||||
},
|
||||
[AccountType.ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES]: {
|
||||
amount: '0',
|
||||
percentageOfTotal: '0',
|
||||
},
|
||||
[AccountType.ACCOUNT_TYPE_REWARD_MAKER_RECEIVED_FEES]: {
|
||||
amount: '0',
|
||||
percentageOfTotal: '0',
|
||||
},
|
||||
[AccountType.ACCOUNT_TYPE_REWARD_MARKET_PROPOSERS]: {
|
||||
amount: '0',
|
||||
percentageOfTotal: '0',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
asset: 'EUR',
|
||||
totalAmount: '50',
|
||||
rewardTypes: {
|
||||
[AccountType.ACCOUNT_TYPE_FEES_INFRASTRUCTURE]: {
|
||||
amount: '0',
|
||||
percentageOfTotal: '0',
|
||||
},
|
||||
[AccountType.ACCOUNT_TYPE_FEES_LIQUIDITY]: {
|
||||
amount: '0',
|
||||
percentageOfTotal: '0',
|
||||
},
|
||||
[AccountType.ACCOUNT_TYPE_GLOBAL_REWARD]: {
|
||||
amount: '50',
|
||||
percentageOfTotal: '0.05',
|
||||
},
|
||||
[AccountType.ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES]: {
|
||||
amount: '0',
|
||||
percentageOfTotal: '0',
|
||||
},
|
||||
[AccountType.ACCOUNT_TYPE_REWARD_MAKER_RECEIVED_FEES]: {
|
||||
amount: '0',
|
||||
percentageOfTotal: '0',
|
||||
},
|
||||
[AccountType.ACCOUNT_TYPE_REWARD_MARKET_PROPOSERS]: {
|
||||
amount: '0',
|
||||
percentageOfTotal: '0',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
|
||||
const resultPageTwo = generateEpochIndividualRewardsList({
|
||||
rewards,
|
||||
epochId: 3,
|
||||
page: 2,
|
||||
size: 2,
|
||||
});
|
||||
|
||||
expect(resultPageTwo).toEqual([
|
||||
{
|
||||
epoch: 1,
|
||||
rewards: [
|
||||
{
|
||||
asset: 'USD',
|
||||
|
||||
+30
-11
@@ -2,9 +2,10 @@ import { BigNumber } from '../../../lib/bignumber';
|
||||
import { RowAccountTypes } from '../shared-rewards-table-assets/shared-rewards-table-assets';
|
||||
import type { RewardFieldsFragment } from '../home/__generated__/Rewards';
|
||||
import type { AccountType } from '@vegaprotocol/types';
|
||||
import { calculateEpochOffset } from '../../../lib/epoch-pagination';
|
||||
|
||||
export interface EpochIndividualReward {
|
||||
epoch: string;
|
||||
epoch: number;
|
||||
rewards: {
|
||||
asset: string;
|
||||
totalAmount: string;
|
||||
@@ -27,11 +28,29 @@ const emptyRowAccountTypes = accountTypes.map((type) => [
|
||||
},
|
||||
]);
|
||||
|
||||
export const generateEpochIndividualRewardsList = (
|
||||
rewards: RewardFieldsFragment[]
|
||||
) => {
|
||||
export const generateEpochIndividualRewardsList = ({
|
||||
rewards,
|
||||
epochId,
|
||||
page = 1,
|
||||
size = 10,
|
||||
}: {
|
||||
rewards: RewardFieldsFragment[];
|
||||
epochId: number;
|
||||
page?: number;
|
||||
size?: number;
|
||||
}) => {
|
||||
const map: Map<string, EpochIndividualReward> = new Map();
|
||||
const { fromEpoch, toEpoch } = calculateEpochOffset({ epochId, page, size });
|
||||
|
||||
for (let i = toEpoch; i >= fromEpoch; i--) {
|
||||
map.set(i.toString(), {
|
||||
epoch: i,
|
||||
rewards: [],
|
||||
});
|
||||
}
|
||||
|
||||
// We take the rewards and aggregate them by epoch and asset.
|
||||
const epochIndividualRewards = rewards.reduce((map, reward) => {
|
||||
const epochIndividualRewards = rewards.reduce((acc, reward) => {
|
||||
const epochId = reward.epoch.id;
|
||||
const assetName = reward.asset.name;
|
||||
const rewardType = reward.rewardType;
|
||||
@@ -40,14 +59,14 @@ export const generateEpochIndividualRewardsList = (
|
||||
|
||||
// if the rewardType is not of a type we display in the table, we skip it.
|
||||
if (!accountTypes.includes(rewardType)) {
|
||||
return map;
|
||||
return acc;
|
||||
}
|
||||
|
||||
if (!map.has(epochId)) {
|
||||
map.set(epochId, { epoch: epochId, rewards: [] });
|
||||
if (!acc.has(epochId)) {
|
||||
return acc;
|
||||
}
|
||||
|
||||
const epoch = map.get(epochId);
|
||||
const epoch = acc.get(epochId);
|
||||
|
||||
let asset = epoch?.rewards.find((r) => r.asset === assetName);
|
||||
|
||||
@@ -76,8 +95,8 @@ export const generateEpochIndividualRewardsList = (
|
||||
});
|
||||
}
|
||||
|
||||
return map;
|
||||
}, new Map<string, EpochIndividualReward>());
|
||||
return acc;
|
||||
}, map);
|
||||
|
||||
return Array.from(epochIndividualRewards.values()).sort(
|
||||
(a, b) => Number(b.epoch) - Number(a.epoch)
|
||||
|
||||
+54
-34
@@ -1,44 +1,64 @@
|
||||
import { render } from '@testing-library/react';
|
||||
import { AppStateProvider } from '../../../contexts/app-state/app-state-provider';
|
||||
import { EpochTotalRewardsTable } from './epoch-total-rewards-table';
|
||||
import type {
|
||||
AggregatedEpochRewardSummary,
|
||||
RewardType,
|
||||
RewardItem,
|
||||
} from './generate-epoch-total-rewards-list';
|
||||
import { AccountType } from '@vegaprotocol/types';
|
||||
|
||||
const assetId =
|
||||
'b340c130096819428a62e5df407fd6abe66e444b89ad64f670beb98621c9c663';
|
||||
|
||||
const rewardsList = [
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_GLOBAL_REWARD,
|
||||
amount: '0',
|
||||
},
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_FEES_INFRASTRUCTURE,
|
||||
amount: '295',
|
||||
},
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES,
|
||||
amount: '0',
|
||||
},
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_REWARD_MAKER_RECEIVED_FEES,
|
||||
amount: '0',
|
||||
},
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_FEES_LIQUIDITY,
|
||||
amount: '0',
|
||||
},
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_REWARD_MARKET_PROPOSERS,
|
||||
amount: '0',
|
||||
},
|
||||
];
|
||||
|
||||
const rewards: Map<RewardType, RewardItem> = new Map();
|
||||
|
||||
rewardsList.forEach((r) => {
|
||||
rewards.set(r.rewardType, r);
|
||||
});
|
||||
|
||||
const assetRewards: Map<
|
||||
AggregatedEpochRewardSummary['assetId'],
|
||||
AggregatedEpochRewardSummary
|
||||
> = new Map();
|
||||
|
||||
assetRewards.set(assetId, {
|
||||
assetId,
|
||||
name: 'tDAI TEST',
|
||||
rewards,
|
||||
totalAmount: '295',
|
||||
});
|
||||
|
||||
const mockData = {
|
||||
epoch: 4431,
|
||||
assetRewards: [
|
||||
{
|
||||
assetId:
|
||||
'b340c130096819428a62e5df407fd6abe66e444b89ad64f670beb98621c9c663',
|
||||
name: 'tDAI TEST',
|
||||
rewards: [
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_GLOBAL_REWARD,
|
||||
amount: '0',
|
||||
},
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_FEES_INFRASTRUCTURE,
|
||||
amount: '295',
|
||||
},
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES,
|
||||
amount: '0',
|
||||
},
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_REWARD_MAKER_RECEIVED_FEES,
|
||||
amount: '0',
|
||||
},
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_FEES_LIQUIDITY,
|
||||
amount: '0',
|
||||
},
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_REWARD_MARKET_PROPOSERS,
|
||||
amount: '0',
|
||||
},
|
||||
],
|
||||
totalAmount: '295',
|
||||
},
|
||||
],
|
||||
assetRewards,
|
||||
};
|
||||
|
||||
describe('EpochTotalRewardsTable', () => {
|
||||
|
||||
+12
-10
@@ -48,17 +48,19 @@ export const EpochTotalRewardsTable = ({
|
||||
}: EpochTotalRewardsGridProps) => {
|
||||
return (
|
||||
<RewardsTable dataTestId="epoch-total-rewards-table" epoch={data.epoch}>
|
||||
{data.assetRewards.map(({ name, rewards, totalAmount }, i) => (
|
||||
<div className="contents" key={i}>
|
||||
<div data-testid="asset" className={`${rowGridItemStyles()} p-5`}>
|
||||
{name}
|
||||
{Array.from(data.assetRewards.values()).map(
|
||||
({ name, rewards, totalAmount }, i) => (
|
||||
<div className="contents" key={i}>
|
||||
<div data-testid="asset" className={`${rowGridItemStyles()} p-5`}>
|
||||
{name}
|
||||
</div>
|
||||
{Array.from(rewards.values()).map(({ rewardType, amount }, i) => (
|
||||
<RewardItem key={i} dataTestId={rewardType} value={amount} />
|
||||
))}
|
||||
<RewardItem dataTestId="total" value={totalAmount} last={true} />
|
||||
</div>
|
||||
{rewards.map(({ rewardType, amount }, i) => (
|
||||
<RewardItem key={i} dataTestId={rewardType} value={amount} />
|
||||
))}
|
||||
<RewardItem dataTestId="total" value={totalAmount} last={true} />
|
||||
</div>
|
||||
))}
|
||||
)
|
||||
)}
|
||||
</RewardsTable>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,21 +1,62 @@
|
||||
import { AsyncRenderer } from '@vegaprotocol/ui-toolkit';
|
||||
import { useState, useCallback, useEffect } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { AsyncRenderer, Pagination } from '@vegaprotocol/ui-toolkit';
|
||||
import type { EpochFieldsFragment } from '../home/__generated__/Rewards';
|
||||
import { useEpochAssetsRewardsQuery } from '../home/__generated__/Rewards';
|
||||
import { useRefreshAfterEpoch } from '../../../hooks/use-refresh-after-epoch';
|
||||
import { generateEpochTotalRewardsList } from './generate-epoch-total-rewards-list';
|
||||
import { NoRewards } from '../no-rewards';
|
||||
import { EpochTotalRewardsTable } from './epoch-total-rewards-table';
|
||||
import { calculateEpochOffset } from '../../../lib/epoch-pagination';
|
||||
|
||||
export const EpochTotalRewards = () => {
|
||||
const EPOCHS_PAGE_SIZE = 10;
|
||||
|
||||
type EpochTotalRewardsProps = {
|
||||
currentEpoch: EpochFieldsFragment;
|
||||
};
|
||||
|
||||
export const EpochTotalRewards = ({ currentEpoch }: EpochTotalRewardsProps) => {
|
||||
// we start from the previous epoch when displaying rewards data, because the current one has no calculated data while ongoing
|
||||
const epochId = Number(currentEpoch.id) - 1;
|
||||
const totalPages = Math.ceil(epochId / EPOCHS_PAGE_SIZE);
|
||||
const { t } = useTranslation();
|
||||
const [page, setPage] = useState(1);
|
||||
const { data, loading, error, refetch } = useEpochAssetsRewardsQuery({
|
||||
notifyOnNetworkStatusChange: true,
|
||||
variables: {
|
||||
epochRewardSummariesPagination: {
|
||||
first: 10,
|
||||
epochRewardSummariesFilter: {
|
||||
fromEpoch: epochId - EPOCHS_PAGE_SIZE,
|
||||
},
|
||||
},
|
||||
});
|
||||
useRefreshAfterEpoch(data?.epoch.timestamps.expiry, refetch);
|
||||
|
||||
const epochTotalRewardSummaries = generateEpochTotalRewardsList(data) || [];
|
||||
const refetchData = useCallback(
|
||||
async (toPage?: number) => {
|
||||
const targetPage = toPage ?? page;
|
||||
await refetch({
|
||||
epochRewardSummariesFilter: calculateEpochOffset({
|
||||
epochId,
|
||||
page: targetPage,
|
||||
size: EPOCHS_PAGE_SIZE,
|
||||
}),
|
||||
});
|
||||
setPage(targetPage);
|
||||
},
|
||||
[epochId, page, refetch]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
// when the epoch changes, we want to refetch the data to update the current page
|
||||
if (data) {
|
||||
refetchData();
|
||||
}
|
||||
}, [epochId, data, refetchData]);
|
||||
|
||||
const epochTotalRewardSummaries =
|
||||
generateEpochTotalRewardsList({
|
||||
data,
|
||||
epochId,
|
||||
page,
|
||||
size: EPOCHS_PAGE_SIZE,
|
||||
}) || [];
|
||||
|
||||
return (
|
||||
<AsyncRenderer
|
||||
@@ -27,15 +68,22 @@ export const EpochTotalRewards = () => {
|
||||
className="max-w-full overflow-auto"
|
||||
data-testid="epoch-rewards-total"
|
||||
>
|
||||
{epochTotalRewardSummaries.length === 0 ? (
|
||||
<NoRewards />
|
||||
) : (
|
||||
<>
|
||||
{epochTotalRewardSummaries.map((epochTotalSummary, index) => (
|
||||
<EpochTotalRewardsTable data={epochTotalSummary} key={index} />
|
||||
))}
|
||||
</>
|
||||
{Array.from(epochTotalRewardSummaries.values()).map(
|
||||
(epochTotalSummary, index) => (
|
||||
<EpochTotalRewardsTable data={epochTotalSummary} key={index} />
|
||||
)
|
||||
)}
|
||||
<Pagination
|
||||
isLoading={loading}
|
||||
hasPrevPage={page > 1}
|
||||
hasNextPage={page < totalPages}
|
||||
onBack={() => refetchData(page - 1)}
|
||||
onNext={() => refetchData(page + 1)}
|
||||
onFirst={() => refetchData(1)}
|
||||
onLast={() => refetchData(totalPages)}
|
||||
>
|
||||
{t('Page')} {page}
|
||||
</Pagination>
|
||||
</div>
|
||||
)}
|
||||
/>
|
||||
|
||||
+521
-117
@@ -3,13 +3,23 @@ import { AccountType } from '@vegaprotocol/types';
|
||||
|
||||
describe('generateEpochAssetRewardsList', () => {
|
||||
it('should return an empty array if data is undefined', () => {
|
||||
const result = generateEpochTotalRewardsList(undefined);
|
||||
const result = generateEpochTotalRewardsList({ epochId: 1 });
|
||||
|
||||
expect(result).toEqual([]);
|
||||
expect(result).toEqual(
|
||||
new Map([
|
||||
[
|
||||
'1',
|
||||
{
|
||||
epoch: 1,
|
||||
assetRewards: new Map(),
|
||||
},
|
||||
],
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
it('should return an empty array if empty data is provided', () => {
|
||||
const epochData = {
|
||||
it('should return an empty map if empty data is provided', () => {
|
||||
const data = {
|
||||
assetsConnection: {
|
||||
edges: [],
|
||||
},
|
||||
@@ -23,13 +33,23 @@ describe('generateEpochAssetRewardsList', () => {
|
||||
},
|
||||
};
|
||||
|
||||
const result = generateEpochTotalRewardsList(epochData);
|
||||
const result = generateEpochTotalRewardsList({ data, epochId: 1 });
|
||||
|
||||
expect(result).toEqual([]);
|
||||
expect(result).toEqual(
|
||||
new Map([
|
||||
[
|
||||
'1',
|
||||
{
|
||||
epoch: 1,
|
||||
assetRewards: new Map(),
|
||||
},
|
||||
],
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
it('should return an empty array if no epochRewardSummaries are provided', () => {
|
||||
const epochData = {
|
||||
it('should return an empty map if no epochRewardSummaries are provided', () => {
|
||||
const data = {
|
||||
assetsConnection: {
|
||||
edges: [
|
||||
{
|
||||
@@ -56,13 +76,23 @@ describe('generateEpochAssetRewardsList', () => {
|
||||
},
|
||||
};
|
||||
|
||||
const result = generateEpochTotalRewardsList(epochData);
|
||||
const result = generateEpochTotalRewardsList({ data, epochId: 1 });
|
||||
|
||||
expect(result).toEqual([]);
|
||||
expect(result).toEqual(
|
||||
new Map([
|
||||
[
|
||||
'1',
|
||||
{
|
||||
epoch: 1,
|
||||
assetRewards: new Map(),
|
||||
},
|
||||
],
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
it('should return an array of unnamed assets if no asset names are provided (should not happen)', () => {
|
||||
const epochData = {
|
||||
it('should return a map of unnamed assets if no asset names are provided (should not happen)', () => {
|
||||
const data = {
|
||||
assetsConnection: {
|
||||
edges: [],
|
||||
},
|
||||
@@ -85,50 +115,80 @@ describe('generateEpochAssetRewardsList', () => {
|
||||
},
|
||||
};
|
||||
|
||||
const result = generateEpochTotalRewardsList(epochData);
|
||||
const result = generateEpochTotalRewardsList({ data, epochId: 1 });
|
||||
|
||||
expect(result).toEqual([
|
||||
{
|
||||
epoch: 1,
|
||||
assetRewards: [
|
||||
expect(result).toEqual(
|
||||
new Map([
|
||||
[
|
||||
'1',
|
||||
{
|
||||
assetId: '1',
|
||||
name: '',
|
||||
rewards: [
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_GLOBAL_REWARD,
|
||||
amount: '123',
|
||||
},
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_FEES_INFRASTRUCTURE,
|
||||
amount: '0',
|
||||
},
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES,
|
||||
amount: '0',
|
||||
},
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_REWARD_MAKER_RECEIVED_FEES,
|
||||
amount: '0',
|
||||
},
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_FEES_LIQUIDITY,
|
||||
amount: '0',
|
||||
},
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_REWARD_MARKET_PROPOSERS,
|
||||
amount: '0',
|
||||
},
|
||||
],
|
||||
totalAmount: '123',
|
||||
epoch: 1,
|
||||
assetRewards: new Map([
|
||||
[
|
||||
'1',
|
||||
{
|
||||
assetId: '1',
|
||||
name: '',
|
||||
rewards: new Map([
|
||||
[
|
||||
AccountType.ACCOUNT_TYPE_GLOBAL_REWARD,
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_GLOBAL_REWARD,
|
||||
amount: '123',
|
||||
},
|
||||
],
|
||||
[
|
||||
AccountType.ACCOUNT_TYPE_FEES_INFRASTRUCTURE,
|
||||
{
|
||||
rewardType:
|
||||
AccountType.ACCOUNT_TYPE_FEES_INFRASTRUCTURE,
|
||||
amount: '0',
|
||||
},
|
||||
],
|
||||
[
|
||||
AccountType.ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES,
|
||||
{
|
||||
rewardType:
|
||||
AccountType.ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES,
|
||||
amount: '0',
|
||||
},
|
||||
],
|
||||
[
|
||||
AccountType.ACCOUNT_TYPE_REWARD_MAKER_RECEIVED_FEES,
|
||||
{
|
||||
rewardType:
|
||||
AccountType.ACCOUNT_TYPE_REWARD_MAKER_RECEIVED_FEES,
|
||||
amount: '0',
|
||||
},
|
||||
],
|
||||
[
|
||||
AccountType.ACCOUNT_TYPE_FEES_LIQUIDITY,
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_FEES_LIQUIDITY,
|
||||
amount: '0',
|
||||
},
|
||||
],
|
||||
[
|
||||
AccountType.ACCOUNT_TYPE_REWARD_MARKET_PROPOSERS,
|
||||
{
|
||||
rewardType:
|
||||
AccountType.ACCOUNT_TYPE_REWARD_MARKET_PROPOSERS,
|
||||
amount: '0',
|
||||
},
|
||||
],
|
||||
]),
|
||||
totalAmount: '123',
|
||||
},
|
||||
],
|
||||
]),
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
it('should return an array of aggregated epoch summaries', () => {
|
||||
const epochData = {
|
||||
it('should return the aggregated epoch summaries', () => {
|
||||
const data = {
|
||||
assetsConnection: {
|
||||
edges: [
|
||||
{
|
||||
@@ -180,81 +240,425 @@ describe('generateEpochAssetRewardsList', () => {
|
||||
},
|
||||
};
|
||||
|
||||
const result = generateEpochTotalRewardsList(epochData);
|
||||
const result = generateEpochTotalRewardsList({ data, epochId: 2 });
|
||||
|
||||
expect(result).toEqual([
|
||||
{
|
||||
epoch: 1,
|
||||
assetRewards: [
|
||||
expect(result).toEqual(
|
||||
new Map([
|
||||
[
|
||||
'1',
|
||||
{
|
||||
assetId: '1',
|
||||
name: 'Asset 1',
|
||||
rewards: [
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_GLOBAL_REWARD,
|
||||
amount: '0',
|
||||
},
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_FEES_INFRASTRUCTURE,
|
||||
amount: '100',
|
||||
},
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES,
|
||||
amount: '123',
|
||||
},
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_REWARD_MAKER_RECEIVED_FEES,
|
||||
amount: '0',
|
||||
},
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_FEES_LIQUIDITY,
|
||||
amount: '0',
|
||||
},
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_REWARD_MARKET_PROPOSERS,
|
||||
amount: '0',
|
||||
},
|
||||
],
|
||||
totalAmount: '223',
|
||||
epoch: 1,
|
||||
assetRewards: new Map([
|
||||
[
|
||||
'1',
|
||||
{
|
||||
assetId: '1',
|
||||
name: 'Asset 1',
|
||||
rewards: new Map([
|
||||
[
|
||||
AccountType.ACCOUNT_TYPE_GLOBAL_REWARD,
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_GLOBAL_REWARD,
|
||||
amount: '0',
|
||||
},
|
||||
],
|
||||
[
|
||||
AccountType.ACCOUNT_TYPE_FEES_INFRASTRUCTURE,
|
||||
{
|
||||
rewardType:
|
||||
AccountType.ACCOUNT_TYPE_FEES_INFRASTRUCTURE,
|
||||
amount: '100',
|
||||
},
|
||||
],
|
||||
[
|
||||
AccountType.ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES,
|
||||
{
|
||||
rewardType:
|
||||
AccountType.ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES,
|
||||
amount: '123',
|
||||
},
|
||||
],
|
||||
[
|
||||
AccountType.ACCOUNT_TYPE_REWARD_MAKER_RECEIVED_FEES,
|
||||
{
|
||||
rewardType:
|
||||
AccountType.ACCOUNT_TYPE_REWARD_MAKER_RECEIVED_FEES,
|
||||
amount: '0',
|
||||
},
|
||||
],
|
||||
[
|
||||
AccountType.ACCOUNT_TYPE_FEES_LIQUIDITY,
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_FEES_LIQUIDITY,
|
||||
amount: '0',
|
||||
},
|
||||
],
|
||||
[
|
||||
AccountType.ACCOUNT_TYPE_REWARD_MARKET_PROPOSERS,
|
||||
{
|
||||
rewardType:
|
||||
AccountType.ACCOUNT_TYPE_REWARD_MARKET_PROPOSERS,
|
||||
amount: '0',
|
||||
},
|
||||
],
|
||||
]),
|
||||
totalAmount: '223',
|
||||
},
|
||||
],
|
||||
]),
|
||||
},
|
||||
],
|
||||
[
|
||||
'2',
|
||||
{
|
||||
epoch: 2,
|
||||
assetRewards: new Map([
|
||||
[
|
||||
'1',
|
||||
{
|
||||
assetId: '1',
|
||||
name: 'Asset 1',
|
||||
rewards: new Map([
|
||||
[
|
||||
AccountType.ACCOUNT_TYPE_GLOBAL_REWARD,
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_GLOBAL_REWARD,
|
||||
amount: '0',
|
||||
},
|
||||
],
|
||||
[
|
||||
AccountType.ACCOUNT_TYPE_FEES_INFRASTRUCTURE,
|
||||
{
|
||||
rewardType:
|
||||
AccountType.ACCOUNT_TYPE_FEES_INFRASTRUCTURE,
|
||||
amount: '0',
|
||||
},
|
||||
],
|
||||
[
|
||||
AccountType.ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES,
|
||||
{
|
||||
rewardType:
|
||||
AccountType.ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES,
|
||||
amount: '0',
|
||||
},
|
||||
],
|
||||
[
|
||||
AccountType.ACCOUNT_TYPE_REWARD_MAKER_RECEIVED_FEES,
|
||||
{
|
||||
rewardType:
|
||||
AccountType.ACCOUNT_TYPE_REWARD_MAKER_RECEIVED_FEES,
|
||||
amount: '0',
|
||||
},
|
||||
],
|
||||
[
|
||||
AccountType.ACCOUNT_TYPE_FEES_LIQUIDITY,
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_FEES_LIQUIDITY,
|
||||
amount: '5',
|
||||
},
|
||||
],
|
||||
[
|
||||
AccountType.ACCOUNT_TYPE_REWARD_MARKET_PROPOSERS,
|
||||
{
|
||||
rewardType:
|
||||
AccountType.ACCOUNT_TYPE_REWARD_MARKET_PROPOSERS,
|
||||
amount: '0',
|
||||
},
|
||||
],
|
||||
]),
|
||||
totalAmount: '5',
|
||||
},
|
||||
],
|
||||
]),
|
||||
},
|
||||
],
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
it('should return the requested range for aggregated epoch summaries', () => {
|
||||
const data = {
|
||||
assetsConnection: {
|
||||
edges: [
|
||||
{
|
||||
node: {
|
||||
id: '1',
|
||||
name: 'Asset 1',
|
||||
},
|
||||
},
|
||||
{
|
||||
node: {
|
||||
id: '2',
|
||||
name: 'Asset 2',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
epoch: 2,
|
||||
assetRewards: [
|
||||
epochRewardSummaries: {
|
||||
edges: [
|
||||
{
|
||||
assetId: '1',
|
||||
name: 'Asset 1',
|
||||
rewards: [
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_GLOBAL_REWARD,
|
||||
amount: '0',
|
||||
},
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_FEES_INFRASTRUCTURE,
|
||||
amount: '0',
|
||||
},
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES,
|
||||
amount: '0',
|
||||
},
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_REWARD_MAKER_RECEIVED_FEES,
|
||||
amount: '0',
|
||||
},
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_FEES_LIQUIDITY,
|
||||
amount: '5',
|
||||
},
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_REWARD_MARKET_PROPOSERS,
|
||||
amount: '0',
|
||||
},
|
||||
],
|
||||
totalAmount: '5',
|
||||
node: {
|
||||
epoch: 1,
|
||||
assetId: '1',
|
||||
rewardType: AccountType.ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES,
|
||||
amount: '123',
|
||||
},
|
||||
},
|
||||
{
|
||||
node: {
|
||||
epoch: 1,
|
||||
assetId: '1',
|
||||
rewardType: AccountType.ACCOUNT_TYPE_FEES_INFRASTRUCTURE,
|
||||
amount: '100',
|
||||
},
|
||||
},
|
||||
{
|
||||
node: {
|
||||
epoch: 2,
|
||||
assetId: '1',
|
||||
rewardType: AccountType.ACCOUNT_TYPE_FEES_LIQUIDITY,
|
||||
amount: '6',
|
||||
},
|
||||
},
|
||||
{
|
||||
node: {
|
||||
epoch: 2,
|
||||
assetId: '1',
|
||||
rewardType: AccountType.ACCOUNT_TYPE_FEES_LIQUIDITY,
|
||||
amount: '27',
|
||||
},
|
||||
},
|
||||
{
|
||||
node: {
|
||||
epoch: 3,
|
||||
assetId: '1',
|
||||
rewardType: AccountType.ACCOUNT_TYPE_FEES_INFRASTRUCTURE,
|
||||
amount: '15',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
epoch: {
|
||||
timestamps: {
|
||||
expiry: null,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const resultPageOne = generateEpochTotalRewardsList({
|
||||
data,
|
||||
epochId: 3,
|
||||
page: 1,
|
||||
size: 2,
|
||||
});
|
||||
|
||||
expect(resultPageOne).toEqual(
|
||||
new Map([
|
||||
[
|
||||
'2',
|
||||
{
|
||||
epoch: 2,
|
||||
assetRewards: new Map([
|
||||
[
|
||||
'1',
|
||||
{
|
||||
assetId: '1',
|
||||
name: 'Asset 1',
|
||||
rewards: new Map([
|
||||
[
|
||||
AccountType.ACCOUNT_TYPE_GLOBAL_REWARD,
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_GLOBAL_REWARD,
|
||||
amount: '0',
|
||||
},
|
||||
],
|
||||
[
|
||||
AccountType.ACCOUNT_TYPE_FEES_INFRASTRUCTURE,
|
||||
{
|
||||
rewardType:
|
||||
AccountType.ACCOUNT_TYPE_FEES_INFRASTRUCTURE,
|
||||
amount: '0',
|
||||
},
|
||||
],
|
||||
[
|
||||
AccountType.ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES,
|
||||
{
|
||||
rewardType:
|
||||
AccountType.ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES,
|
||||
amount: '0',
|
||||
},
|
||||
],
|
||||
[
|
||||
AccountType.ACCOUNT_TYPE_REWARD_MAKER_RECEIVED_FEES,
|
||||
{
|
||||
rewardType:
|
||||
AccountType.ACCOUNT_TYPE_REWARD_MAKER_RECEIVED_FEES,
|
||||
amount: '0',
|
||||
},
|
||||
],
|
||||
[
|
||||
AccountType.ACCOUNT_TYPE_FEES_LIQUIDITY,
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_FEES_LIQUIDITY,
|
||||
amount: '33',
|
||||
},
|
||||
],
|
||||
[
|
||||
AccountType.ACCOUNT_TYPE_REWARD_MARKET_PROPOSERS,
|
||||
{
|
||||
rewardType:
|
||||
AccountType.ACCOUNT_TYPE_REWARD_MARKET_PROPOSERS,
|
||||
amount: '0',
|
||||
},
|
||||
],
|
||||
]),
|
||||
totalAmount: '33',
|
||||
},
|
||||
],
|
||||
]),
|
||||
},
|
||||
],
|
||||
[
|
||||
'3',
|
||||
{
|
||||
epoch: 3,
|
||||
assetRewards: new Map([
|
||||
[
|
||||
'1',
|
||||
{
|
||||
assetId: '1',
|
||||
name: 'Asset 1',
|
||||
rewards: new Map([
|
||||
[
|
||||
AccountType.ACCOUNT_TYPE_GLOBAL_REWARD,
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_GLOBAL_REWARD,
|
||||
amount: '0',
|
||||
},
|
||||
],
|
||||
[
|
||||
AccountType.ACCOUNT_TYPE_FEES_INFRASTRUCTURE,
|
||||
{
|
||||
rewardType:
|
||||
AccountType.ACCOUNT_TYPE_FEES_INFRASTRUCTURE,
|
||||
amount: '15',
|
||||
},
|
||||
],
|
||||
[
|
||||
AccountType.ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES,
|
||||
{
|
||||
rewardType:
|
||||
AccountType.ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES,
|
||||
amount: '0',
|
||||
},
|
||||
],
|
||||
[
|
||||
AccountType.ACCOUNT_TYPE_REWARD_MAKER_RECEIVED_FEES,
|
||||
{
|
||||
rewardType:
|
||||
AccountType.ACCOUNT_TYPE_REWARD_MAKER_RECEIVED_FEES,
|
||||
amount: '0',
|
||||
},
|
||||
],
|
||||
[
|
||||
AccountType.ACCOUNT_TYPE_FEES_LIQUIDITY,
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_FEES_LIQUIDITY,
|
||||
amount: '0',
|
||||
},
|
||||
],
|
||||
[
|
||||
AccountType.ACCOUNT_TYPE_REWARD_MARKET_PROPOSERS,
|
||||
{
|
||||
rewardType:
|
||||
AccountType.ACCOUNT_TYPE_REWARD_MARKET_PROPOSERS,
|
||||
amount: '0',
|
||||
},
|
||||
],
|
||||
]),
|
||||
totalAmount: '15',
|
||||
},
|
||||
],
|
||||
]),
|
||||
},
|
||||
],
|
||||
])
|
||||
);
|
||||
|
||||
const resultPageTwo = generateEpochTotalRewardsList({
|
||||
data,
|
||||
epochId: 3,
|
||||
page: 2,
|
||||
size: 2,
|
||||
});
|
||||
|
||||
expect(resultPageTwo).toEqual(
|
||||
new Map([
|
||||
[
|
||||
'1',
|
||||
{
|
||||
epoch: 1,
|
||||
assetRewards: new Map([
|
||||
[
|
||||
'1',
|
||||
{
|
||||
assetId: '1',
|
||||
name: 'Asset 1',
|
||||
rewards: new Map([
|
||||
[
|
||||
AccountType.ACCOUNT_TYPE_GLOBAL_REWARD,
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_GLOBAL_REWARD,
|
||||
amount: '0',
|
||||
},
|
||||
],
|
||||
[
|
||||
AccountType.ACCOUNT_TYPE_FEES_INFRASTRUCTURE,
|
||||
{
|
||||
rewardType:
|
||||
AccountType.ACCOUNT_TYPE_FEES_INFRASTRUCTURE,
|
||||
amount: '100',
|
||||
},
|
||||
],
|
||||
[
|
||||
AccountType.ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES,
|
||||
{
|
||||
rewardType:
|
||||
AccountType.ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES,
|
||||
amount: '123',
|
||||
},
|
||||
],
|
||||
[
|
||||
AccountType.ACCOUNT_TYPE_REWARD_MAKER_RECEIVED_FEES,
|
||||
{
|
||||
rewardType:
|
||||
AccountType.ACCOUNT_TYPE_REWARD_MAKER_RECEIVED_FEES,
|
||||
amount: '0',
|
||||
},
|
||||
],
|
||||
[
|
||||
AccountType.ACCOUNT_TYPE_FEES_LIQUIDITY,
|
||||
{
|
||||
rewardType: AccountType.ACCOUNT_TYPE_FEES_LIQUIDITY,
|
||||
amount: '0',
|
||||
},
|
||||
],
|
||||
[
|
||||
AccountType.ACCOUNT_TYPE_REWARD_MARKET_PROPOSERS,
|
||||
{
|
||||
rewardType:
|
||||
AccountType.ACCOUNT_TYPE_REWARD_MARKET_PROPOSERS,
|
||||
amount: '0',
|
||||
},
|
||||
],
|
||||
]),
|
||||
totalAmount: '223',
|
||||
},
|
||||
],
|
||||
]),
|
||||
},
|
||||
],
|
||||
])
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
+74
-104
@@ -5,127 +5,97 @@ import type {
|
||||
import { removePaginationWrapper } from '@vegaprotocol/utils';
|
||||
import { RowAccountTypes } from '../shared-rewards-table-assets/shared-rewards-table-assets';
|
||||
import type { AccountType } from '@vegaprotocol/types';
|
||||
import { BigNumber } from '../../../lib/bignumber';
|
||||
import { calculateEpochOffset } from '../../../lib/epoch-pagination';
|
||||
|
||||
interface EpochSummaryWithNamedReward extends EpochRewardSummaryFieldsFragment {
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface AggregatedEpochRewardSummary {
|
||||
export type RewardType = EpochRewardSummaryFieldsFragment['rewardType'];
|
||||
export type RewardItem = Pick<
|
||||
EpochRewardSummaryFieldsFragment,
|
||||
'rewardType' | 'amount'
|
||||
>;
|
||||
|
||||
export type AggregatedEpochRewardSummary = {
|
||||
assetId: EpochRewardSummaryFieldsFragment['assetId'];
|
||||
name: EpochSummaryWithNamedReward['name'];
|
||||
rewards: {
|
||||
rewardType: EpochRewardSummaryFieldsFragment['rewardType'];
|
||||
amount: EpochRewardSummaryFieldsFragment['amount'];
|
||||
}[];
|
||||
rewards: Map<RewardType, RewardItem>;
|
||||
totalAmount: string;
|
||||
}
|
||||
};
|
||||
|
||||
export interface EpochTotalSummary {
|
||||
export type EpochTotalSummary = {
|
||||
epoch: EpochRewardSummaryFieldsFragment['epoch'];
|
||||
assetRewards: AggregatedEpochRewardSummary[];
|
||||
}
|
||||
assetRewards: Map<
|
||||
EpochRewardSummaryFieldsFragment['assetId'],
|
||||
AggregatedEpochRewardSummary
|
||||
>;
|
||||
};
|
||||
|
||||
const emptyRowAccountTypes = Object.keys(RowAccountTypes).map((type) => ({
|
||||
rewardType: type as AccountType,
|
||||
amount: '0',
|
||||
}));
|
||||
const emptyRowAccountTypes: Map<RewardType, RewardItem> = new Map();
|
||||
|
||||
export const generateEpochTotalRewardsList = (
|
||||
epochData: EpochAssetsRewardsQuery | undefined
|
||||
) => {
|
||||
Object.keys(RowAccountTypes).forEach((type) => {
|
||||
emptyRowAccountTypes.set(type as AccountType, {
|
||||
rewardType: type as AccountType,
|
||||
amount: '0',
|
||||
});
|
||||
});
|
||||
|
||||
export const generateEpochTotalRewardsList = ({
|
||||
data,
|
||||
epochId,
|
||||
page = 1,
|
||||
size = 10,
|
||||
}: {
|
||||
data?: EpochAssetsRewardsQuery | undefined;
|
||||
epochId: number;
|
||||
page?: number;
|
||||
size?: number;
|
||||
}) => {
|
||||
const epochRewardSummaries = removePaginationWrapper(
|
||||
epochData?.epochRewardSummaries?.edges
|
||||
data?.epochRewardSummaries?.edges
|
||||
);
|
||||
|
||||
const assets = removePaginationWrapper(epochData?.assetsConnection?.edges);
|
||||
const assets = removePaginationWrapper(data?.assetsConnection?.edges);
|
||||
|
||||
// Because the epochRewardSummaries don't have the asset name, we need to find it in the assets list
|
||||
const epochSummariesWithNamedReward: EpochSummaryWithNamedReward[] =
|
||||
epochRewardSummaries.map((epochReward) => ({
|
||||
...epochReward,
|
||||
name:
|
||||
assets.find((asset) => asset.id === epochReward.assetId)?.name || '',
|
||||
}));
|
||||
const map: Map<string, EpochTotalSummary> = new Map();
|
||||
const { fromEpoch, toEpoch } = calculateEpochOffset({ epochId, page, size });
|
||||
|
||||
// Aggregating the epoch summaries by epoch number
|
||||
const aggregatedEpochSummariesByEpochNumber =
|
||||
epochSummariesWithNamedReward.reduce((acc, epochReward) => {
|
||||
const epoch = epochReward.epoch;
|
||||
const epochSummaryIndex = acc.findIndex(
|
||||
(epochSummary) => epochSummary[0].epoch === epoch
|
||||
);
|
||||
|
||||
if (epochSummaryIndex === -1) {
|
||||
acc.push([epochReward]);
|
||||
} else {
|
||||
acc[epochSummaryIndex].push(epochReward);
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, [] as EpochSummaryWithNamedReward[][]);
|
||||
|
||||
// Now aggregate the array of arrays of epoch summaries by asset rewards.
|
||||
const epochTotalRewards: EpochTotalSummary[] =
|
||||
aggregatedEpochSummariesByEpochNumber.map((epochSummaries) => {
|
||||
const assetRewards = epochSummaries.reduce((acc, epochSummary) => {
|
||||
const assetRewardIndex = acc.findIndex(
|
||||
(assetReward) =>
|
||||
assetReward.assetId === epochSummary.assetId &&
|
||||
assetReward.name === epochSummary.name
|
||||
);
|
||||
|
||||
if (assetRewardIndex === -1) {
|
||||
acc.push({
|
||||
assetId: epochSummary.assetId,
|
||||
name: epochSummary.name,
|
||||
rewards: [
|
||||
...emptyRowAccountTypes.map((emptyRowAccountType) => {
|
||||
if (
|
||||
emptyRowAccountType.rewardType === epochSummary.rewardType
|
||||
) {
|
||||
return {
|
||||
rewardType: epochSummary.rewardType,
|
||||
amount: epochSummary.amount,
|
||||
};
|
||||
} else {
|
||||
return emptyRowAccountType;
|
||||
}
|
||||
}),
|
||||
],
|
||||
totalAmount: epochSummary.amount,
|
||||
});
|
||||
} else {
|
||||
acc[assetRewardIndex].rewards = acc[assetRewardIndex].rewards.map(
|
||||
(reward) => {
|
||||
if (reward.rewardType === epochSummary.rewardType) {
|
||||
return {
|
||||
rewardType: epochSummary.rewardType,
|
||||
amount: (
|
||||
Number(reward.amount) + Number(epochSummary.amount)
|
||||
).toString(),
|
||||
};
|
||||
} else {
|
||||
return reward;
|
||||
}
|
||||
}
|
||||
);
|
||||
acc[assetRewardIndex].totalAmount = (
|
||||
Number(acc[assetRewardIndex].totalAmount) +
|
||||
Number(epochSummary.amount)
|
||||
).toString();
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, [] as AggregatedEpochRewardSummary[]);
|
||||
|
||||
return {
|
||||
epoch: epochSummaries[0].epoch,
|
||||
assetRewards: assetRewards.sort((a, b) => {
|
||||
return new BigNumber(b.totalAmount).comparedTo(a.totalAmount);
|
||||
}),
|
||||
};
|
||||
for (let i = toEpoch; i >= fromEpoch; i--) {
|
||||
map.set(i.toString(), {
|
||||
epoch: i,
|
||||
assetRewards: new Map(),
|
||||
});
|
||||
}
|
||||
|
||||
return epochTotalRewards;
|
||||
return epochRewardSummaries.reduce((acc, reward) => {
|
||||
const epoch = acc.get(reward.epoch.toString());
|
||||
|
||||
if (epoch) {
|
||||
const matchingAsset = assets.find((asset) => asset.id === reward.assetId);
|
||||
const assetWithRewards = epoch.assetRewards.get(reward.assetId);
|
||||
|
||||
const rewards =
|
||||
assetWithRewards?.rewards || new Map(emptyRowAccountTypes);
|
||||
const rewardItem = rewards?.get(reward.rewardType);
|
||||
const amount = (
|
||||
(Number(rewardItem?.amount) || 0) + Number(reward.amount)
|
||||
).toString();
|
||||
|
||||
rewards?.set(reward.rewardType, {
|
||||
rewardType: reward.rewardType,
|
||||
amount,
|
||||
});
|
||||
|
||||
epoch.assetRewards.set(reward.assetId, {
|
||||
assetId: reward.assetId,
|
||||
name: matchingAsset?.name || '',
|
||||
rewards: rewards || new Map(emptyRowAccountTypes),
|
||||
totalAmount: (
|
||||
Number(reward.amount) + Number(assetWithRewards?.totalAmount || 0)
|
||||
).toString(),
|
||||
});
|
||||
}
|
||||
return acc;
|
||||
}, map);
|
||||
};
|
||||
|
||||
@@ -23,12 +23,18 @@ fragment DelegationFields on Delegation {
|
||||
|
||||
query Rewards(
|
||||
$partyId: ID!
|
||||
$delegationsPagination: Pagination
|
||||
$fromEpoch: Int
|
||||
$toEpoch: Int
|
||||
$rewardsPagination: Pagination
|
||||
$delegationsPagination: Pagination
|
||||
) {
|
||||
party(id: $partyId) {
|
||||
id
|
||||
rewardsConnection(pagination: $rewardsPagination) {
|
||||
rewardsConnection(
|
||||
fromEpoch: $fromEpoch
|
||||
toEpoch: $toEpoch
|
||||
pagination: $rewardsPagination
|
||||
) {
|
||||
edges {
|
||||
node {
|
||||
...RewardFields
|
||||
@@ -43,14 +49,6 @@ query Rewards(
|
||||
}
|
||||
}
|
||||
}
|
||||
epoch {
|
||||
id
|
||||
timestamps {
|
||||
start
|
||||
end
|
||||
expiry
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fragment EpochRewardSummaryFields on EpochRewardSummary {
|
||||
@@ -60,7 +58,10 @@ fragment EpochRewardSummaryFields on EpochRewardSummary {
|
||||
rewardType
|
||||
}
|
||||
|
||||
query EpochAssetsRewards($epochRewardSummariesPagination: Pagination) {
|
||||
query EpochAssetsRewards(
|
||||
$epochRewardSummariesFilter: RewardSummaryFilter
|
||||
$epochRewardSummariesPagination: Pagination
|
||||
) {
|
||||
assetsConnection {
|
||||
edges {
|
||||
node {
|
||||
@@ -69,18 +70,16 @@ query EpochAssetsRewards($epochRewardSummariesPagination: Pagination) {
|
||||
}
|
||||
}
|
||||
}
|
||||
epochRewardSummaries(pagination: $epochRewardSummariesPagination) {
|
||||
epochRewardSummaries(
|
||||
filter: $epochRewardSummariesFilter
|
||||
pagination: $epochRewardSummariesPagination
|
||||
) {
|
||||
edges {
|
||||
node {
|
||||
...EpochRewardSummaryFields
|
||||
}
|
||||
}
|
||||
}
|
||||
epoch {
|
||||
timestamps {
|
||||
expiry
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fragment EpochFields on Epoch {
|
||||
|
||||
+21
-21
@@ -9,21 +9,24 @@ export type DelegationFieldsFragment = { __typename?: 'Delegation', amount: stri
|
||||
|
||||
export type RewardsQueryVariables = Types.Exact<{
|
||||
partyId: Types.Scalars['ID'];
|
||||
delegationsPagination?: Types.InputMaybe<Types.Pagination>;
|
||||
fromEpoch?: Types.InputMaybe<Types.Scalars['Int']>;
|
||||
toEpoch?: Types.InputMaybe<Types.Scalars['Int']>;
|
||||
rewardsPagination?: Types.InputMaybe<Types.Pagination>;
|
||||
delegationsPagination?: Types.InputMaybe<Types.Pagination>;
|
||||
}>;
|
||||
|
||||
|
||||
export type RewardsQuery = { __typename?: 'Query', party?: { __typename?: 'Party', id: string, rewardsConnection?: { __typename?: 'RewardsConnection', edges?: Array<{ __typename?: 'RewardEdge', node: { __typename?: 'Reward', rewardType: Types.AccountType, amount: string, percentageOfTotal: string, receivedAt: any, asset: { __typename?: 'Asset', id: string, symbol: string, name: string }, party: { __typename?: 'Party', id: string }, epoch: { __typename?: 'Epoch', id: string } } } | null> | null } | null, delegationsConnection?: { __typename?: 'DelegationsConnection', edges?: Array<{ __typename?: 'DelegationEdge', node: { __typename?: 'Delegation', amount: string, epoch: number } } | null> | null } | null } | null, epoch: { __typename?: 'Epoch', id: string, timestamps: { __typename?: 'EpochTimestamps', start?: any | null, end?: any | null, expiry?: any | null } } };
|
||||
export type RewardsQuery = { __typename?: 'Query', party?: { __typename?: 'Party', id: string, rewardsConnection?: { __typename?: 'RewardsConnection', edges?: Array<{ __typename?: 'RewardEdge', node: { __typename?: 'Reward', rewardType: Types.AccountType, amount: string, percentageOfTotal: string, receivedAt: any, asset: { __typename?: 'Asset', id: string, symbol: string, name: string }, party: { __typename?: 'Party', id: string }, epoch: { __typename?: 'Epoch', id: string } } } | null> | null } | null, delegationsConnection?: { __typename?: 'DelegationsConnection', edges?: Array<{ __typename?: 'DelegationEdge', node: { __typename?: 'Delegation', amount: string, epoch: number } } | null> | null } | null } | null };
|
||||
|
||||
export type EpochRewardSummaryFieldsFragment = { __typename?: 'EpochRewardSummary', epoch: number, assetId: string, amount: string, rewardType: Types.AccountType };
|
||||
|
||||
export type EpochAssetsRewardsQueryVariables = Types.Exact<{
|
||||
epochRewardSummariesFilter?: Types.InputMaybe<Types.RewardSummaryFilter>;
|
||||
epochRewardSummariesPagination?: Types.InputMaybe<Types.Pagination>;
|
||||
}>;
|
||||
|
||||
|
||||
export type EpochAssetsRewardsQuery = { __typename?: 'Query', assetsConnection?: { __typename?: 'AssetsConnection', edges?: Array<{ __typename?: 'AssetEdge', node: { __typename?: 'Asset', id: string, name: string } } | null> | null } | null, epochRewardSummaries?: { __typename?: 'EpochRewardSummaryConnection', edges?: Array<{ __typename?: 'EpochRewardSummaryEdge', node: { __typename?: 'EpochRewardSummary', epoch: number, assetId: string, amount: string, rewardType: Types.AccountType } } | null> | null } | null, epoch: { __typename?: 'Epoch', timestamps: { __typename?: 'EpochTimestamps', expiry?: any | null } } };
|
||||
export type EpochAssetsRewardsQuery = { __typename?: 'Query', assetsConnection?: { __typename?: 'AssetsConnection', edges?: Array<{ __typename?: 'AssetEdge', node: { __typename?: 'Asset', id: string, name: string } } | null> | null } | null, epochRewardSummaries?: { __typename?: 'EpochRewardSummaryConnection', edges?: Array<{ __typename?: 'EpochRewardSummaryEdge', node: { __typename?: 'EpochRewardSummary', epoch: number, assetId: string, amount: string, rewardType: Types.AccountType } } | null> | null } | null };
|
||||
|
||||
export type EpochFieldsFragment = { __typename?: 'Epoch', id: string, timestamps: { __typename?: 'EpochTimestamps', start?: any | null, end?: any | null, expiry?: any | null } };
|
||||
|
||||
@@ -76,10 +79,14 @@ export const EpochFieldsFragmentDoc = gql`
|
||||
}
|
||||
`;
|
||||
export const RewardsDocument = gql`
|
||||
query Rewards($partyId: ID!, $delegationsPagination: Pagination, $rewardsPagination: Pagination) {
|
||||
query Rewards($partyId: ID!, $fromEpoch: Int, $toEpoch: Int, $rewardsPagination: Pagination, $delegationsPagination: Pagination) {
|
||||
party(id: $partyId) {
|
||||
id
|
||||
rewardsConnection(pagination: $rewardsPagination) {
|
||||
rewardsConnection(
|
||||
fromEpoch: $fromEpoch
|
||||
toEpoch: $toEpoch
|
||||
pagination: $rewardsPagination
|
||||
) {
|
||||
edges {
|
||||
node {
|
||||
...RewardFields
|
||||
@@ -94,14 +101,6 @@ export const RewardsDocument = gql`
|
||||
}
|
||||
}
|
||||
}
|
||||
epoch {
|
||||
id
|
||||
timestamps {
|
||||
start
|
||||
end
|
||||
expiry
|
||||
}
|
||||
}
|
||||
}
|
||||
${RewardFieldsFragmentDoc}
|
||||
${DelegationFieldsFragmentDoc}`;
|
||||
@@ -119,8 +118,10 @@ ${DelegationFieldsFragmentDoc}`;
|
||||
* const { data, loading, error } = useRewardsQuery({
|
||||
* variables: {
|
||||
* partyId: // value for 'partyId'
|
||||
* delegationsPagination: // value for 'delegationsPagination'
|
||||
* fromEpoch: // value for 'fromEpoch'
|
||||
* toEpoch: // value for 'toEpoch'
|
||||
* rewardsPagination: // value for 'rewardsPagination'
|
||||
* delegationsPagination: // value for 'delegationsPagination'
|
||||
* },
|
||||
* });
|
||||
*/
|
||||
@@ -136,7 +137,7 @@ export type RewardsQueryHookResult = ReturnType<typeof useRewardsQuery>;
|
||||
export type RewardsLazyQueryHookResult = ReturnType<typeof useRewardsLazyQuery>;
|
||||
export type RewardsQueryResult = Apollo.QueryResult<RewardsQuery, RewardsQueryVariables>;
|
||||
export const EpochAssetsRewardsDocument = gql`
|
||||
query EpochAssetsRewards($epochRewardSummariesPagination: Pagination) {
|
||||
query EpochAssetsRewards($epochRewardSummariesFilter: RewardSummaryFilter, $epochRewardSummariesPagination: Pagination) {
|
||||
assetsConnection {
|
||||
edges {
|
||||
node {
|
||||
@@ -145,18 +146,16 @@ export const EpochAssetsRewardsDocument = gql`
|
||||
}
|
||||
}
|
||||
}
|
||||
epochRewardSummaries(pagination: $epochRewardSummariesPagination) {
|
||||
epochRewardSummaries(
|
||||
filter: $epochRewardSummariesFilter
|
||||
pagination: $epochRewardSummariesPagination
|
||||
) {
|
||||
edges {
|
||||
node {
|
||||
...EpochRewardSummaryFields
|
||||
}
|
||||
}
|
||||
}
|
||||
epoch {
|
||||
timestamps {
|
||||
expiry
|
||||
}
|
||||
}
|
||||
}
|
||||
${EpochRewardSummaryFieldsFragmentDoc}`;
|
||||
|
||||
@@ -172,6 +171,7 @@ export const EpochAssetsRewardsDocument = gql`
|
||||
* @example
|
||||
* const { data, loading, error } = useEpochAssetsRewardsQuery({
|
||||
* variables: {
|
||||
* epochRewardSummariesFilter: // value for 'epochRewardSummariesFilter'
|
||||
* epochRewardSummariesPagination: // value for 'epochRewardSummariesPagination'
|
||||
* },
|
||||
* });
|
||||
|
||||
@@ -136,11 +136,15 @@ export const RewardsPage = () => {
|
||||
</section>
|
||||
|
||||
{toggleRewardsView === 'total' ? (
|
||||
<EpochTotalRewards />
|
||||
epochData?.epoch ? (
|
||||
<EpochTotalRewards currentEpoch={epochData?.epoch} />
|
||||
) : null
|
||||
) : (
|
||||
<section>
|
||||
{pubKey && pubKeys?.length ? (
|
||||
<EpochIndividualRewards />
|
||||
epochData?.epoch ? (
|
||||
<EpochIndividualRewards currentEpoch={epochData?.epoch} />
|
||||
) : null
|
||||
) : (
|
||||
<ConnectToSeeRewards />
|
||||
)}
|
||||
|
||||
@@ -1,11 +1,44 @@
|
||||
[
|
||||
{
|
||||
"tranche_id": 57,
|
||||
"tranche_start": "2024-04-01T00:00:00.000Z",
|
||||
"tranche_end": "2024-10-01T00:00:00.000Z",
|
||||
"total_added": "2500",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "2500",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "2500",
|
||||
"user": "0x6ad69157EfB1E17EBf6614D352D098589EaE3060",
|
||||
"tx": "0xd89dcda79394278ed62c6d2d36c94d90c59a6cf2c0135903796db75c1797b644"
|
||||
}
|
||||
],
|
||||
"withdrawals": [],
|
||||
"users": [
|
||||
{
|
||||
"address": "0x6ad69157EfB1E17EBf6614D352D098589EaE3060",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "2500",
|
||||
"user": "0x6ad69157EfB1E17EBf6614D352D098589EaE3060",
|
||||
"tranche_id": 57,
|
||||
"tx": "0xd89dcda79394278ed62c6d2d36c94d90c59a6cf2c0135903796db75c1797b644"
|
||||
}
|
||||
],
|
||||
"withdrawals": [],
|
||||
"total_tokens": "2500",
|
||||
"withdrawn_tokens": "0",
|
||||
"remaining_tokens": "2500"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tranche_id": 56,
|
||||
"tranche_start": "2023-04-20T00:00:00.000Z",
|
||||
"tranche_end": "2023-05-20T00:00:00.000Z",
|
||||
"total_added": "15711.125",
|
||||
"total_added": "15761.125",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "15711.125",
|
||||
"locked_amount": "15761.125",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "241.5",
|
||||
@@ -87,6 +120,11 @@
|
||||
"user": "0x697cEF6741F519621fE14c72041e4B8B1f7e2c8A",
|
||||
"tx": "0xc7483de16af39896b3ae052dd8a6e01fb3dc3794ceb9d2a76d81436992af320e"
|
||||
},
|
||||
{
|
||||
"amount": "50",
|
||||
"user": "0x9E53F72210479BF46aE7ABF77c48B0d611b3c3dB",
|
||||
"tx": "0x3ce5a0e3e1eed31ca786cb22ee1b7bea1936491604306b10390d93198602d746"
|
||||
},
|
||||
{
|
||||
"amount": "50",
|
||||
"user": "0x15024E62134A8BFFCce11f5ce58CeCDe853038D7",
|
||||
@@ -376,6 +414,21 @@
|
||||
"withdrawn_tokens": "0",
|
||||
"remaining_tokens": "103.5"
|
||||
},
|
||||
{
|
||||
"address": "0x9E53F72210479BF46aE7ABF77c48B0d611b3c3dB",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "50",
|
||||
"user": "0x9E53F72210479BF46aE7ABF77c48B0d611b3c3dB",
|
||||
"tranche_id": 56,
|
||||
"tx": "0x3ce5a0e3e1eed31ca786cb22ee1b7bea1936491604306b10390d93198602d746"
|
||||
}
|
||||
],
|
||||
"withdrawals": [],
|
||||
"total_tokens": "50",
|
||||
"withdrawn_tokens": "0",
|
||||
"remaining_tokens": "50"
|
||||
},
|
||||
{
|
||||
"address": "0x15024E62134A8BFFCce11f5ce58CeCDe853038D7",
|
||||
"deposits": [
|
||||
@@ -547,10 +600,15 @@
|
||||
"tranche_id": 55,
|
||||
"tranche_start": "2023-09-01T00:00:00.000Z",
|
||||
"tranche_end": "2024-03-01T00:00:00.000Z",
|
||||
"total_added": "17500",
|
||||
"total_added": "30000",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "17500",
|
||||
"locked_amount": "30000",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "12500",
|
||||
"user": "0x52dD21Bd0A8fBD31f4D5002c34b98d0c328791c8",
|
||||
"tx": "0xd89dcda79394278ed62c6d2d36c94d90c59a6cf2c0135903796db75c1797b644"
|
||||
},
|
||||
{
|
||||
"amount": "12500",
|
||||
"user": "0x52dD21Bd0A8fBD31f4D5002c34b98d0c328791c8",
|
||||
@@ -567,6 +625,12 @@
|
||||
{
|
||||
"address": "0x52dD21Bd0A8fBD31f4D5002c34b98d0c328791c8",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "12500",
|
||||
"user": "0x52dD21Bd0A8fBD31f4D5002c34b98d0c328791c8",
|
||||
"tranche_id": 55,
|
||||
"tx": "0xd89dcda79394278ed62c6d2d36c94d90c59a6cf2c0135903796db75c1797b644"
|
||||
},
|
||||
{
|
||||
"amount": "12500",
|
||||
"user": "0x52dD21Bd0A8fBD31f4D5002c34b98d0c328791c8",
|
||||
@@ -575,9 +639,9 @@
|
||||
}
|
||||
],
|
||||
"withdrawals": [],
|
||||
"total_tokens": "12500",
|
||||
"total_tokens": "25000",
|
||||
"withdrawn_tokens": "0",
|
||||
"remaining_tokens": "12500"
|
||||
"remaining_tokens": "25000"
|
||||
},
|
||||
{
|
||||
"address": "0xbCDBCC3Ff54D659f2CC737bEf49B10D92dF3FDbf",
|
||||
@@ -602,7 +666,7 @@
|
||||
"tranche_end": "2023-05-06T00:00:00.000Z",
|
||||
"total_added": "8865",
|
||||
"total_removed": "362.31015740205",
|
||||
"locked_amount": "5538.613958333333793",
|
||||
"locked_amount": "4947.631059027778128",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "33",
|
||||
@@ -1212,10 +1276,15 @@
|
||||
"tranche_id": 50,
|
||||
"tranche_start": "2023-10-01T00:00:00.000Z",
|
||||
"tranche_end": "2024-04-01T00:00:00.000Z",
|
||||
"total_added": "2500",
|
||||
"total_added": "10000",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "2500",
|
||||
"locked_amount": "10000",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "7500",
|
||||
"user": "0x20CD77B9FC2f1fEDfb6F184E25f7127BFE991C8b",
|
||||
"tx": "0xd89dcda79394278ed62c6d2d36c94d90c59a6cf2c0135903796db75c1797b644"
|
||||
},
|
||||
{
|
||||
"amount": "2500",
|
||||
"user": "0x6ad69157EfB1E17EBf6614D352D098589EaE3060",
|
||||
@@ -1224,6 +1293,21 @@
|
||||
],
|
||||
"withdrawals": [],
|
||||
"users": [
|
||||
{
|
||||
"address": "0x20CD77B9FC2f1fEDfb6F184E25f7127BFE991C8b",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "7500",
|
||||
"user": "0x20CD77B9FC2f1fEDfb6F184E25f7127BFE991C8b",
|
||||
"tranche_id": 50,
|
||||
"tx": "0xd89dcda79394278ed62c6d2d36c94d90c59a6cf2c0135903796db75c1797b644"
|
||||
}
|
||||
],
|
||||
"withdrawals": [],
|
||||
"total_tokens": "7500",
|
||||
"withdrawn_tokens": "0",
|
||||
"remaining_tokens": "7500"
|
||||
},
|
||||
{
|
||||
"address": "0x6ad69157EfB1E17EBf6614D352D098589EaE3060",
|
||||
"deposits": [
|
||||
@@ -4323,7 +4407,7 @@
|
||||
"tranche_end": "2023-12-05T00:00:00.000Z",
|
||||
"total_added": "86666.297",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "55025.5466231533472612942",
|
||||
"locked_amount": "54550.6765448265232514477",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "86666.297",
|
||||
@@ -4389,7 +4473,7 @@
|
||||
"tranche_end": "2023-06-01T00:00:00.000Z",
|
||||
"total_added": "2500",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "614.60431929181935",
|
||||
"locked_amount": "587.132586741961625",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "2500",
|
||||
@@ -4510,7 +4594,7 @@
|
||||
"tranche_end": "2023-09-01T00:00:00.000Z",
|
||||
"total_added": "17500",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "13005.4668629227055",
|
||||
"locked_amount": "12815.2549755938015",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "12500",
|
||||
@@ -4777,7 +4861,7 @@
|
||||
"tranche_end": "2023-08-01T00:00:00.000Z",
|
||||
"total_added": "37500",
|
||||
"total_removed": "12294.731717775",
|
||||
"locked_amount": "21908.1203959484325",
|
||||
"locked_amount": "21493.76774478207375",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "7500",
|
||||
@@ -5141,7 +5225,7 @@
|
||||
"tranche_end": "2023-12-05T00:00:00.000Z",
|
||||
"total_added": "129999.45",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "54975.34273543947564153",
|
||||
"locked_amount": "54500.905916308673138415",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "129999.45",
|
||||
@@ -5174,7 +5258,7 @@
|
||||
"tranche_end": "2024-04-01T00:00:00.000Z",
|
||||
"total_added": "54144.7663",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "51739.79106068279198289418",
|
||||
"locked_amount": "51443.92658193328217573951",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "54144.7663",
|
||||
@@ -5207,7 +5291,7 @@
|
||||
"tranche_end": "2023-09-03T00:00:00.000Z",
|
||||
"total_added": "62600",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "23795.408143074584596",
|
||||
"locked_amount": "23452.40436960933488",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "10000",
|
||||
@@ -5400,7 +5484,7 @@
|
||||
"tranche_end": "2023-09-17T00:00:00.000Z",
|
||||
"total_added": "5000",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "2092.3725266362253",
|
||||
"locked_amount": "2064.976059107052",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "5000",
|
||||
@@ -5941,7 +6025,7 @@
|
||||
"tranche_end": "2023-05-01T00:00:00.000Z",
|
||||
"total_added": "22500",
|
||||
"total_removed": "6871.43713545",
|
||||
"locked_amount": "1708.408149171271425",
|
||||
"locked_amount": "1459.796558471453925",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "7500",
|
||||
@@ -6425,7 +6509,7 @@
|
||||
"tranche_end": "2023-06-02T00:00:00.000Z",
|
||||
"total_added": "1939928.38",
|
||||
"total_removed": "928642.9598472029154",
|
||||
"locked_amount": "243119.235875715365230116",
|
||||
"locked_amount": "232489.7989013972454998708",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "1852091.69",
|
||||
@@ -40241,7 +40325,7 @@
|
||||
"tranche_end": "2023-06-05T00:00:00.000Z",
|
||||
"total_added": "3732368.4671",
|
||||
"total_removed": "715655.108029600523393",
|
||||
"locked_amount": "398090.945142600518940293162",
|
||||
"locked_amount": "381757.201289964680148718477",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "1998.95815",
|
||||
@@ -41633,8 +41717,8 @@
|
||||
"tranche_start": "2022-06-05T00:00:00.000Z",
|
||||
"tranche_end": "2023-12-05T00:00:00.000Z",
|
||||
"total_added": "15870102.715470999700000001",
|
||||
"total_removed": "834257.00587199386490352",
|
||||
"locked_amount": "6711292.5172348569092608533891844209570154",
|
||||
"total_removed": "835090.78677275839915352",
|
||||
"locked_amount": "6653374.1102600029976151216559241015233847",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "16249.93",
|
||||
@@ -42188,6 +42272,11 @@
|
||||
"user": "0x20CD77B9FC2f1fEDfb6F184E25f7127BFE991C8b",
|
||||
"tx": "0x94df9afacf00f3d2a01e8856c83050a2737cd31f7736ae472bfbb3f19e66f5e4"
|
||||
},
|
||||
{
|
||||
"amount": "833.78090076453425",
|
||||
"user": "0x20CD77B9FC2f1fEDfb6F184E25f7127BFE991C8b",
|
||||
"tx": "0xa56a064890829624fb37f887adb87987dfafd709ebea2cdf423c91a38e91b82f"
|
||||
},
|
||||
{
|
||||
"amount": "998.454771147362375",
|
||||
"user": "0x20CD77B9FC2f1fEDfb6F184E25f7127BFE991C8b",
|
||||
@@ -44280,6 +44369,12 @@
|
||||
"tranche_id": 2,
|
||||
"tx": "0x94df9afacf00f3d2a01e8856c83050a2737cd31f7736ae472bfbb3f19e66f5e4"
|
||||
},
|
||||
{
|
||||
"amount": "833.78090076453425",
|
||||
"user": "0x20CD77B9FC2f1fEDfb6F184E25f7127BFE991C8b",
|
||||
"tranche_id": 2,
|
||||
"tx": "0xa56a064890829624fb37f887adb87987dfafd709ebea2cdf423c91a38e91b82f"
|
||||
},
|
||||
{
|
||||
"amount": "998.454771147362375",
|
||||
"user": "0x20CD77B9FC2f1fEDfb6F184E25f7127BFE991C8b",
|
||||
@@ -45716,8 +45811,8 @@
|
||||
}
|
||||
],
|
||||
"total_tokens": "259998.8875",
|
||||
"withdrawn_tokens": "149900.199617162944125",
|
||||
"remaining_tokens": "110098.687882837055875"
|
||||
"withdrawn_tokens": "150733.980517927478375",
|
||||
"remaining_tokens": "109264.906982072521625"
|
||||
},
|
||||
{
|
||||
"address": "0x89051CAb67Bc7F8CC44F7e270c6EDaf1EC57676c",
|
||||
@@ -48068,8 +48163,8 @@
|
||||
"tranche_start": "2021-11-05T00:00:00.000Z",
|
||||
"tranche_end": "2023-05-05T00:00:00.000Z",
|
||||
"total_added": "14597706.0446472999",
|
||||
"total_removed": "5843584.692344376939683626",
|
||||
"locked_amount": "474377.173613587991545219924406688",
|
||||
"total_removed": "5844740.479416869886902626",
|
||||
"locked_amount": "420907.270106923449603004591821117",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "129284.449",
|
||||
@@ -48338,6 +48433,16 @@
|
||||
"user": "0x4Aa3c35F6CC2d507E5C18205ee57099A4C80B19b",
|
||||
"tx": "0x467e16d3f10ba66de4ab7452682f50266a731200be9e036c9b35692e0d447572"
|
||||
},
|
||||
{
|
||||
"amount": "472.655886985174737",
|
||||
"user": "0x4Aa3c35F6CC2d507E5C18205ee57099A4C80B19b",
|
||||
"tx": "0xca4c0571969c50f47990b214485913df8e2b7d1d92cdd6ac4c8bcc6ce760ce0b"
|
||||
},
|
||||
{
|
||||
"amount": "683.131185507772482",
|
||||
"user": "0x4Aa3c35F6CC2d507E5C18205ee57099A4C80B19b",
|
||||
"tx": "0x5cee329248d32efdbd9e7f2b223f1714843a154b530cafd9f5df43a1d45c625b"
|
||||
},
|
||||
{
|
||||
"amount": "37462.74710421168752574",
|
||||
"user": "0x66827bCD635f2bB1779d68c46aEB16541bCA6ba8",
|
||||
@@ -51607,6 +51712,18 @@
|
||||
"tranche_id": 3,
|
||||
"tx": "0x467e16d3f10ba66de4ab7452682f50266a731200be9e036c9b35692e0d447572"
|
||||
},
|
||||
{
|
||||
"amount": "472.655886985174737",
|
||||
"user": "0x4Aa3c35F6CC2d507E5C18205ee57099A4C80B19b",
|
||||
"tranche_id": 3,
|
||||
"tx": "0xca4c0571969c50f47990b214485913df8e2b7d1d92cdd6ac4c8bcc6ce760ce0b"
|
||||
},
|
||||
{
|
||||
"amount": "683.131185507772482",
|
||||
"user": "0x4Aa3c35F6CC2d507E5C18205ee57099A4C80B19b",
|
||||
"tranche_id": 3,
|
||||
"tx": "0x5cee329248d32efdbd9e7f2b223f1714843a154b530cafd9f5df43a1d45c625b"
|
||||
},
|
||||
{
|
||||
"amount": "1383.345213676043696",
|
||||
"user": "0x4Aa3c35F6CC2d507E5C18205ee57099A4C80B19b",
|
||||
@@ -54345,8 +54462,8 @@
|
||||
}
|
||||
],
|
||||
"total_tokens": "359123.469575",
|
||||
"withdrawn_tokens": "347247.868554926171196",
|
||||
"remaining_tokens": "11875.601020073828804"
|
||||
"withdrawn_tokens": "348403.655627419118415",
|
||||
"remaining_tokens": "10719.813947580881585"
|
||||
},
|
||||
{
|
||||
"address": "0xBdd412797c1B78535Afc5F71503b91fAbD0160fB",
|
||||
@@ -57980,8 +58097,8 @@
|
||||
"tranche_start": "2022-06-05T00:00:00.000Z",
|
||||
"tranche_end": "2023-06-05T00:00:00.000Z",
|
||||
"total_added": "472355.6199999996",
|
||||
"total_removed": "43035.7702931331849",
|
||||
"locked_amount": "63079.785842701599708063408828024",
|
||||
"total_removed": "43120.0853616251849",
|
||||
"locked_amount": "60491.61076159115414066601116184",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "3000",
|
||||
@@ -64630,6 +64747,11 @@
|
||||
"user": "0x07d1a589447395fe78bca3627Cb82F7C3310f598",
|
||||
"tx": "0x71bd2cf2152fd2175e3a63a2ba70ffc4db0d8d47c8feb493ae9de59c9164ffcf"
|
||||
},
|
||||
{
|
||||
"amount": "84.315068492",
|
||||
"user": "0x40447e8eDee2F8D0088844E35Ff7aD2Bb5fCabfb",
|
||||
"tx": "0x2aa7bdc96b05e86a7c689062112e932630e7e14b7f05534af1a5d140fc2a88c4"
|
||||
},
|
||||
{
|
||||
"amount": "19.918569252",
|
||||
"user": "0xcB555C5602cC0b2434A27d277e14Cb5C7bF4Ead1",
|
||||
@@ -76227,6 +76349,12 @@
|
||||
}
|
||||
],
|
||||
"withdrawals": [
|
||||
{
|
||||
"amount": "84.315068492",
|
||||
"user": "0x40447e8eDee2F8D0088844E35Ff7aD2Bb5fCabfb",
|
||||
"tranche_id": 5,
|
||||
"tx": "0x2aa7bdc96b05e86a7c689062112e932630e7e14b7f05534af1a5d140fc2a88c4"
|
||||
},
|
||||
{
|
||||
"amount": "89.067954084",
|
||||
"user": "0x40447e8eDee2F8D0088844E35Ff7aD2Bb5fCabfb",
|
||||
@@ -76235,8 +76363,8 @@
|
||||
}
|
||||
],
|
||||
"total_tokens": "200",
|
||||
"withdrawn_tokens": "89.067954084",
|
||||
"remaining_tokens": "110.932045916"
|
||||
"withdrawn_tokens": "173.383022576",
|
||||
"remaining_tokens": "26.616977424"
|
||||
},
|
||||
{
|
||||
"address": "0x1bAc2912394A42Cec87767327FC039f2EfBB95Dd",
|
||||
@@ -143172,6 +143300,11 @@
|
||||
"user": "0x759C9ABABA492500c4c730bEB568B5b851Dec2c7",
|
||||
"tx": "0xf4cdc0b0f6c24cb52dd0126bc6bff9c75ec715502809f9c80d675327beb4889d"
|
||||
},
|
||||
{
|
||||
"amount": "0",
|
||||
"user": "0x759C9ABABA492500c4c730bEB568B5b851Dec2c7",
|
||||
"tx": "0x11aafa8a2fb510a50d52e5d1e149c5c2027ad2c3dc2d9ef67c18d391c0331c49"
|
||||
},
|
||||
{
|
||||
"amount": "0",
|
||||
"user": "0x759C9ABABA492500c4c730bEB568B5b851Dec2c7",
|
||||
@@ -143454,6 +143587,12 @@
|
||||
"tranche_id": 9,
|
||||
"tx": "0xf4cdc0b0f6c24cb52dd0126bc6bff9c75ec715502809f9c80d675327beb4889d"
|
||||
},
|
||||
{
|
||||
"amount": "0",
|
||||
"user": "0x759C9ABABA492500c4c730bEB568B5b851Dec2c7",
|
||||
"tranche_id": 9,
|
||||
"tx": "0x11aafa8a2fb510a50d52e5d1e149c5c2027ad2c3dc2d9ef67c18d391c0331c49"
|
||||
},
|
||||
{
|
||||
"amount": "0",
|
||||
"user": "0x759C9ABABA492500c4c730bEB568B5b851Dec2c7",
|
||||
|
||||
@@ -29,7 +29,10 @@ import { LiquidityContainer } from '../liquidity/liquidity';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import type { PinnedAsset } from '@vegaprotocol/accounts';
|
||||
import { useScreenDimensions } from '@vegaprotocol/react-helpers';
|
||||
import { useMarketClickHandler } from '../../lib/hooks/use-market-click-handler';
|
||||
import {
|
||||
useMarketClickHandler,
|
||||
useMarketLiquidityClickHandler,
|
||||
} from '../../lib/hooks/use-market-click-handler';
|
||||
|
||||
type MarketDependantView =
|
||||
| typeof CandlesChartContainer
|
||||
@@ -79,6 +82,7 @@ const MarketBottomPanel = memo(
|
||||
({ marketId, pinnedAsset }: BottomPanelProps) => {
|
||||
const { screenSize } = useScreenDimensions();
|
||||
const onMarketClick = useMarketClickHandler(true);
|
||||
const onOrderTypeClick = useMarketLiquidityClickHandler(true);
|
||||
|
||||
return 'xxxl' === screenSize ? (
|
||||
<ResizableGrid proportionalLayout minSize={200}>
|
||||
@@ -94,6 +98,7 @@ const MarketBottomPanel = memo(
|
||||
<TradingViews.Orders
|
||||
marketId={marketId}
|
||||
onMarketClick={onMarketClick}
|
||||
onOrderTypeClick={onOrderTypeClick}
|
||||
enforceBottomPlaceholder
|
||||
/>
|
||||
</VegaWalletContainer>
|
||||
@@ -150,6 +155,7 @@ const MarketBottomPanel = memo(
|
||||
<TradingViews.Orders
|
||||
marketId={marketId}
|
||||
onMarketClick={onMarketClick}
|
||||
onOrderTypeClick={onOrderTypeClick}
|
||||
enforceBottomPlaceholder
|
||||
/>
|
||||
</VegaWalletContainer>
|
||||
@@ -293,6 +299,7 @@ interface TradePanelsProps {
|
||||
market: Market | null;
|
||||
onSelect: (marketId: string, metaKey?: boolean) => void;
|
||||
onMarketClick?: (marketId: string) => void;
|
||||
onOrderTypeClick?: (marketId: string) => void;
|
||||
onClickCollateral: () => void;
|
||||
pinnedAsset?: PinnedAsset;
|
||||
}
|
||||
@@ -303,12 +310,16 @@ export const TradePanels = ({
|
||||
onClickCollateral,
|
||||
pinnedAsset,
|
||||
}: TradePanelsProps) => {
|
||||
const onMarketClick = useMarketClickHandler(true);
|
||||
const onOrderTypeClick = useMarketLiquidityClickHandler(true);
|
||||
|
||||
const [view, setView] = useState<TradingView>('Candles');
|
||||
const renderView = () => {
|
||||
const Component = memo<{
|
||||
marketId: string;
|
||||
onSelect: (marketId: string, metaKey?: boolean) => void;
|
||||
onMarketClick?: (marketId: string) => void;
|
||||
onOrderTypeClick?: (marketId: string) => void;
|
||||
onClickCollateral: () => void;
|
||||
pinnedAsset?: PinnedAsset;
|
||||
}>(TradingViews[view]);
|
||||
@@ -325,6 +336,8 @@ export const TradePanels = ({
|
||||
onSelect={onSelect}
|
||||
onClickCollateral={onClickCollateral}
|
||||
pinnedAsset={pinnedAsset}
|
||||
onMarketClick={onMarketClick}
|
||||
onOrderTypeClick={onOrderTypeClick}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -19,7 +19,10 @@ import { usePageTitleStore } from '../../stores';
|
||||
import { LedgerContainer } from '@vegaprotocol/ledger';
|
||||
import { AccountsContainer } from '../../components/accounts-container';
|
||||
import { AccountHistoryContainer } from './account-history-container';
|
||||
import { useMarketClickHandler } from '../../lib/hooks/use-market-click-handler';
|
||||
import {
|
||||
useMarketClickHandler,
|
||||
useMarketLiquidityClickHandler,
|
||||
} from '../../lib/hooks/use-market-click-handler';
|
||||
|
||||
export const Portfolio = () => {
|
||||
const { updateTitle } = usePageTitleStore((store) => ({
|
||||
@@ -31,6 +34,7 @@ export const Portfolio = () => {
|
||||
}, [updateTitle]);
|
||||
|
||||
const onMarketClick = useMarketClickHandler(true);
|
||||
const onOrderTypeClick = useMarketLiquidityClickHandler(true);
|
||||
|
||||
const wrapperClasses = 'h-full max-h-full flex flex-col';
|
||||
return (
|
||||
@@ -54,7 +58,10 @@ export const Portfolio = () => {
|
||||
</Tab>
|
||||
<Tab id="orders" name={t('Orders')}>
|
||||
<VegaWalletContainer>
|
||||
<OrderListContainer onMarketClick={onMarketClick} />
|
||||
<OrderListContainer
|
||||
onMarketClick={onMarketClick}
|
||||
onOrderTypeClick={onOrderTypeClick}
|
||||
/>
|
||||
</VegaWalletContainer>
|
||||
</Tab>
|
||||
<Tab id="fills" name={t('Fills')}>
|
||||
|
||||
@@ -19,3 +19,21 @@ export const useMarketClickHandler = (replace = false) => {
|
||||
[navigate, marketId, replace, isMarketPage]
|
||||
);
|
||||
};
|
||||
|
||||
export const useMarketLiquidityClickHandler = (replace = false) => {
|
||||
const navigate = useNavigate();
|
||||
const { marketId } = useParams();
|
||||
const { pathname } = useLocation();
|
||||
const isLiquidityPage = pathname.match(/^\/liquidity\/(.+)/);
|
||||
return useCallback(
|
||||
(selectedId: string, metaKey?: boolean) => {
|
||||
const link = Links[Routes.LIQUIDITY](selectedId);
|
||||
if (metaKey) {
|
||||
window.open(`/#${link}`, '_blank');
|
||||
} else if (selectedId !== marketId || !isLiquidityPage) {
|
||||
navigate(link, { replace });
|
||||
}
|
||||
},
|
||||
[navigate, marketId, replace, isLiquidityPage]
|
||||
);
|
||||
};
|
||||
|
||||
@@ -33,6 +33,8 @@ import { ViewingBanner } from '../components/viewing-banner';
|
||||
import { Banner } from '../components/banner';
|
||||
import { AppLoader, DynamicLoader } from '../components/app-loader';
|
||||
import { Navbar } from '../components/navbar';
|
||||
import { useDataProvider } from '@vegaprotocol/react-helpers';
|
||||
import { activeOrdersProvider } from '@vegaprotocol/orders';
|
||||
|
||||
const DEFAULT_TITLE = t('Welcome to Vega trading!');
|
||||
|
||||
@@ -95,6 +97,7 @@ function AppBody({ Component }: AppProps) {
|
||||
<ToastsManager />
|
||||
<InitializeHandlers />
|
||||
<MaybeConnectEagerly />
|
||||
<PartyData />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -127,6 +130,18 @@ function VegaTradingApp(props: AppProps) {
|
||||
|
||||
export default VegaTradingApp;
|
||||
|
||||
const PartyData = () => {
|
||||
const { pubKey } = useVegaWallet();
|
||||
const variables = { partyId: pubKey || '' };
|
||||
const skip = !pubKey;
|
||||
useDataProvider({
|
||||
dataProvider: activeOrdersProvider,
|
||||
variables,
|
||||
skip,
|
||||
});
|
||||
return null;
|
||||
};
|
||||
|
||||
const MaybeConnectEagerly = () => {
|
||||
useVegaEagerConnect(Connectors);
|
||||
useEthereumEagerConnect();
|
||||
|
||||
@@ -31,7 +31,7 @@ export enum Routes {
|
||||
MARKET = '/markets',
|
||||
MARKETS = '/markets/all',
|
||||
PORTFOLIO = '/portfolio',
|
||||
LIQUIDITY = 'liquidity/:marketId',
|
||||
LIQUIDITY = '/liquidity',
|
||||
}
|
||||
|
||||
type ConsoleLinks = { [r in Routes]: (...args: string[]) => string };
|
||||
@@ -41,8 +41,10 @@ export const Links: ConsoleLinks = {
|
||||
marketId ? trimEnd(`${Routes.MARKET}/${marketId}`, '/') : Routes.MARKET,
|
||||
[Routes.MARKETS]: () => Routes.MARKETS,
|
||||
[Routes.PORTFOLIO]: () => Routes.PORTFOLIO,
|
||||
[Routes.LIQUIDITY]: (marketId: string) =>
|
||||
Routes.LIQUIDITY.replace(':marketId', marketId),
|
||||
[Routes.LIQUIDITY]: (marketId: string | null | undefined) =>
|
||||
marketId
|
||||
? trimEnd(`${Routes.LIQUIDITY}/${marketId}`, '/')
|
||||
: Routes.LIQUIDITY,
|
||||
};
|
||||
|
||||
const routerConfig: RouteObject[] = [
|
||||
@@ -70,6 +72,16 @@ const routerConfig: RouteObject[] = [
|
||||
{
|
||||
path: Routes.LIQUIDITY,
|
||||
element: <LazyLiquidity />,
|
||||
children: [
|
||||
{
|
||||
index: true,
|
||||
element: <LazyLiquidity />,
|
||||
},
|
||||
{
|
||||
path: ':marketId',
|
||||
element: <LazyLiquidity />,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: Routes.PORTFOLIO,
|
||||
|
||||
@@ -10,6 +10,7 @@ export * from './lib/cells/price-flash-cell';
|
||||
export * from './lib/cells/vol-cell';
|
||||
export * from './lib/cells/centered-grid-cell';
|
||||
export * from './lib/cells/market-name-cell';
|
||||
export * from './lib/cells/order-type-cell';
|
||||
|
||||
export * from './lib/filters/date-range-filter';
|
||||
export * from './lib/filters/set-filter';
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import type { MouseEvent } from 'react';
|
||||
import { useMemo } from 'react';
|
||||
import { useCallback } from 'react';
|
||||
import { t } from '@vegaprotocol/i18n';
|
||||
import * as Schema from '@vegaprotocol/types';
|
||||
|
||||
interface OrderTypeCellProps {
|
||||
value?: Schema.OrderType;
|
||||
data?: Schema.Order;
|
||||
onClick?: (marketId: string, metaKey?: boolean) => void;
|
||||
}
|
||||
|
||||
export const OrderTypeCell = ({
|
||||
value,
|
||||
data: order,
|
||||
onClick,
|
||||
}: OrderTypeCellProps) => {
|
||||
const id = order ? order.market.id : '';
|
||||
|
||||
const label = useMemo(() => {
|
||||
if (!order) {
|
||||
return undefined;
|
||||
}
|
||||
if (!value) return '-';
|
||||
if (order?.peggedOrder) {
|
||||
return t('Pegged');
|
||||
}
|
||||
if (order?.liquidityProvision) {
|
||||
return t('Liquidity provision');
|
||||
}
|
||||
return Schema.OrderTypeMapping[value];
|
||||
}, [order, value]);
|
||||
|
||||
const handleOnClick = useCallback(
|
||||
(ev: MouseEvent<HTMLButtonElement>) => {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
if (onClick) {
|
||||
onClick(id, ev.metaKey || ev.ctrlKey);
|
||||
}
|
||||
},
|
||||
[id, onClick]
|
||||
);
|
||||
if (!order) return null;
|
||||
return order?.liquidityProvision ? (
|
||||
<button onClick={handleOnClick} tabIndex={0} className="underline">
|
||||
{label}
|
||||
</button>
|
||||
) : (
|
||||
<span>{label}</span>
|
||||
);
|
||||
};
|
||||
@@ -8,7 +8,7 @@ const commonProps = {
|
||||
|
||||
describe('DateRangeFilter', () => {
|
||||
it('should be properly rendered', async () => {
|
||||
const defaultRangeFilter = {
|
||||
const defaultValue = {
|
||||
start: '2023-02-14T13:53:01+01:00',
|
||||
end: '2023-02-21T13:53:01+01:00',
|
||||
};
|
||||
@@ -17,7 +17,7 @@ describe('DateRangeFilter', () => {
|
||||
render(
|
||||
<DateRangeFilter
|
||||
{...(commonProps as unknown as DateRangeFilterProps)}
|
||||
defaultRangeFilter={defaultRangeFilter}
|
||||
defaultValue={defaultValue}
|
||||
/>
|
||||
);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { ChangeEvent } from 'react';
|
||||
import { useEffect, useMemo } from 'react';
|
||||
import { useEffect, useMemo, useRef } from 'react';
|
||||
import type * as Schema from '@vegaprotocol/types';
|
||||
import { forwardRef, useImperativeHandle, useState } from 'react';
|
||||
import type { IDoesFilterPassParams, IFilterParams } from 'ag-grid-community';
|
||||
@@ -17,9 +17,9 @@ import { formatForInput } from '@vegaprotocol/utils';
|
||||
import { t } from '@vegaprotocol/i18n';
|
||||
import { InputError } from '@vegaprotocol/ui-toolkit';
|
||||
|
||||
const defaultFilterValue: Schema.DateRange = {};
|
||||
const defaultValue: Schema.DateRange = {};
|
||||
export interface DateRangeFilterProps extends IFilterParams {
|
||||
defaultRangeFilter?: Schema.DateRange;
|
||||
defaultValue?: Schema.DateRange;
|
||||
maxSubDays?: number;
|
||||
maxNextDays?: number;
|
||||
maxDaysRange?: number;
|
||||
@@ -27,8 +27,9 @@ export interface DateRangeFilterProps extends IFilterParams {
|
||||
|
||||
export const DateRangeFilter = forwardRef(
|
||||
(props: DateRangeFilterProps, ref) => {
|
||||
const defaultDates = props?.defaultRangeFilter || defaultFilterValue;
|
||||
const defaultDates = props?.defaultValue || defaultValue;
|
||||
const [value, setValue] = useState<Schema.DateRange>(defaultDates);
|
||||
const valueRef = useRef<Schema.DateRange>(value);
|
||||
const [error, setError] = useState<string>('');
|
||||
const [minStartDate, maxStartDate, minEndDate, maxEndDate] = useMemo(() => {
|
||||
const minStartDate =
|
||||
@@ -93,7 +94,7 @@ export const DateRangeFilter = forwardRef(
|
||||
},
|
||||
|
||||
isFilterActive() {
|
||||
return value.start || value.end;
|
||||
return valueRef.current.start || valueRef.current.end;
|
||||
},
|
||||
|
||||
getModel() {
|
||||
@@ -101,13 +102,13 @@ export const DateRangeFilter = forwardRef(
|
||||
return null;
|
||||
}
|
||||
|
||||
return { value };
|
||||
return { value: valueRef.current };
|
||||
},
|
||||
|
||||
setModel(model?: { value: Schema.DateRange } | null) {
|
||||
setValue(
|
||||
model?.value || props?.defaultRangeFilter || defaultFilterValue
|
||||
);
|
||||
valueRef.current =
|
||||
model?.value || props?.defaultValue || defaultValue;
|
||||
setValue(valueRef.current);
|
||||
},
|
||||
};
|
||||
});
|
||||
@@ -185,10 +186,8 @@ export const DateRangeFilter = forwardRef(
|
||||
update = { ...update, end: checkForEndDate(endDate, startDate) };
|
||||
|
||||
if (validate(name, date, update)) {
|
||||
setValue((curr) => ({
|
||||
...curr,
|
||||
...update,
|
||||
}));
|
||||
valueRef.current = { ...valueRef.current, ...update };
|
||||
setValue(valueRef.current);
|
||||
}
|
||||
};
|
||||
useEffect(() => {
|
||||
@@ -241,7 +240,8 @@ export const DateRangeFilter = forwardRef(
|
||||
className="ag-standard-button ag-filter-apply-panel-button"
|
||||
onClick={() => {
|
||||
setError('');
|
||||
setValue(defaultDates);
|
||||
valueRef.current = defaultDates;
|
||||
setValue(valueRef.current);
|
||||
}}
|
||||
>
|
||||
{t('Reset')}
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
import type { ChangeEvent } from 'react';
|
||||
import { forwardRef, useEffect, useImperativeHandle, useState } from 'react';
|
||||
import {
|
||||
forwardRef,
|
||||
useEffect,
|
||||
useImperativeHandle,
|
||||
useState,
|
||||
useRef,
|
||||
} from 'react';
|
||||
import type { IDoesFilterPassParams, IFilterParams } from 'ag-grid-community';
|
||||
import { t } from '@vegaprotocol/i18n';
|
||||
|
||||
export const SetFilter = forwardRef((props: IFilterParams, ref) => {
|
||||
const [value, setValue] = useState<string[]>([]);
|
||||
const valueRef = useRef(value);
|
||||
|
||||
// expose AG Grid Filter Lifecycle callbacks
|
||||
useImperativeHandle(ref, () => {
|
||||
@@ -28,29 +35,28 @@ export const SetFilter = forwardRef((props: IFilterParams, ref) => {
|
||||
},
|
||||
|
||||
isFilterActive() {
|
||||
return value.length !== 0;
|
||||
return valueRef.current.length !== 0;
|
||||
},
|
||||
|
||||
getModel() {
|
||||
if (!this.isFilterActive()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return { value };
|
||||
return { value: valueRef.current };
|
||||
},
|
||||
|
||||
setModel(model?: { value: string[] } | null) {
|
||||
setValue(!model ? [] : model.value);
|
||||
valueRef.current = !model ? [] : model.value;
|
||||
setValue(valueRef.current);
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
const onChange = (event: ChangeEvent<HTMLInputElement>) => {
|
||||
setValue(
|
||||
event.target.checked
|
||||
? [...value, event.target.value]
|
||||
: value.filter((v) => v !== event.target.value)
|
||||
);
|
||||
valueRef.current = event.target.checked
|
||||
? [...value, event.target.value]
|
||||
: value.filter((v) => v !== event.target.value);
|
||||
setValue(valueRef.current);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
@@ -77,7 +83,7 @@ export const SetFilter = forwardRef((props: IFilterParams, ref) => {
|
||||
<button
|
||||
type="button"
|
||||
className="ag-standard-button ag-filter-apply-panel-button"
|
||||
onClick={() => setValue([])}
|
||||
onClick={() => setValue((valueRef.current = []))}
|
||||
>
|
||||
{t('Reset')}
|
||||
</button>
|
||||
|
||||
@@ -15,8 +15,8 @@ export const useInitialMargin = (
|
||||
marketId: OrderSubmissionBody['orderSubmission']['marketId'],
|
||||
order?: OrderSubmissionBody['orderSubmission']
|
||||
) => {
|
||||
const { pubKey: partyId } = useVegaWallet();
|
||||
const commonVariables = { marketId, partyId: partyId || '' };
|
||||
const { pubKey } = useVegaWallet();
|
||||
const commonVariables = { marketId, partyId: pubKey || '' };
|
||||
const { data: marketData } = useDataProvider({
|
||||
dataProvider: marketDataProvider,
|
||||
variables: { marketId },
|
||||
@@ -24,7 +24,7 @@ export const useInitialMargin = (
|
||||
const { data: activeVolumeAndMargin } = useDataProvider({
|
||||
dataProvider: volumeAndMarginProvider,
|
||||
variables: commonVariables,
|
||||
skip: !partyId,
|
||||
skip: !pubKey,
|
||||
});
|
||||
const { data: marketInfo } = useDataProvider({
|
||||
dataProvider: marketInfoProvider,
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
export * from './use-environment';
|
||||
export * from './use-links';
|
||||
export * from './use-node-health';
|
||||
export * from './use-vega-releases';
|
||||
export * from './use-vega-release';
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,41 +0,0 @@
|
||||
import { renderHook, waitFor } from '@testing-library/react';
|
||||
import fetchMock from 'fetch-mock';
|
||||
import {
|
||||
GITHUB_VEGA_DEV_RELEASES,
|
||||
GITHUB_VEGA_RELEASES,
|
||||
} from './use-vega-releases';
|
||||
import {
|
||||
GITHUB_VEGA_RELEASES_DATA,
|
||||
GITHUB_VEGA_DEV_RELEASES_DATA,
|
||||
} from './mocks/github-releases';
|
||||
import { useVegaRelease } from './use-vega-release';
|
||||
|
||||
describe('useVegaRelease', () => {
|
||||
beforeEach(() => {
|
||||
fetchMock.get(GITHUB_VEGA_RELEASES, GITHUB_VEGA_RELEASES_DATA);
|
||||
fetchMock.get(GITHUB_VEGA_DEV_RELEASES, GITHUB_VEGA_DEV_RELEASES_DATA);
|
||||
});
|
||||
afterEach(() => {
|
||||
fetchMock.reset();
|
||||
});
|
||||
|
||||
it('should return release information by given tag', async () => {
|
||||
const { result } = renderHook(() => useVegaRelease('v0.70.1'));
|
||||
await waitFor(() => {
|
||||
expect(result.current).toBeTruthy();
|
||||
expect(result.current?.tagName).toEqual('v0.70.1');
|
||||
expect(result.current?.htmlUrl).toEqual(
|
||||
'https://github.com/vegaprotocol/vega/releases/tag/v0.70.1'
|
||||
);
|
||||
expect(result.current?.name).toEqual('v0.70.1');
|
||||
expect(result.current?.isDraft).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return undefined when a release cannot be found', async () => {
|
||||
const { result } = renderHook(() => useVegaRelease('v0.70.1'));
|
||||
await waitFor(() => {
|
||||
expect(result.current).toEqual(undefined);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,9 +0,0 @@
|
||||
import { useMemo } from 'react';
|
||||
import { useVegaReleases } from './use-vega-releases';
|
||||
|
||||
export const useVegaRelease = (tag: string, includeDevReleases = false) => {
|
||||
const { data } = useVegaReleases();
|
||||
return useMemo(() => {
|
||||
return data?.find((r) => r.tagName === tag);
|
||||
}, [data, tag]);
|
||||
};
|
||||
@@ -1,58 +0,0 @@
|
||||
import { renderHook, waitFor } from '@testing-library/react';
|
||||
import fetchMock from 'fetch-mock';
|
||||
import {
|
||||
GITHUB_VEGA_DEV_RELEASES,
|
||||
GITHUB_VEGA_RELEASES,
|
||||
useVegaReleases,
|
||||
} from './use-vega-releases';
|
||||
import {
|
||||
GITHUB_VEGA_RELEASES_DATA,
|
||||
GITHUB_VEGA_DEV_RELEASES_DATA,
|
||||
} from './mocks/github-releases';
|
||||
|
||||
describe('useVegaReleases', () => {
|
||||
afterEach(() => {
|
||||
fetchMock.reset();
|
||||
});
|
||||
|
||||
it('should return an empty list when request is unsuccessful', async () => {
|
||||
fetchMock.get(GITHUB_VEGA_RELEASES, 404);
|
||||
fetchMock.get(GITHUB_VEGA_DEV_RELEASES, 404);
|
||||
|
||||
const { result } = renderHook(() => useVegaReleases());
|
||||
expect(result.current.loading).toBeTruthy();
|
||||
await waitFor(() => {
|
||||
expect(result.current.loading).toBeFalsy();
|
||||
expect(result.current.data).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return a list of releases', async () => {
|
||||
fetchMock.get(GITHUB_VEGA_RELEASES, GITHUB_VEGA_RELEASES_DATA);
|
||||
fetchMock.get(GITHUB_VEGA_DEV_RELEASES, GITHUB_VEGA_DEV_RELEASES_DATA);
|
||||
|
||||
const { result } = renderHook(() => useVegaReleases());
|
||||
expect(result.current.loading).toBeTruthy();
|
||||
await waitFor(() => {
|
||||
expect(result.current.loading).toBeFalsy();
|
||||
expect(result.current).not.toEqual([]);
|
||||
const data = result.current.data;
|
||||
expect(data?.[0].tagName).toEqual('v0.70.3');
|
||||
expect(data?.[0].htmlUrl).toEqual(
|
||||
'https://github.com/vegaprotocol/vega/releases/tag/v0.70.3'
|
||||
);
|
||||
expect(data?.[1].tagName).toEqual('v0.70.2');
|
||||
expect(data?.[2].tagName).toEqual('v0.70.1');
|
||||
});
|
||||
});
|
||||
|
||||
it('should return a list of releases including dev releases', async () => {
|
||||
fetchMock.get(GITHUB_VEGA_RELEASES, GITHUB_VEGA_RELEASES_DATA);
|
||||
fetchMock.get(GITHUB_VEGA_DEV_RELEASES, GITHUB_VEGA_DEV_RELEASES_DATA);
|
||||
const { result } = renderHook(() => useVegaReleases(true));
|
||||
await waitFor(() => {
|
||||
expect(result.current.data?.length).toBeGreaterThan(30);
|
||||
expect(fetchMock.calls().length).toEqual(2);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,124 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import z from 'zod';
|
||||
|
||||
export const GITHUB_VEGA_RELEASES =
|
||||
'https://api.github.com/repos/vegaprotocol/vega/releases';
|
||||
export const GITHUB_VEGA_DEV_RELEASES =
|
||||
'https://api.github.com/repos/vegaprotocol/vega-dev-releases/releases';
|
||||
|
||||
const GithubReleaseSchema = z.object({
|
||||
url: z.string(),
|
||||
html_url: z.string(),
|
||||
id: z.number(),
|
||||
tag_name: z.string(),
|
||||
name: z.string().nullable(),
|
||||
draft: z.boolean(),
|
||||
created_at: z.string().datetime(),
|
||||
});
|
||||
|
||||
const GithubReleasesSchema = z.array(GithubReleaseSchema);
|
||||
|
||||
type ReleaseInfo = {
|
||||
id: number;
|
||||
name: string;
|
||||
tagName: string;
|
||||
htmlUrl: string;
|
||||
url: string;
|
||||
isDraft: boolean;
|
||||
createdAt: Date;
|
||||
isDevRelease: boolean;
|
||||
};
|
||||
|
||||
const toReleaseInfo = (
|
||||
releaseData: z.infer<typeof GithubReleaseSchema>,
|
||||
isDevRelease: boolean
|
||||
): ReleaseInfo => ({
|
||||
id: releaseData.id,
|
||||
name: releaseData.name || '',
|
||||
tagName: releaseData.tag_name,
|
||||
htmlUrl: releaseData.html_url,
|
||||
url: releaseData.url,
|
||||
isDraft: releaseData.draft,
|
||||
createdAt: new Date(releaseData.created_at),
|
||||
isDevRelease,
|
||||
});
|
||||
|
||||
enum ReleaseFeed {
|
||||
// @ts-ignore TS18033 - allowed in 5.0
|
||||
Vega = GITHUB_VEGA_RELEASES,
|
||||
// @ts-ignore TS18033
|
||||
VegaDev = GITHUB_VEGA_DEV_RELEASES,
|
||||
}
|
||||
|
||||
const fetchReleases = async (feed: ReleaseFeed) => {
|
||||
const response = await fetch(String(feed), {
|
||||
cache: 'force-cache',
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const json = await response.json();
|
||||
const data = GithubReleasesSchema.parse(json);
|
||||
return data.map((d) => toReleaseInfo(d, feed === ReleaseFeed.VegaDev));
|
||||
}
|
||||
|
||||
return [];
|
||||
};
|
||||
|
||||
type State = {
|
||||
loading: boolean;
|
||||
data: ReleaseInfo[] | null;
|
||||
error: Error | null | undefined;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves a list of vega releases from github.
|
||||
* First element is the newest.
|
||||
*/
|
||||
export const useVegaReleases = (includeDevReleases = false) => {
|
||||
const [state, setState] = useState<State>({
|
||||
loading: true,
|
||||
data: null,
|
||||
error: null,
|
||||
});
|
||||
|
||||
const fetchData = useCallback(() => {
|
||||
let mounted = true;
|
||||
|
||||
Promise.all(
|
||||
includeDevReleases
|
||||
? [fetchReleases(ReleaseFeed.Vega), fetchReleases(ReleaseFeed.VegaDev)]
|
||||
: [fetchReleases(ReleaseFeed.Vega)]
|
||||
)
|
||||
.then(([vega, vegaDev]) => {
|
||||
if (mounted) {
|
||||
setState({
|
||||
loading: false,
|
||||
data: (vegaDev ? vega.concat(vegaDev) : vega).sort(
|
||||
(a, b) => b.createdAt.valueOf() - a.createdAt.valueOf()
|
||||
),
|
||||
error: null,
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
if (mounted) {
|
||||
setState({
|
||||
loading: false,
|
||||
data: null,
|
||||
error: err,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return () => {
|
||||
mounted = false;
|
||||
};
|
||||
}, [includeDevReleases, setState]);
|
||||
|
||||
useEffect(() => {
|
||||
fetchData();
|
||||
}, [fetchData]);
|
||||
|
||||
return state;
|
||||
};
|
||||
@@ -120,6 +120,40 @@ describe('FillsTable', () => {
|
||||
expect(amountCell).toHaveClass('text-vega-pink');
|
||||
});
|
||||
|
||||
it('should format cells correctly for side unspecified', async () => {
|
||||
const partyId = 'party-id';
|
||||
const buyerFill = generateFill({
|
||||
...defaultFill,
|
||||
seller: {
|
||||
id: partyId,
|
||||
},
|
||||
aggressor: Schema.Side.SIDE_UNSPECIFIED,
|
||||
sellerFee: {
|
||||
makerFee: '1',
|
||||
infrastructureFee: '1',
|
||||
liquidityFee: '1',
|
||||
},
|
||||
});
|
||||
render(<FillsTable partyId={partyId} rowData={[buyerFill]} />);
|
||||
|
||||
const cells = screen.getAllByRole('gridcell');
|
||||
const expectedValues = [
|
||||
buyerFill.market?.tradableInstrument.instrument.name || '',
|
||||
'-3.00',
|
||||
'1.00 BTC',
|
||||
'3.00 BTC',
|
||||
'-',
|
||||
'0.03 BTC',
|
||||
getDateTimeFormat().format(new Date(buyerFill.createdAt)),
|
||||
];
|
||||
cells.forEach((cell, i) => {
|
||||
expect(cell).toHaveTextContent(expectedValues[i]);
|
||||
});
|
||||
|
||||
const amountCell = cells.find((c) => c.getAttribute('col-id') === 'size');
|
||||
expect(amountCell).toHaveClass('text-vega-pink');
|
||||
});
|
||||
|
||||
it('should render correct maker or taker role', async () => {
|
||||
const partyId = 'party-id';
|
||||
const takerFill = generateFill({
|
||||
@@ -190,7 +224,7 @@ describe('FillsTable', () => {
|
||||
makerFee: '1000',
|
||||
totalFee: '6000',
|
||||
};
|
||||
expect(getFeesBreakdown('TAKER', fees)).toEqual(expectedBreakdown);
|
||||
expect(getFeesBreakdown('Taker', fees)).toEqual(expectedBreakdown);
|
||||
});
|
||||
|
||||
it('should return correct fees breakdown for a maker', () => {
|
||||
@@ -205,7 +239,7 @@ describe('FillsTable', () => {
|
||||
makerFee: '-1000',
|
||||
totalFee: '4000',
|
||||
};
|
||||
expect(getFeesBreakdown('MAKER', fees)).toEqual(expectedBreakdown);
|
||||
expect(getFeesBreakdown('Maker', fees)).toEqual(expectedBreakdown);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -26,8 +26,10 @@ import BigNumber from 'bignumber.js';
|
||||
import type { Trade } from './fills-data-provider';
|
||||
import type { FillFieldsFragment } from './__generated__/Fills';
|
||||
|
||||
const TAKER = 'TAKER';
|
||||
const MAKER = 'MAKER';
|
||||
const TAKER = 'Taker';
|
||||
const MAKER = 'Maker';
|
||||
|
||||
export type Role = typeof TAKER | typeof MAKER | '-';
|
||||
|
||||
export type Props = (AgGridReactProps | AgReactUiProps) & {
|
||||
partyId: string;
|
||||
@@ -180,24 +182,10 @@ const formatTotal = ({
|
||||
};
|
||||
|
||||
const formatRole = (partyId: string) => {
|
||||
return ({ value, data }: VegaValueFormatterParams<Trade, 'aggressor'>) => {
|
||||
const taker = t('Taker');
|
||||
const maker = t('Maker');
|
||||
if (data?.buyer.id === partyId) {
|
||||
if (value === Schema.Side.SIDE_BUY) {
|
||||
return taker;
|
||||
} else {
|
||||
return maker;
|
||||
}
|
||||
} else if (data?.seller.id === partyId) {
|
||||
if (value === Schema.Side.SIDE_SELL) {
|
||||
return taker;
|
||||
} else {
|
||||
return maker;
|
||||
}
|
||||
} else {
|
||||
return '-';
|
||||
}
|
||||
return ({ data }: VegaValueFormatterParams<Trade, 'aggressor'>) => {
|
||||
if (!data) return '-';
|
||||
const { role } = getRoleAndFees({ data, partyId });
|
||||
return role;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -222,6 +210,15 @@ const formatFee = (partyId: string) => {
|
||||
};
|
||||
};
|
||||
|
||||
export const isEmptyFeeObj = (feeObj: Schema.TradeFee) => {
|
||||
if (!feeObj) return true;
|
||||
return (
|
||||
feeObj.liquidityFee === '0' &&
|
||||
feeObj.makerFee === '0' &&
|
||||
feeObj.infrastructureFee === '0'
|
||||
);
|
||||
};
|
||||
|
||||
export const getRoleAndFees = ({
|
||||
data,
|
||||
partyId,
|
||||
@@ -232,14 +229,30 @@ export const getRoleAndFees = ({
|
||||
>;
|
||||
partyId?: string;
|
||||
}) => {
|
||||
let role;
|
||||
let role: Role;
|
||||
let feesObj;
|
||||
if (data?.buyer.id === partyId) {
|
||||
role = data.aggressor === Schema.Side.SIDE_BUY ? TAKER : MAKER;
|
||||
feesObj = role === TAKER ? data?.buyerFee : data.sellerFee;
|
||||
if (data.aggressor === Schema.Side.SIDE_BUY) {
|
||||
role = TAKER;
|
||||
feesObj = data?.buyerFee;
|
||||
} else if (data.aggressor === Schema.Side.SIDE_SELL) {
|
||||
role = MAKER;
|
||||
feesObj = data?.sellerFee;
|
||||
} else {
|
||||
role = '-';
|
||||
feesObj = !isEmptyFeeObj(data?.buyerFee) ? data.buyerFee : data.sellerFee;
|
||||
}
|
||||
} else if (data?.seller.id === partyId) {
|
||||
role = data.aggressor === Schema.Side.SIDE_SELL ? TAKER : MAKER;
|
||||
feesObj = role === TAKER ? data?.sellerFee : data.buyerFee;
|
||||
if (data.aggressor === Schema.Side.SIDE_SELL) {
|
||||
role = TAKER;
|
||||
feesObj = data?.sellerFee;
|
||||
} else if (data.aggressor === Schema.Side.SIDE_BUY) {
|
||||
role = MAKER;
|
||||
feesObj = data?.buyerFee;
|
||||
} else {
|
||||
role = '-';
|
||||
feesObj = !isEmptyFeeObj(data.sellerFee) ? data.sellerFee : data.buyerFee;
|
||||
}
|
||||
} else {
|
||||
return { role: '-', feesObj: '-' };
|
||||
}
|
||||
@@ -270,11 +283,6 @@ const FeesBreakdownTooltip = ({
|
||||
{role === MAKER && (
|
||||
<>
|
||||
<p className="mb-1">{t('The maker will receive the maker fee.')}</p>
|
||||
<p className="mb-1">
|
||||
{t(
|
||||
'If the market is in monitoring auction the maker will pay half of the infrastructure and liquidity fees.'
|
||||
)}
|
||||
</p>
|
||||
<p className="mb-1">
|
||||
{t(
|
||||
'If the market is active the maker will pay zero infrastructure and liquidity fees.'
|
||||
@@ -283,14 +291,14 @@ const FeesBreakdownTooltip = ({
|
||||
</>
|
||||
)}
|
||||
{role === TAKER && (
|
||||
<>
|
||||
<p className="mb-1">{t('Fees to be paid by the taker.')}</p>
|
||||
<p className="mb-1">
|
||||
{t(
|
||||
'If the market is in monitoring auction the taker will pay half of the infrastructure and liquidity fees.'
|
||||
)}
|
||||
</p>
|
||||
</>
|
||||
<p className="mb-1">{t('Fees to be paid by the taker.')}</p>
|
||||
)}
|
||||
{role === '-' && (
|
||||
<p className="mb-1">
|
||||
{t(
|
||||
'If the market is in monitoring auction, half of the infrastructure and liquidity fees will be paid.'
|
||||
)}
|
||||
</p>
|
||||
)}
|
||||
<dl className="grid grid-cols-2 gap-x-1">
|
||||
<dt className="col-span-1">{t('Infrastructure fee')}</dt>
|
||||
@@ -316,7 +324,7 @@ const FeesBreakdownTooltip = ({
|
||||
};
|
||||
|
||||
export const getFeesBreakdown = (
|
||||
role: string,
|
||||
role: Role,
|
||||
feesObj: {
|
||||
__typename?: 'TradeFee' | undefined;
|
||||
makerFee: string;
|
||||
@@ -328,6 +336,7 @@ export const getFeesBreakdown = (
|
||||
role === MAKER
|
||||
? new BigNumber(feesObj.makerFee).times(-1).toString()
|
||||
: feesObj.makerFee;
|
||||
|
||||
const infrastructureFee = feesObj.infrastructureFee;
|
||||
const liquidityFee = feesObj.liquidityFee;
|
||||
|
||||
|
||||
@@ -38,10 +38,10 @@ export const TransferTooltipCellComponent = ({
|
||||
);
|
||||
};
|
||||
|
||||
const defaultRangeFilter = { start: formatRFC3339(subDays(Date.now(), 7)) };
|
||||
const defaultValue = { start: formatRFC3339(subDays(Date.now(), 7)) };
|
||||
const dateRangeFilterParams = {
|
||||
maxNextDays: 0,
|
||||
defaultRangeFilter,
|
||||
defaultValue,
|
||||
};
|
||||
type LedgerEntryProps = TypedDataAgGrid<LedgerEntry>;
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import type {
|
||||
OrdersQueryVariables,
|
||||
} from './__generated__/Orders';
|
||||
import { OrdersDocument, OrdersUpdateDocument } from './__generated__/Orders';
|
||||
import type { ApolloClient } from '@apollo/client';
|
||||
|
||||
export type Order = Omit<OrderFieldsFragment, 'market'> & {
|
||||
market?: Market;
|
||||
@@ -81,8 +82,31 @@ const getData = (
|
||||
): Edge<OrderFieldsFragment>[] =>
|
||||
responseData?.party?.ordersConnection?.edges || [];
|
||||
|
||||
const getDelta = (subscriptionData: OrdersUpdateSubscription) =>
|
||||
subscriptionData.orders || [];
|
||||
const getDelta = (
|
||||
subscriptionData: OrdersUpdateSubscription,
|
||||
variables: OrdersQueryVariables,
|
||||
client: ApolloClient<object>
|
||||
) => {
|
||||
if (!subscriptionData.orders) {
|
||||
return [];
|
||||
}
|
||||
subscriptionData.orders.forEach((order) => {
|
||||
client.cache.modify({
|
||||
id: client.cache.identify({
|
||||
__typename: 'Order',
|
||||
id: order.id,
|
||||
}),
|
||||
fields: {
|
||||
price: () => order.price,
|
||||
size: () => order.size,
|
||||
remaining: () => order.remaining,
|
||||
updatedAt: () => order.updatedAt,
|
||||
status: () => order.status,
|
||||
},
|
||||
});
|
||||
});
|
||||
return subscriptionData.orders;
|
||||
};
|
||||
|
||||
const getPageInfo = (responseData: OrdersQuery): PageInfo | null =>
|
||||
responseData.party?.ordersConnection?.pageInfo || null;
|
||||
@@ -150,7 +174,7 @@ export const update = (
|
||||
});
|
||||
};
|
||||
|
||||
export const ordersProvider = makeDataProvider<
|
||||
const ordersProvider = makeDataProvider<
|
||||
OrdersQuery,
|
||||
ReturnType<typeof getData>,
|
||||
OrdersUpdateSubscription,
|
||||
@@ -165,11 +189,36 @@ export const ordersProvider = makeDataProvider<
|
||||
pagination: {
|
||||
getPageInfo,
|
||||
append,
|
||||
first: 100,
|
||||
first: 1000,
|
||||
},
|
||||
additionalContext: { isEnlargedTimeout: true },
|
||||
});
|
||||
|
||||
export const activeOrdersProvider = makeDerivedDataProvider<
|
||||
ReturnType<typeof getData>,
|
||||
never,
|
||||
{ partyId: string; marketId?: string }
|
||||
>(
|
||||
[
|
||||
(callback, client, variables) =>
|
||||
ordersProvider(callback, client, {
|
||||
partyId: variables.partyId,
|
||||
filter: {
|
||||
status: [OrderStatus.STATUS_ACTIVE, OrderStatus.STATUS_PARKED],
|
||||
},
|
||||
}),
|
||||
],
|
||||
(partsData, variables, prevData, parts, subscriptions) => {
|
||||
if (!parts[0].isUpdate && subscriptions && subscriptions[0].load) {
|
||||
subscriptions[0].load();
|
||||
}
|
||||
const orders = partsData[0] as ReturnType<typeof getData>;
|
||||
return variables.marketId
|
||||
? orders.filter((edge) => variables.marketId === edge.node.market.id)
|
||||
: orders;
|
||||
}
|
||||
);
|
||||
|
||||
export const ordersWithMarketProvider = makeDerivedDataProvider<
|
||||
(OrderEdge | null)[],
|
||||
Order[],
|
||||
@@ -193,63 +242,20 @@ export const ordersWithMarketProvider = makeDerivedDataProvider<
|
||||
combineInsertionData<Order>
|
||||
);
|
||||
|
||||
const hasActiveOrderProviderInternal = makeDataProvider<
|
||||
OrdersQuery,
|
||||
boolean,
|
||||
OrdersUpdateSubscription,
|
||||
ReturnType<typeof getDelta>,
|
||||
OrdersQueryVariables
|
||||
>({
|
||||
query: OrdersDocument,
|
||||
subscriptionQuery: OrdersUpdateDocument,
|
||||
update: (
|
||||
data: boolean | null,
|
||||
delta: ReturnType<typeof getDelta>,
|
||||
reload: () => void
|
||||
) => {
|
||||
const orders = delta?.filter(
|
||||
(order) => !(order.peggedOrder || order.liquidityProvisionId)
|
||||
);
|
||||
if (!orders?.length) {
|
||||
return data;
|
||||
}
|
||||
const hasActiveOrders = orders.some(
|
||||
(order) => order.status === OrderStatus.STATUS_ACTIVE
|
||||
);
|
||||
if (hasActiveOrders) {
|
||||
return true;
|
||||
} else if (data && !hasActiveOrders) {
|
||||
reload();
|
||||
}
|
||||
return data;
|
||||
},
|
||||
getData: (responseData: OrdersQuery | null) => {
|
||||
const hasActiveOrder = !!responseData?.party?.ordersConnection?.edges?.some(
|
||||
(order) => !(order.node.peggedOrder || order.node.liquidityProvision)
|
||||
);
|
||||
return hasActiveOrder;
|
||||
},
|
||||
getDelta,
|
||||
});
|
||||
|
||||
export const hasActiveOrderProvider = makeDerivedDataProvider<
|
||||
boolean,
|
||||
never,
|
||||
{ partyId: string; marketId?: string }
|
||||
>(
|
||||
[
|
||||
(callback, client, { partyId, marketId }) =>
|
||||
hasActiveOrderProviderInternal(callback, client, {
|
||||
marketIds: marketId ? [marketId] : undefined,
|
||||
filter: {
|
||||
status: [OrderStatus.STATUS_ACTIVE],
|
||||
excludeLiquidity: true,
|
||||
},
|
||||
pagination: {
|
||||
first: 1,
|
||||
},
|
||||
partyId,
|
||||
} as OrdersQueryVariables),
|
||||
],
|
||||
(parts) => parts[0]
|
||||
);
|
||||
>([activeOrdersProvider], (parts) => !!parts[0].length);
|
||||
|
||||
export const hasAmendableOrderProvider = makeDerivedDataProvider<
|
||||
boolean,
|
||||
never,
|
||||
{ partyId: string; marketId?: string }
|
||||
>([activeOrdersProvider], (parts) => {
|
||||
const activeOrders = parts[0] as ReturnType<typeof getData>;
|
||||
const hasAmendableOrder = activeOrders.some(
|
||||
(edge) => !(edge.node.liquidityProvision || edge.node.peggedOrder)
|
||||
);
|
||||
return hasAmendableOrder;
|
||||
});
|
||||
|
||||
@@ -6,10 +6,12 @@ import { OrderListManager } from './order-list-manager';
|
||||
export const OrderListContainer = ({
|
||||
marketId,
|
||||
onMarketClick,
|
||||
onOrderTypeClick,
|
||||
enforceBottomPlaceholder,
|
||||
}: {
|
||||
marketId?: string;
|
||||
onMarketClick?: (marketId: string, metaKey?: boolean) => void;
|
||||
onOrderTypeClick?: (marketId: string, metaKey?: boolean) => void;
|
||||
enforceBottomPlaceholder?: boolean;
|
||||
}) => {
|
||||
const { pubKey, isReadOnly } = useVegaWallet();
|
||||
@@ -23,6 +25,7 @@ export const OrderListContainer = ({
|
||||
partyId={pubKey}
|
||||
marketId={marketId}
|
||||
onMarketClick={onMarketClick}
|
||||
onOrderTypeClick={onOrderTypeClick}
|
||||
isReadOnly={isReadOnly}
|
||||
enforceBottomPlaceholder={enforceBottomPlaceholder}
|
||||
/>
|
||||
|
||||
@@ -8,7 +8,7 @@ import type { GridReadyEvent } from 'ag-grid-community';
|
||||
|
||||
import { OrderListTable } from '../order-list/order-list';
|
||||
import { useOrderListData } from './use-order-list-data';
|
||||
import { useHasActiveOrder } from '../../order-hooks/use-has-active-order';
|
||||
import { useHasAmendableOrder } from '../../order-hooks/use-has-amendable-order';
|
||||
import type { Filter, Sort } from './use-order-list-data';
|
||||
import { useBottomPlaceholder } from '@vegaprotocol/react-helpers';
|
||||
import { OrderStatus } from '@vegaprotocol/types';
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
normalizeOrderAmendment,
|
||||
useVegaTransactionStore,
|
||||
} from '@vegaprotocol/wallet';
|
||||
import isEqual from 'lodash/isEqual';
|
||||
import type { OrderTxUpdateFieldsFragment } from '@vegaprotocol/wallet';
|
||||
import { OrderEditDialog } from '../order-list/order-edit-dialog';
|
||||
import type { Order, OrderEdge } from '../order-data-provider';
|
||||
@@ -24,31 +25,23 @@ export interface OrderListManagerProps {
|
||||
partyId: string;
|
||||
marketId?: string;
|
||||
onMarketClick?: (marketId: string, metaKey?: boolean) => void;
|
||||
onOrderTypeClick?: (marketId: string, metaKey?: boolean) => void;
|
||||
isReadOnly: boolean;
|
||||
enforceBottomPlaceholder?: boolean;
|
||||
}
|
||||
|
||||
const CancelAllOrdersButton = ({
|
||||
onClick,
|
||||
marketId,
|
||||
}: {
|
||||
onClick: (marketId?: string) => void;
|
||||
marketId?: string;
|
||||
}) => {
|
||||
const hasActiveOrder = useHasActiveOrder(marketId);
|
||||
return hasActiveOrder ? (
|
||||
<div className="dark:bg-black/75 bg-white/75 h-auto flex justify-end px-[11px] py-2 absolute bottom-0 right-3 rounded">
|
||||
<Button
|
||||
variant="primary"
|
||||
size="sm"
|
||||
onClick={() => onClick(marketId)}
|
||||
data-testid="cancelAll"
|
||||
>
|
||||
{t('Cancel all')}
|
||||
</Button>
|
||||
</div>
|
||||
) : null;
|
||||
};
|
||||
const CancelAllOrdersButton = ({ onClick }: { onClick: () => void }) => (
|
||||
<div className="dark:bg-black/75 bg-white/75 h-auto flex justify-end px-[11px] py-2 absolute bottom-0 right-3 rounded">
|
||||
<Button
|
||||
variant="primary"
|
||||
size="sm"
|
||||
onClick={onClick}
|
||||
data-testid="cancelAll"
|
||||
>
|
||||
{t('Cancel all')}
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
|
||||
const initialFilter: Filter = {
|
||||
status: {
|
||||
@@ -60,6 +53,7 @@ export const OrderListManager = ({
|
||||
partyId,
|
||||
marketId,
|
||||
onMarketClick,
|
||||
onOrderTypeClick,
|
||||
isReadOnly,
|
||||
enforceBottomPlaceholder,
|
||||
}: OrderListManagerProps) => {
|
||||
@@ -68,9 +62,10 @@ export const OrderListManager = ({
|
||||
const scrolledToTop = useRef(false);
|
||||
const [sort, setSort] = useState<Sort[] | undefined>();
|
||||
const [filter, setFilter] = useState<Filter | undefined>(initialFilter);
|
||||
const filterRef = useRef(initialFilter);
|
||||
const [editOrder, setEditOrder] = useState<Order | null>(null);
|
||||
const create = useVegaTransactionStore((state) => state.create);
|
||||
const hasActiveOrder = useHasActiveOrder(marketId);
|
||||
const hasAmendableOrder = useHasAmendableOrder(marketId);
|
||||
|
||||
const { data, error, loading, reload } = useOrderListData({
|
||||
partyId,
|
||||
@@ -86,12 +81,16 @@ export const OrderListManager = ({
|
||||
...bottomPlaceholderProps
|
||||
} = useBottomPlaceholder<Order>({
|
||||
gridRef,
|
||||
disabled: !enforceBottomPlaceholder && !isReadOnly && !hasActiveOrder,
|
||||
disabled: !enforceBottomPlaceholder && !isReadOnly && !hasAmendableOrder,
|
||||
});
|
||||
|
||||
const onFilterChanged = useCallback(
|
||||
(event: FilterChangedEvent) => {
|
||||
const updatedFilter = event.api.getFilterModel();
|
||||
if (isEqual(updatedFilter, filterRef.current)) {
|
||||
return;
|
||||
}
|
||||
filterRef.current = updatedFilter;
|
||||
if (Object.keys(updatedFilter).length) {
|
||||
setFilter(updatedFilter);
|
||||
} else {
|
||||
@@ -142,16 +141,13 @@ export const OrderListManager = ({
|
||||
setDataCount(gridRef.current?.api?.getModel().getRowCount() ?? 0);
|
||||
}, [data]);
|
||||
|
||||
const cancelAll = useCallback(
|
||||
(marketId?: string) => {
|
||||
create({
|
||||
orderCancellation: {
|
||||
marketId,
|
||||
},
|
||||
});
|
||||
},
|
||||
[create]
|
||||
);
|
||||
const cancelAll = useCallback(() => {
|
||||
create({
|
||||
orderCancellation: {
|
||||
marketId,
|
||||
},
|
||||
});
|
||||
}, [create, marketId]);
|
||||
const extractedData =
|
||||
data && !loading
|
||||
? data
|
||||
@@ -171,6 +167,7 @@ export const OrderListManager = ({
|
||||
cancel={cancel}
|
||||
setEditOrder={setEditOrder}
|
||||
onMarketClick={onMarketClick}
|
||||
onOrderTypeClick={onOrderTypeClick}
|
||||
isReadOnly={isReadOnly}
|
||||
blockLoadDebounceMillis={100}
|
||||
suppressLoadingOverlay
|
||||
@@ -188,8 +185,8 @@ export const OrderListManager = ({
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{!isReadOnly && (
|
||||
<CancelAllOrdersButton onClick={cancelAll} marketId={marketId} />
|
||||
{!isReadOnly && hasAmendableOrder && (
|
||||
<CancelAllOrdersButton onClick={cancelAll} />
|
||||
)}
|
||||
{editOrder && (
|
||||
<OrderEditDialog
|
||||
|
||||
@@ -71,17 +71,27 @@ export const useOrderListData = ({
|
||||
// define variable as const to get type safety, using generic with useMemo resulted in lost type safety
|
||||
const allVars: OrdersQueryVariables & OrdersUpdateSubscriptionVariables = {
|
||||
partyId,
|
||||
filter: {
|
||||
dateRange: filter?.updatedAt?.value,
|
||||
status: filter?.status?.value,
|
||||
timeInForce: filter?.timeInForce?.value,
|
||||
types: filter?.type?.value,
|
||||
},
|
||||
pagination: {
|
||||
first: 1000,
|
||||
},
|
||||
};
|
||||
|
||||
if (
|
||||
filter?.updatedAt?.value ||
|
||||
filter?.status?.value.length ||
|
||||
filter?.timeInForce?.value.length ||
|
||||
filter?.type?.value.length
|
||||
) {
|
||||
allVars.filter = {};
|
||||
if (filter?.updatedAt?.value) {
|
||||
allVars.filter.dateRange = filter?.updatedAt?.value;
|
||||
}
|
||||
if (filter?.status?.value.length) {
|
||||
allVars.filter.status = filter?.status?.value;
|
||||
}
|
||||
if (filter?.timeInForce?.value.length) {
|
||||
allVars.filter.timeInForce = filter?.timeInForce?.value;
|
||||
}
|
||||
if (filter?.type?.value.length) {
|
||||
allVars.filter.types = filter?.type?.value;
|
||||
}
|
||||
}
|
||||
return allVars;
|
||||
}, [partyId, filter]);
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
negativeClassNames,
|
||||
positiveClassNames,
|
||||
MarketNameCell,
|
||||
OrderTypeCell,
|
||||
} from '@vegaprotocol/datagrid';
|
||||
import type {
|
||||
TypedDataAgGrid,
|
||||
@@ -31,12 +32,16 @@ export type OrderListTableProps = OrderListProps & {
|
||||
cancel: (order: Order) => void;
|
||||
setEditOrder: (order: Order) => void;
|
||||
onMarketClick?: (marketId: string, metaKey?: boolean) => void;
|
||||
onOrderTypeClick?: (marketId: string, metaKey?: boolean) => void;
|
||||
isReadOnly: boolean;
|
||||
};
|
||||
|
||||
export const OrderListTable = memo(
|
||||
forwardRef<AgGridReact, OrderListTableProps>(
|
||||
({ cancel, setEditOrder, onMarketClick, ...props }, ref) => {
|
||||
(
|
||||
{ cancel, setEditOrder, onMarketClick, onOrderTypeClick, ...props },
|
||||
ref
|
||||
) => {
|
||||
return (
|
||||
<AgGrid
|
||||
ref={ref}
|
||||
@@ -51,7 +56,7 @@ export const OrderListTable = memo(
|
||||
height: '100%',
|
||||
}}
|
||||
getRowId={({ data }) => data.id}
|
||||
components={{ MarketNameCell }}
|
||||
components={{ MarketNameCell, OrderTypeCell }}
|
||||
{...props}
|
||||
>
|
||||
<AgGridColumn
|
||||
@@ -103,17 +108,9 @@ export const OrderListTable = memo(
|
||||
filterParams={{
|
||||
set: Schema.OrderTypeMapping,
|
||||
}}
|
||||
valueFormatter={({
|
||||
data: order,
|
||||
value,
|
||||
}: VegaValueFormatterParams<Order, 'type'>) => {
|
||||
if (!order) {
|
||||
return undefined;
|
||||
}
|
||||
if (!value) return '-';
|
||||
if (order?.peggedOrder) return t('Pegged');
|
||||
if (order?.liquidityProvision) return t('Liquidity provision');
|
||||
return Schema.OrderTypeMapping[value];
|
||||
cellRenderer="OrderTypeCell"
|
||||
cellRendererParams={{
|
||||
onClick: onOrderTypeClick,
|
||||
}}
|
||||
minWidth={80}
|
||||
/>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
export * from './__generated__/OrdersSubscription';
|
||||
export * from './use-has-active-order';
|
||||
export * from './use-has-amendable-order';
|
||||
export * from './use-order-update';
|
||||
export * from './use-pending-orders-volume';
|
||||
export * from './use-order-store';
|
||||
|
||||
+6
-6
@@ -1,17 +1,17 @@
|
||||
import { useCallback, useState } from 'react';
|
||||
import { hasActiveOrderProvider } from '../components/order-data-provider/';
|
||||
import { hasAmendableOrderProvider } from '../components/order-data-provider';
|
||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
||||
import { useDataProvider } from '@vegaprotocol/react-helpers';
|
||||
|
||||
export const useHasActiveOrder = (marketId?: string) => {
|
||||
export const useHasAmendableOrder = (marketId?: string) => {
|
||||
const { pubKey } = useVegaWallet();
|
||||
const [hasActiveOrder, setHasActiveOrder] = useState(false);
|
||||
const [hasAmendableOrder, setHasAmendableOrder] = useState(false);
|
||||
const update = useCallback(({ data }: { data: boolean | null }) => {
|
||||
setHasActiveOrder(Boolean(data));
|
||||
setHasAmendableOrder(Boolean(data));
|
||||
return true;
|
||||
}, []);
|
||||
useDataProvider({
|
||||
dataProvider: hasActiveOrderProvider,
|
||||
dataProvider: hasAmendableOrderProvider,
|
||||
update,
|
||||
variables: {
|
||||
partyId: pubKey || '',
|
||||
@@ -20,5 +20,5 @@ export const useHasActiveOrder = (marketId?: string) => {
|
||||
skip: !pubKey,
|
||||
});
|
||||
|
||||
return hasActiveOrder;
|
||||
return hasAmendableOrder;
|
||||
};
|
||||
@@ -1,74 +0,0 @@
|
||||
import { useState, useCallback } from 'react';
|
||||
import { OrderStatus, Side } from '@vegaprotocol/types';
|
||||
import { ordersProvider } from '../components/order-data-provider/order-data-provider';
|
||||
import type { OrderFieldsFragment } from '../components/order-data-provider/__generated__/Orders';
|
||||
import type { Edge } from '@vegaprotocol/utils';
|
||||
import { useDataProvider } from '@vegaprotocol/react-helpers';
|
||||
|
||||
const sumVolume = (orders: (Edge<OrderFieldsFragment> | null)[], side: Side) =>
|
||||
orders
|
||||
.reduce(
|
||||
(sum, order) =>
|
||||
order?.node.side === side
|
||||
? sum +
|
||||
BigInt(
|
||||
order?.node.status === OrderStatus.STATUS_PARTIALLY_FILLED
|
||||
? order?.node.remaining
|
||||
: order?.node.size
|
||||
)
|
||||
: sum,
|
||||
BigInt(0)
|
||||
)
|
||||
.toString();
|
||||
|
||||
export const useActiveOrdersVolumeAndMargin = (
|
||||
partyId: string | null | undefined,
|
||||
marketId: string
|
||||
) => {
|
||||
const [buyVolume, setBuyVolume] = useState<string | undefined>();
|
||||
const [sellVolume, setSellVolume] = useState<string | undefined>();
|
||||
const [buyInitialMargin, setBuyInitialMargin] = useState<
|
||||
string | undefined
|
||||
>();
|
||||
const [sellInitialMargin, setSellInitialMargin] = useState<
|
||||
string | undefined
|
||||
>();
|
||||
const update = useCallback(
|
||||
({ data }: { data: (Edge<OrderFieldsFragment> | null)[] | null }) => {
|
||||
if (!data) {
|
||||
setBuyVolume(undefined);
|
||||
setSellVolume(undefined);
|
||||
setBuyInitialMargin(undefined);
|
||||
setSellInitialMargin(undefined);
|
||||
} else {
|
||||
setBuyVolume(sumVolume(data, Side.SIDE_BUY));
|
||||
setSellVolume(sumVolume(data, Side.SIDE_SELL));
|
||||
}
|
||||
return true;
|
||||
},
|
||||
[]
|
||||
);
|
||||
useDataProvider({
|
||||
dataProvider: ordersProvider,
|
||||
update,
|
||||
variables: {
|
||||
partyId: partyId || '',
|
||||
marketIds: [marketId],
|
||||
filter: {
|
||||
status: [
|
||||
OrderStatus.STATUS_ACTIVE,
|
||||
OrderStatus.STATUS_PARTIALLY_FILLED,
|
||||
],
|
||||
},
|
||||
},
|
||||
skip: !partyId,
|
||||
});
|
||||
return buyVolume || sellVolume
|
||||
? {
|
||||
buyVolume,
|
||||
sellVolume,
|
||||
buyInitialMargin,
|
||||
sellInitialMargin,
|
||||
}
|
||||
: undefined;
|
||||
};
|
||||
@@ -30,12 +30,12 @@ import {
|
||||
import { marginsDataProvider } from './margin-data-provider';
|
||||
import { calculateMargins } from './margin-calculator';
|
||||
import type { Edge } from '@vegaprotocol/utils';
|
||||
import { OrderStatus, Side } from '@vegaprotocol/types';
|
||||
import { Side } from '@vegaprotocol/types';
|
||||
import { marketInfoProvider } from '@vegaprotocol/market-info';
|
||||
import type { MarketInfoQuery } from '@vegaprotocol/market-info';
|
||||
import { marketDataProvider } from '@vegaprotocol/market-list';
|
||||
import type { MarketData } from '@vegaprotocol/market-list';
|
||||
import { ordersProvider } from '@vegaprotocol/orders';
|
||||
import { activeOrdersProvider } from '@vegaprotocol/orders';
|
||||
import type { OrderFieldsFragment } from '@vegaprotocol/orders';
|
||||
import type { PositionStatus } from '@vegaprotocol/types';
|
||||
|
||||
@@ -350,12 +350,9 @@ export const volumeAndMarginProvider = makeDerivedDataProvider<
|
||||
>(
|
||||
[
|
||||
(callback, client, { partyId, marketId }) =>
|
||||
ordersProvider(callback, client, {
|
||||
activeOrdersProvider(callback, client, {
|
||||
partyId,
|
||||
marketIds: [marketId],
|
||||
filter: {
|
||||
status: [OrderStatus.STATUS_ACTIVE, OrderStatus.STATUS_PARKED],
|
||||
},
|
||||
marketId,
|
||||
}),
|
||||
(callback, client, variables) =>
|
||||
marketDataProvider(callback, client, { marketId: variables.marketId }),
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { useState, useEffect, useRef, useCallback } from 'react';
|
||||
import { useState, useEffect, useRef, useMemo, useCallback } from 'react';
|
||||
import throttle from 'lodash/throttle';
|
||||
import isEqual from 'lodash/isEqual';
|
||||
import isEqualWith from 'lodash/isEqualWith';
|
||||
import { useApolloClient } from '@apollo/client';
|
||||
import { usePrevious } from './use-previous';
|
||||
import type { OperationVariables } from '@apollo/client';
|
||||
import type { Subscribe, Load, UpdateCallback } from '@vegaprotocol/utils';
|
||||
import { variablesIsEqualCustomizer } from '@vegaprotocol/utils';
|
||||
|
||||
export interface useDataProviderParams<
|
||||
Data,
|
||||
@@ -62,13 +62,19 @@ export const useDataProvider = <
|
||||
const flushRef = useRef<(() => void) | undefined>(undefined);
|
||||
const reloadRef = useRef<((force?: boolean) => void) | undefined>(undefined);
|
||||
const loadRef = useRef<Load<Data> | undefined>(undefined);
|
||||
const prevVariables = usePrevious(props.variables);
|
||||
const [variables, setVariables] = useState(props.variables);
|
||||
useEffect(() => {
|
||||
if (!isEqual(prevVariables, props.variables)) {
|
||||
setVariables(props.variables);
|
||||
const variablesRef = useRef<Variables>(props.variables);
|
||||
const variables = useMemo(() => {
|
||||
if (
|
||||
!isEqualWith(
|
||||
variablesRef.current,
|
||||
props.variables,
|
||||
variablesIsEqualCustomizer
|
||||
)
|
||||
) {
|
||||
variablesRef.current = props.variables;
|
||||
}
|
||||
}, [props.variables, prevVariables]);
|
||||
return variablesRef.current;
|
||||
}, [props.variables]);
|
||||
const flush = useCallback(() => {
|
||||
if (flushRef.current) {
|
||||
flushRef.current();
|
||||
|
||||
Generated
+271
-52
@@ -796,6 +796,67 @@ export type ETHAddress = {
|
||||
address?: Maybe<Scalars['String']>;
|
||||
};
|
||||
|
||||
/** List of all entities created by transaction hash */
|
||||
export type Entities = {
|
||||
__typename?: 'Entities';
|
||||
/** List of accounts created by the transaction hash */
|
||||
accounts?: Maybe<Array<Maybe<AccountEvent>>>;
|
||||
/** List of assets created by the transaction hash */
|
||||
assets?: Maybe<Array<Maybe<Asset>>>;
|
||||
/** List of balance changes created by the transaction hash */
|
||||
balanceChanges?: Maybe<Array<Maybe<AccountBalance>>>;
|
||||
/** List of delegations created by the transaction hash */
|
||||
delegations?: Maybe<Array<Maybe<Delegation>>>;
|
||||
/** List of deposits created by the transaction hash */
|
||||
deposits?: Maybe<Array<Maybe<Deposit>>>;
|
||||
/** List of ERC-20 multisig signer added bundles created by the transaction hash */
|
||||
erc20MultiSigSignerAddedBundles?: Maybe<Array<Maybe<ERC20MultiSigSignerAddedBundle>>>;
|
||||
/** List of ERC-20 multisig signer removed bundles created by the transaction hash */
|
||||
erc20MultiSigSignerRemovedBundles?: Maybe<Array<Maybe<ERC20MultiSigSignerRemovedBundle>>>;
|
||||
/** List of ethereum key rotations created by the transaction hash */
|
||||
ethereumKeyRotations?: Maybe<Array<Maybe<EthereumKeyRotation>>>;
|
||||
/** List of key rotations created by the transaction hash */
|
||||
keyRotations?: Maybe<Array<Maybe<KeyRotation>>>;
|
||||
/** List of ledger entries created by the transaction hash */
|
||||
ledgerEntries?: Maybe<Array<Maybe<LedgerEntry>>>;
|
||||
/** List of liquidity provisions created by the transaction hash */
|
||||
liquidityProvisions?: Maybe<Array<Maybe<LiquidityProvision>>>;
|
||||
/** List of margin levels created by the transaction hash */
|
||||
marginLevels?: Maybe<Array<Maybe<MarginLevels>>>;
|
||||
/** List of markets created by the transaction hash */
|
||||
markets?: Maybe<Array<Maybe<Market>>>;
|
||||
/** List of network parameters created by the transaction hash */
|
||||
networkParameters?: Maybe<Array<Maybe<NetworkParameter>>>;
|
||||
/** List of node signatures created by the transaction hash */
|
||||
nodeSignatures?: Maybe<Array<Maybe<NodeSignature>>>;
|
||||
/** List of nodes created by the transaction hash */
|
||||
nodes?: Maybe<Array<Maybe<NodeBasic>>>;
|
||||
/** List of oracle data created by the transaction hash */
|
||||
oracleData?: Maybe<Array<Maybe<OracleData>>>;
|
||||
/** List of oracle specs created by the transaction hash */
|
||||
oracleSpecs?: Maybe<Array<Maybe<OracleSpec>>>;
|
||||
/** List of orders created by the transaction hash */
|
||||
orders?: Maybe<Array<Maybe<Order>>>;
|
||||
/** List of parties created by the transaction hash */
|
||||
parties?: Maybe<Array<Maybe<Party>>>;
|
||||
/** List of positions created by the transaction hash */
|
||||
positions?: Maybe<Array<Maybe<Position>>>;
|
||||
/** List of proposals created by the transaction hash */
|
||||
proposals?: Maybe<Array<Maybe<ProposalDetail>>>;
|
||||
/** List of protocol upgrade proposals created by the transaction hash */
|
||||
protocolUpgradeProposals?: Maybe<Array<Maybe<ProtocolUpgradeProposal>>>;
|
||||
/** List of rewards created by the transaction hash */
|
||||
rewards?: Maybe<Array<Maybe<Reward>>>;
|
||||
/** List of trades created by the transaction hash */
|
||||
trades?: Maybe<Array<Maybe<Trade>>>;
|
||||
/** List of transfers created by the transaction hash */
|
||||
transfers?: Maybe<Array<Maybe<Transfer>>>;
|
||||
/** List of votes created by the transaction hash */
|
||||
votes?: Maybe<Array<Maybe<Vote>>>;
|
||||
/** List of withdrawals created by the transaction hash */
|
||||
withdrawals?: Maybe<Array<Maybe<Withdrawal>>>;
|
||||
};
|
||||
|
||||
/** Epoch describes a specific period of time in the Vega network */
|
||||
export type Epoch = {
|
||||
__typename?: 'Epoch';
|
||||
@@ -988,6 +1049,15 @@ export type ExternalDataSourceSpec = {
|
||||
spec: DataSourceSpec;
|
||||
};
|
||||
|
||||
/** An estimate of the fee to be paid for the order */
|
||||
export type FeeEstimate = {
|
||||
__typename?: 'FeeEstimate';
|
||||
/** The estimated fees if the order was to trade */
|
||||
fees: TradeFee;
|
||||
/** The total estimated amount of fees if the order was to trade */
|
||||
totalFeeAmount: Scalars['String'];
|
||||
};
|
||||
|
||||
/** The factors applied to calculate the fees */
|
||||
export type FeeFactors = {
|
||||
__typename?: 'FeeFactors';
|
||||
@@ -1178,6 +1248,26 @@ export type LedgerEntryFilter = {
|
||||
TransferTypes?: InputMaybe<Array<InputMaybe<TransferType>>>;
|
||||
};
|
||||
|
||||
/** Liquidation estimate for both worst and best case possible */
|
||||
export type LiquidationEstimate = {
|
||||
__typename?: 'LiquidationEstimate';
|
||||
/** Liquidation price estimate assuming no slippage */
|
||||
bestCase: LiquidationPrice;
|
||||
/** Liquidation price estimate assuming slippage cap is applied */
|
||||
worstCase: LiquidationPrice;
|
||||
};
|
||||
|
||||
/** Liquidation price estimate for either only the current open volume and position given some or all buy orders get filled, or position given some or all sell orders get filled */
|
||||
export type LiquidationPrice = {
|
||||
__typename?: 'LiquidationPrice';
|
||||
/** Liquidation price assuming buy orders start getting filled */
|
||||
including_buy_orders: Scalars['String'];
|
||||
/** Liquidation price assuming sell orders start getting filled */
|
||||
including_sell_orders: Scalars['String'];
|
||||
/** Liquidation price for current open volume ignoring any active orders */
|
||||
open_volume_only: Scalars['String'];
|
||||
};
|
||||
|
||||
/** Configuration of a market liquidity monitoring parameters */
|
||||
export type LiquidityMonitoringParameters = {
|
||||
__typename?: 'LiquidityMonitoringParameters';
|
||||
@@ -1367,6 +1457,15 @@ export type MarginEdge = {
|
||||
node: MarginLevels;
|
||||
};
|
||||
|
||||
/** Margin level estimate for both worst and best case possible */
|
||||
export type MarginEstimate = {
|
||||
__typename?: 'MarginEstimate';
|
||||
/** Margin level estimate assuming no slippage */
|
||||
bestCase: MarginLevels;
|
||||
/** Margin level estimate assuming slippage cap is applied */
|
||||
worstCase: MarginLevels;
|
||||
};
|
||||
|
||||
/** Margins for a given a party */
|
||||
export type MarginLevels = {
|
||||
__typename?: 'MarginLevels';
|
||||
@@ -1377,7 +1476,7 @@ export type MarginLevels = {
|
||||
* the general account of the party for the given asset.
|
||||
*/
|
||||
collateralReleaseLevel: Scalars['String'];
|
||||
/** This is the minimum margin required for a party to place a new order on the network (unsigned integer) */
|
||||
/** This is the minimum margin required for a party to place a new order on the network, expressed as unsigned integer */
|
||||
initialLevel: Scalars['String'];
|
||||
/** Minimal margin for the position to be maintained in the network (unsigned integer) */
|
||||
maintenanceLevel: Scalars['String'];
|
||||
@@ -1385,7 +1484,7 @@ export type MarginLevels = {
|
||||
market: Market;
|
||||
/** The party for this margin */
|
||||
party: Party;
|
||||
/** If the margin is between maintenance and search, the network will initiate a collateral search (unsigned integer) */
|
||||
/** If the margin is between maintenance and search, the network will initiate a collateral search, expressed as unsigned integer */
|
||||
searchLevel: Scalars['String'];
|
||||
/** RFC3339Nano time from at which this margin level was relevant */
|
||||
timestamp: Scalars['Timestamp'];
|
||||
@@ -1483,6 +1582,7 @@ export type Market = {
|
||||
state: MarketState;
|
||||
/** An instance of, or reference to, a tradable instrument. */
|
||||
tradableInstrument: TradableInstrument;
|
||||
/** @deprecated Simplify and consolidate trades query and remove nesting. Use trades query instead */
|
||||
tradesConnection?: Maybe<TradeConnection>;
|
||||
/** Current mode of execution of the market */
|
||||
tradingMode: MarketTradingMode;
|
||||
@@ -1894,6 +1994,28 @@ export type NodedelegationsConnectionArgs = {
|
||||
partyId?: InputMaybe<Scalars['ID']>;
|
||||
};
|
||||
|
||||
export type NodeBasic = {
|
||||
__typename?: 'NodeBasic';
|
||||
/** The URL of an avatar */
|
||||
avatarUrl?: Maybe<Scalars['String']>;
|
||||
/** Ethereum public key of the node */
|
||||
ethereumAddress: Scalars['String'];
|
||||
/** The node URL, for example n01.vega.xyz */
|
||||
id: Scalars['ID'];
|
||||
/** URL that provides more information about the node */
|
||||
infoUrl: Scalars['String'];
|
||||
/** Country code for the location of the node */
|
||||
location: Scalars['String'];
|
||||
/** The name of the node operator */
|
||||
name: Scalars['String'];
|
||||
/** Public key of the node operator */
|
||||
pubkey: Scalars['String'];
|
||||
/** Validator status of the node */
|
||||
status: NodeStatus;
|
||||
/** Tendermint public key of the node */
|
||||
tmPubkey: Scalars['String'];
|
||||
};
|
||||
|
||||
/** Summary of data across all nodes */
|
||||
export type NodeData = {
|
||||
__typename?: 'NodeData';
|
||||
@@ -2107,18 +2229,6 @@ export type ObservableMarketDepthUpdate = {
|
||||
sequenceNumber: Scalars['String'];
|
||||
};
|
||||
|
||||
export type OffsetPagination = {
|
||||
/**
|
||||
* Descending reverses the order of the records returned
|
||||
* default is true, if false the results will be returned in ascending order
|
||||
*/
|
||||
descending: Scalars['Boolean'];
|
||||
/** Limit the number of returned records to the value specified, default is 50 */
|
||||
limit: Scalars['Int'];
|
||||
/** Skip the number of records specified, default is 0 */
|
||||
skip: Scalars['Int'];
|
||||
};
|
||||
|
||||
/** The specific details for a one-off transfer */
|
||||
export type OneOffTransfer = {
|
||||
__typename?: 'OneOffTransfer';
|
||||
@@ -2213,7 +2323,10 @@ export type Order = {
|
||||
status: OrderStatus;
|
||||
/** The timeInForce of order (determines how and if it executes, and whether it persists on the book) */
|
||||
timeInForce: OrderTimeInForce;
|
||||
/** Trades relating to this order */
|
||||
/**
|
||||
* Trades relating to this order
|
||||
* @deprecated Simplify and consolidate trades query and remove nesting. Use trades query instead
|
||||
*/
|
||||
tradesConnection?: Maybe<TradeConnection>;
|
||||
/** The order type */
|
||||
type?: Maybe<OrderType>;
|
||||
@@ -2279,11 +2392,28 @@ export type OrderFilter = {
|
||||
/** Date range to retrieve orders from/to. Start and end time should be expressed as an integer value of nano-seconds past the Unix epoch */
|
||||
dateRange?: InputMaybe<DateRange>;
|
||||
excludeLiquidity?: InputMaybe<Scalars['Boolean']>;
|
||||
/**
|
||||
* If true, only orders that are live will be returned. Orders are live if they have STATUS_ACTIVE or STATUS_PARKED
|
||||
* as per https://github.com/vegaprotocol/specs-internal/blob/master/protocol/0024-OSTA-order_status.md
|
||||
*/
|
||||
liveOnly?: InputMaybe<Scalars['Boolean']>;
|
||||
status?: InputMaybe<Array<OrderStatus>>;
|
||||
timeInForce?: InputMaybe<Array<OrderTimeInForce>>;
|
||||
types?: InputMaybe<Array<OrderType>>;
|
||||
};
|
||||
|
||||
/** Basic description of an order */
|
||||
export type OrderInfo = {
|
||||
/** Boolean indicating a market order */
|
||||
isMarketOrder: Scalars['Boolean'];
|
||||
/** Price for the order */
|
||||
price: Scalars['String'];
|
||||
/** Number of units remaining of the total that have not yet been bought or sold (uint64) */
|
||||
remaining: Scalars['String'];
|
||||
/** Whether the order is to buy or sell */
|
||||
side: Side;
|
||||
};
|
||||
|
||||
/** Why the order was rejected by the core node */
|
||||
export enum OrderRejectionReason {
|
||||
/** Amending the order failed */
|
||||
@@ -2304,6 +2434,8 @@ export enum OrderRejectionReason {
|
||||
ORDER_ERROR_CANNOT_HAVE_GTC_AND_EXPIRYAT = 'ORDER_ERROR_CANNOT_HAVE_GTC_AND_EXPIRYAT',
|
||||
/** Cannot send FOK orders during an auction */
|
||||
ORDER_ERROR_CANNOT_SEND_FOK_ORDER_DURING_AUCTION = 'ORDER_ERROR_CANNOT_SEND_FOK_ORDER_DURING_AUCTION',
|
||||
/** Good for Auction order received during continuous trading */
|
||||
ORDER_ERROR_CANNOT_SEND_GFA_ORDER_DURING_CONTINUOUS_TRADING = 'ORDER_ERROR_CANNOT_SEND_GFA_ORDER_DURING_CONTINUOUS_TRADING',
|
||||
/** Good for Normal order received during an auction */
|
||||
ORDER_ERROR_CANNOT_SEND_GFN_ORDER_DURING_AN_AUCTION = 'ORDER_ERROR_CANNOT_SEND_GFN_ORDER_DURING_AN_AUCTION',
|
||||
/** Cannot send IOC orders during an auction */
|
||||
@@ -2312,8 +2444,8 @@ export enum OrderRejectionReason {
|
||||
ORDER_ERROR_EDIT_NOT_ALLOWED = 'ORDER_ERROR_EDIT_NOT_ALLOWED',
|
||||
/** Attempt to amend expiry time to a value before time order was created */
|
||||
ORDER_ERROR_EXPIRYAT_BEFORE_CREATEDAT = 'ORDER_ERROR_EXPIRYAT_BEFORE_CREATEDAT',
|
||||
/** Good for Auction order received during continuous trading */
|
||||
ORDER_ERROR_GFA_CANNOT_SEND_ORDER_DURING_CONTINUOUS_TRADING = 'ORDER_ERROR_GFA_CANNOT_SEND_ORDER_DURING_CONTINUOUS_TRADING',
|
||||
/** Order was submitted with an incorrect or invalid market type */
|
||||
ORDER_ERROR_INCORRECT_MARKET_TYPE = 'ORDER_ERROR_INCORRECT_MARKET_TYPE',
|
||||
/** Insufficient balance to submit the order (no deposit made) */
|
||||
ORDER_ERROR_INSUFFICIENT_ASSET_BALANCE = 'ORDER_ERROR_INSUFFICIENT_ASSET_BALANCE',
|
||||
/** Insufficient funds to pay fees */
|
||||
@@ -2360,6 +2492,10 @@ export enum OrderRejectionReason {
|
||||
ORDER_ERROR_OFFSET_MUST_BE_GREATER_THAN_ZERO = 'ORDER_ERROR_OFFSET_MUST_BE_GREATER_THAN_ZERO',
|
||||
/** Order is out of sequence */
|
||||
ORDER_ERROR_OUT_OF_SEQUENCE = 'ORDER_ERROR_OUT_OF_SEQUENCE',
|
||||
/** A post-only order would produce an aggressive trade and thus it has been rejected */
|
||||
ORDER_ERROR_POST_ONLY_ORDER_WOULD_TRADE = 'ORDER_ERROR_POST_ONLY_ORDER_WOULD_TRADE',
|
||||
/** A reduce-ony order would not reduce the party's position and thus it has been rejected */
|
||||
ORDER_ERROR_REDUCE_ONLY_ORDER_WOULD_NOT_REDUCE = 'ORDER_ERROR_REDUCE_ONLY_ORDER_WOULD_NOT_REDUCE',
|
||||
/** Unable to remove the order */
|
||||
ORDER_ERROR_REMOVAL_FAILURE = 'ORDER_ERROR_REMOVAL_FAILURE',
|
||||
/** Order cannot be filled because it would require self trading */
|
||||
@@ -2368,6 +2504,8 @@ export enum OrderRejectionReason {
|
||||
ORDER_ERROR_SELL_CANNOT_REFERENCE_BEST_BID_PRICE = 'ORDER_ERROR_SELL_CANNOT_REFERENCE_BEST_BID_PRICE',
|
||||
/** Time has failed us */
|
||||
ORDER_ERROR_TIME_FAILURE = 'ORDER_ERROR_TIME_FAILURE',
|
||||
/** Unable to submit pegged order, temporarily too many pegged orders across all markets */
|
||||
ORDER_ERROR_TOO_MANY_PEGGED_ORDERS = 'ORDER_ERROR_TOO_MANY_PEGGED_ORDERS',
|
||||
/** Unable to amend pegged order price */
|
||||
ORDER_ERROR_UNABLE_TO_AMEND_PRICE_ON_PEGGED_ORDER = 'ORDER_ERROR_UNABLE_TO_AMEND_PRICE_ON_PEGGED_ORDER',
|
||||
/** Unable to reprice a pegged order */
|
||||
@@ -2526,6 +2664,7 @@ export type Party = {
|
||||
rewardsConnection?: Maybe<RewardsConnection>;
|
||||
/** The staking information for this Party */
|
||||
stakingSummary: StakingSummary;
|
||||
/** @deprecated Simplify and consolidate trades query and remove nesting. Use trades query instead */
|
||||
tradesConnection?: Maybe<TradeConnection>;
|
||||
/** All transfers for a public key */
|
||||
transfersConnection?: Maybe<TransferConnection>;
|
||||
@@ -2754,6 +2893,15 @@ export type PositionEdge = {
|
||||
node: Position;
|
||||
};
|
||||
|
||||
/** Response for the estimate of the margin level and, if available, collateral was provided in the request, liqudation price for the specified position */
|
||||
export type PositionEstimate = {
|
||||
__typename?: 'PositionEstimate';
|
||||
/** Liquidation price range estimate for the specified position. Only populated if available collateral was specified in the request */
|
||||
liquidation?: Maybe<LiquidationEstimate>;
|
||||
/** Margin level range estimate for the specified position */
|
||||
margin: MarginEstimate;
|
||||
};
|
||||
|
||||
export type PositionResolution = {
|
||||
__typename?: 'PositionResolution';
|
||||
/** Number of parties closed out */
|
||||
@@ -2770,6 +2918,8 @@ export type PositionResolution = {
|
||||
export enum PositionStatus {
|
||||
/** The position was distressed, and had to be closed out entirely - orders were removed from the book, and the open volume was closed out by the network */
|
||||
POSITION_STATUS_CLOSED_OUT = 'POSITION_STATUS_CLOSED_OUT',
|
||||
/** The position was distressed, but could not be closed out - orders were removed from the book, and the open volume will be closed out once there is sufficient volume on the book */
|
||||
POSITION_STATUS_DISTRESSED = 'POSITION_STATUS_DISTRESSED',
|
||||
/** The position was distressed, but removing open orders from the book brought the margin level back to a point where the open position could be maintained */
|
||||
POSITION_STATUS_ORDERS_CLOSED = 'POSITION_STATUS_ORDERS_CLOSED',
|
||||
/** The position is either healthy, or if closed out, was closed out normally */
|
||||
@@ -2923,9 +3073,9 @@ export type Proposal = {
|
||||
reference: Scalars['String'];
|
||||
/** Why the proposal was rejected by the core */
|
||||
rejectionReason?: Maybe<ProposalRejectionReason>;
|
||||
/** Required liquidity provider equity like share majority for this proposal to succeed */
|
||||
/** Equity-like share required for a market amendment proposal to be enacted (if not met, the proposal will not be enacted), represented as a fraction that can be converted to a percentage */
|
||||
requiredLpMajority?: Maybe<Scalars['String']>;
|
||||
/** Required liquidity provider equity like share participation for this proposal to succeed */
|
||||
/** The market share of LPs' equity-like share that must take part in the market amendment vote for the proposal to pass. This means the votes of LPs that have submitted more liquidity to that market, or have been LPs from the start carry more weight. If it requires 50% of a market's equity-like share for a majority, and the proposal receives only YES votes but only LPs with 49% of the equity-like share voted, the proposal will not pass */
|
||||
requiredLpParticipation?: Maybe<Scalars['String']>;
|
||||
/** Required majority for this proposal to succeed */
|
||||
requiredMajority: Scalars['String'];
|
||||
@@ -2941,6 +3091,36 @@ export type Proposal = {
|
||||
|
||||
export type ProposalChange = NewAsset | NewFreeform | NewMarket | UpdateAsset | UpdateMarket | UpdateNetworkParameter;
|
||||
|
||||
export type ProposalDetail = {
|
||||
__typename?: 'ProposalDetail';
|
||||
/** RFC3339Nano time and date when the proposal reached the Vega network */
|
||||
datetime: Scalars['Timestamp'];
|
||||
/** Error details of the rejectionReason */
|
||||
errorDetails?: Maybe<Scalars['String']>;
|
||||
/** Proposal ID that is provided by Vega once proposal reaches the network */
|
||||
id?: Maybe<Scalars['ID']>;
|
||||
/** Party that prepared the proposal */
|
||||
party: Party;
|
||||
/** Rationale behind the proposal */
|
||||
rationale: ProposalRationale;
|
||||
/** A UUID reference to aid tracking proposals on Vega */
|
||||
reference: Scalars['String'];
|
||||
/** Why the proposal was rejected by the core */
|
||||
rejectionReason?: Maybe<ProposalRejectionReason>;
|
||||
/** Equity-like share required for a market amendment proposal to be enacted (if not met, the proposal will not be enacted), represented as a fraction that can be converted to a percentage */
|
||||
requiredLpMajority?: Maybe<Scalars['String']>;
|
||||
/** The market share of LPs' equity-like share that must take part in the market amendment vote for the proposal to pass. This means the votes of LPs that have submitted more liquidity to that market, or have been LPs from the start carry more weight. If it requires 50% of a market's equity-like share for a majority, and the proposal receives only YES votes but only LPs with 49% of the equity-like share voted, the proposal will not pass */
|
||||
requiredLpParticipation?: Maybe<Scalars['String']>;
|
||||
/** Required majority for this proposal to succeed */
|
||||
requiredMajority: Scalars['String'];
|
||||
/** Required participation for this proposal to succeed */
|
||||
requiredParticipation: Scalars['String'];
|
||||
/** State of the proposal */
|
||||
state: ProposalState;
|
||||
/** Terms of the proposal */
|
||||
terms: ProposalTerms;
|
||||
};
|
||||
|
||||
/** Edge type containing the proposals and cursor information returned by a ProposalsConnection */
|
||||
export type ProposalEdge = {
|
||||
__typename?: 'ProposalEdge';
|
||||
@@ -3234,6 +3414,8 @@ export type Query = {
|
||||
deposit?: Maybe<Deposit>;
|
||||
/** Fetch all deposits */
|
||||
deposits?: Maybe<DepositsConnection>;
|
||||
/** Fetch all entities for a given transaction hash */
|
||||
entities: Entities;
|
||||
/** Get data for a specific epoch, if ID omitted it gets the current epoch. If the string is 'next', fetch the next epoch */
|
||||
epoch: Epoch;
|
||||
/** List reward summary per epoch by asset, market, reward type */
|
||||
@@ -3249,15 +3431,17 @@ export type Query = {
|
||||
/** Find an erc20 withdrawal approval using its withdrawal ID */
|
||||
erc20WithdrawalApproval?: Maybe<Erc20WithdrawalApproval>;
|
||||
/** Return an estimation of the potential cost for a new order */
|
||||
estimateFees: FeeEstimate;
|
||||
/**
|
||||
* Return an estimation of the potential cost for a new order
|
||||
* @deprecated Use estimateFees and estimatePosition instead
|
||||
*/
|
||||
estimateOrder: OrderEstimate;
|
||||
/** Return a margin range for the specified position and liquidation price range if available collateral is supplied */
|
||||
estimatePosition?: Maybe<PositionEstimate>;
|
||||
/** Query for historic ethereum key rotations */
|
||||
ethereumKeyRotations: EthereumKeyRotationsConnection;
|
||||
/**
|
||||
* Get market data history for a specific market. If no dates are given, the latest snapshot will be returned. If only the start date is provided, all history from the given date will be provided, and if only the end date is provided, all history from the start up to and including the end date will be provided.
|
||||
* @deprecated Use getMarketDataHistoryConnectionByID instead
|
||||
*/
|
||||
getMarketDataHistoryByID?: Maybe<Array<Maybe<MarketData>>>;
|
||||
/** Get market data history for a specific market. If no dates are given, the latest snapshot will be returned. If only the start date is provided all history from the given date will be provided, and if only the end date is provided, all history from the start up to and including the end date will be provided. Pagination is provided using a cursor based pagination model */
|
||||
/** Get market data history for a specific market. If no dates are given, the latest snapshot will be returned. If only the start date is provided all history from the given date will be provided, and if only the end date is provided, all history from the start up to and including the end date will be provided. */
|
||||
getMarketDataHistoryConnectionByID?: Maybe<MarketDataConnection>;
|
||||
/** Query for historic key rotations */
|
||||
keyRotationsConnection: KeyRotationConnection;
|
||||
@@ -3315,6 +3499,8 @@ export type Query = {
|
||||
protocolUpgradeStatus?: Maybe<ProtocolUpgradeStatus>;
|
||||
/** Get statistics about the Vega node */
|
||||
statistics: Statistics;
|
||||
/** Get a list of all trades and apply any given filters to the results */
|
||||
trades?: Maybe<TradeConnection>;
|
||||
/** Get a list of all transfers for a public key */
|
||||
transfersConnection?: Maybe<TransferConnection>;
|
||||
/** Find a withdrawal using its ID */
|
||||
@@ -3364,6 +3550,12 @@ export type QuerydepositsArgs = {
|
||||
};
|
||||
|
||||
|
||||
/** Queries allow a caller to read data and filter data via GraphQL. */
|
||||
export type QueryentitiesArgs = {
|
||||
txHash: Scalars['String'];
|
||||
};
|
||||
|
||||
|
||||
/** Queries allow a caller to read data and filter data via GraphQL. */
|
||||
export type QueryepochArgs = {
|
||||
id?: InputMaybe<Scalars['ID']>;
|
||||
@@ -3413,6 +3605,19 @@ export type Queryerc20WithdrawalApprovalArgs = {
|
||||
};
|
||||
|
||||
|
||||
/** Queries allow a caller to read data and filter data via GraphQL. */
|
||||
export type QueryestimateFeesArgs = {
|
||||
expiration?: InputMaybe<Scalars['Timestamp']>;
|
||||
marketId: Scalars['ID'];
|
||||
partyId: Scalars['ID'];
|
||||
price?: InputMaybe<Scalars['String']>;
|
||||
side: Side;
|
||||
size: Scalars['String'];
|
||||
timeInForce: OrderTimeInForce;
|
||||
type: OrderType;
|
||||
};
|
||||
|
||||
|
||||
/** Queries allow a caller to read data and filter data via GraphQL. */
|
||||
export type QueryestimateOrderArgs = {
|
||||
expiration?: InputMaybe<Scalars['Timestamp']>;
|
||||
@@ -3427,19 +3632,17 @@ export type QueryestimateOrderArgs = {
|
||||
|
||||
|
||||
/** Queries allow a caller to read data and filter data via GraphQL. */
|
||||
export type QueryethereumKeyRotationsArgs = {
|
||||
nodeId?: InputMaybe<Scalars['ID']>;
|
||||
export type QueryestimatePositionArgs = {
|
||||
collateralAvailable?: InputMaybe<Scalars['String']>;
|
||||
marketId: Scalars['ID'];
|
||||
openVolume: Scalars['String'];
|
||||
orders?: InputMaybe<Array<OrderInfo>>;
|
||||
};
|
||||
|
||||
|
||||
/** Queries allow a caller to read data and filter data via GraphQL. */
|
||||
export type QuerygetMarketDataHistoryByIDArgs = {
|
||||
end?: InputMaybe<Scalars['Timestamp']>;
|
||||
first?: InputMaybe<Scalars['Int']>;
|
||||
id: Scalars['ID'];
|
||||
last?: InputMaybe<Scalars['Int']>;
|
||||
skip?: InputMaybe<Scalars['Int']>;
|
||||
start?: InputMaybe<Scalars['Timestamp']>;
|
||||
export type QueryethereumKeyRotationsArgs = {
|
||||
nodeId?: InputMaybe<Scalars['ID']>;
|
||||
};
|
||||
|
||||
|
||||
@@ -3600,6 +3803,14 @@ export type QueryprotocolUpgradeProposalsArgs = {
|
||||
};
|
||||
|
||||
|
||||
/** Queries allow a caller to read data and filter data via GraphQL. */
|
||||
export type QuerytradesArgs = {
|
||||
dateRange?: InputMaybe<DateRange>;
|
||||
filter?: InputMaybe<TradesFilter>;
|
||||
pagination?: InputMaybe<Pagination>;
|
||||
};
|
||||
|
||||
|
||||
/** Queries allow a caller to read data and filter data via GraphQL. */
|
||||
export type QuerytransfersConnectionArgs = {
|
||||
direction?: InputMaybe<TransferDirection>;
|
||||
@@ -3798,7 +4009,9 @@ export enum Side {
|
||||
/** The placer of the order is aiming to buy */
|
||||
SIDE_BUY = 'SIDE_BUY',
|
||||
/** The placer of the order is aiming to sell */
|
||||
SIDE_SELL = 'SIDE_SELL'
|
||||
SIDE_SELL = 'SIDE_SELL',
|
||||
/** Unspecified is only used for trades at the end of an auction, where neither party acts as the aggressor. */
|
||||
SIDE_UNSPECIFIED = 'SIDE_UNSPECIFIED'
|
||||
}
|
||||
|
||||
/** Signer is the authorized signature used for the data. */
|
||||
@@ -3978,8 +4191,6 @@ export type Subscription = {
|
||||
busEvents?: Maybe<Array<BusEvent>>;
|
||||
/** Subscribe to the candles updates */
|
||||
candles: Candle;
|
||||
/** Subscribe to delegation data */
|
||||
delegations: Delegation;
|
||||
/** Subscribe to liquidity provisioning data */
|
||||
liquidityProvisions?: Maybe<Array<LiquidityProvisionUpdate>>;
|
||||
/** Subscribe to the margin changes */
|
||||
@@ -3996,10 +4207,13 @@ export type Subscription = {
|
||||
positions: Array<PositionUpdate>;
|
||||
/** Subscribe to proposals. Leave out all arguments to receive all proposals */
|
||||
proposals: Proposal;
|
||||
/** Subscribe to reward details data */
|
||||
rewards: Reward;
|
||||
/** Subscribe to the trades updates */
|
||||
/**
|
||||
* Subscribe to the trades updates
|
||||
* @deprecated Use tradesStream instead as it allows for filtering multiple markets and/or parties at once
|
||||
*/
|
||||
trades?: Maybe<Array<TradeUpdate>>;
|
||||
/** Subscribe to the trades updates */
|
||||
tradesStream?: Maybe<Array<TradeUpdate>>;
|
||||
/** Subscribe to votes, either by proposal ID or party ID */
|
||||
votes: ProposalVote;
|
||||
};
|
||||
@@ -4030,13 +4244,6 @@ export type SubscriptioncandlesArgs = {
|
||||
};
|
||||
|
||||
|
||||
/** Subscriptions allow a caller to receive new information as it is available from the Vega network. */
|
||||
export type SubscriptiondelegationsArgs = {
|
||||
nodeId?: InputMaybe<Scalars['ID']>;
|
||||
partyId?: InputMaybe<Scalars['ID']>;
|
||||
};
|
||||
|
||||
|
||||
/** Subscriptions allow a caller to receive new information as it is available from the Vega network. */
|
||||
export type SubscriptionliquidityProvisionsArgs = {
|
||||
marketId?: InputMaybe<Scalars['ID']>;
|
||||
@@ -4089,16 +4296,15 @@ export type SubscriptionproposalsArgs = {
|
||||
|
||||
|
||||
/** Subscriptions allow a caller to receive new information as it is available from the Vega network. */
|
||||
export type SubscriptionrewardsArgs = {
|
||||
assetId?: InputMaybe<Scalars['ID']>;
|
||||
export type SubscriptiontradesArgs = {
|
||||
marketId?: InputMaybe<Scalars['ID']>;
|
||||
partyId?: InputMaybe<Scalars['ID']>;
|
||||
};
|
||||
|
||||
|
||||
/** Subscriptions allow a caller to receive new information as it is available from the Vega network. */
|
||||
export type SubscriptiontradesArgs = {
|
||||
marketId?: InputMaybe<Scalars['ID']>;
|
||||
partyId?: InputMaybe<Scalars['ID']>;
|
||||
export type SubscriptiontradesStreamArgs = {
|
||||
filter: TradesSubscriptionFilter;
|
||||
};
|
||||
|
||||
|
||||
@@ -4251,6 +4457,19 @@ export type TradeUpdate = {
|
||||
type: TradeType;
|
||||
};
|
||||
|
||||
/** Filter to apply to the trade connection query */
|
||||
export type TradesFilter = {
|
||||
marketIds?: InputMaybe<Array<Scalars['ID']>>;
|
||||
orderIds?: InputMaybe<Array<Scalars['ID']>>;
|
||||
partyIds?: InputMaybe<Array<Scalars['ID']>>;
|
||||
};
|
||||
|
||||
/** Filter to apply to the trade subscription request */
|
||||
export type TradesSubscriptionFilter = {
|
||||
marketIds?: InputMaybe<Array<Scalars['ID']>>;
|
||||
partyIds?: InputMaybe<Array<Scalars['ID']>>;
|
||||
};
|
||||
|
||||
/** The result from processing a transaction */
|
||||
export type TransactionResult = {
|
||||
__typename?: 'TransactionResult';
|
||||
|
||||
@@ -172,7 +172,7 @@ export const OrderRejectionReasonMapping: {
|
||||
'Cannot send IOC order during auction',
|
||||
ORDER_ERROR_EDIT_NOT_ALLOWED: 'Edit not allowed',
|
||||
ORDER_ERROR_EXPIRYAT_BEFORE_CREATEDAT: 'Expiry time before creation time',
|
||||
ORDER_ERROR_GFA_CANNOT_SEND_ORDER_DURING_CONTINUOUS_TRADING:
|
||||
ORDER_ERROR_CANNOT_SEND_GFA_ORDER_DURING_CONTINUOUS_TRADING:
|
||||
'Cannot send GFA order during continuous trading',
|
||||
ORDER_ERROR_INSUFFICIENT_ASSET_BALANCE: 'Insufficient asset balance',
|
||||
ORDER_ERROR_INSUFFICIENT_FUNDS_TO_PAY_FEES: 'Insufficient funds to pay fees',
|
||||
@@ -209,6 +209,11 @@ export const OrderRejectionReasonMapping: {
|
||||
'Unable to amend price on pegged order',
|
||||
ORDER_ERROR_UNABLE_TO_REPRICE_PEGGED_ORDER: 'Unable to reprice pegged order',
|
||||
ORDER_ERROR_WITHOUT_REFERENCE_PRICE: 'Without reference price',
|
||||
ORDER_ERROR_INCORRECT_MARKET_TYPE: 'Incorrect market type',
|
||||
ORDER_ERROR_POST_ONLY_ORDER_WOULD_TRADE: 'Post only order would trade',
|
||||
ORDER_ERROR_REDUCE_ONLY_ORDER_WOULD_NOT_REDUCE:
|
||||
'Reduce only order would not reduce',
|
||||
ORDER_ERROR_TOO_MANY_PEGGED_ORDERS: 'Too many pegged orders',
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -345,6 +350,7 @@ export const SideMapping: {
|
||||
} = {
|
||||
SIDE_BUY: 'Long',
|
||||
SIDE_SELL: 'Short',
|
||||
SIDE_UNSPECIFIED: 'Unspecified',
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -458,6 +464,7 @@ export const PositionStatusMapping: {
|
||||
POSITION_STATUS_CLOSED_OUT: 'Closed by network',
|
||||
POSITION_STATUS_ORDERS_CLOSED: 'Maintained by network',
|
||||
POSITION_STATUS_UNSPECIFIED: 'Normal',
|
||||
POSITION_STATUS_DISTRESSED: 'Distressed',
|
||||
};
|
||||
|
||||
export const ConditionOperatorMapping: { [C in ConditionOperator]: string } = {
|
||||
|
||||
@@ -25,6 +25,7 @@ export * from './nav-dropdown';
|
||||
export * from './nav';
|
||||
export * from './navigation';
|
||||
export * from './notification';
|
||||
export * from './pagination';
|
||||
export * from './popover';
|
||||
export * from './progress-bar';
|
||||
export * from './radio-group';
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export * from './pagination';
|
||||
@@ -0,0 +1,28 @@
|
||||
import { useState } from 'react';
|
||||
import { Pagination } from './pagination';
|
||||
|
||||
import type { ComponentStory, ComponentMeta } from '@storybook/react';
|
||||
export default {
|
||||
title: 'Pagination',
|
||||
component: Pagination,
|
||||
} as ComponentMeta<typeof Pagination>;
|
||||
|
||||
const Template: ComponentStory<typeof Pagination> = (args) => {
|
||||
const MAX_PAGE = 3;
|
||||
const [page, setPage] = useState(1);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Pagination
|
||||
hasPrevPage={page !== 1}
|
||||
hasNextPage={page < MAX_PAGE}
|
||||
onBack={() => setPage(Math.max(1, page - 1))}
|
||||
onNext={() => setPage(Math.min(MAX_PAGE, page + 1))}
|
||||
>
|
||||
Page {page}
|
||||
</Pagination>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const Default = Template.bind({});
|
||||
@@ -0,0 +1,73 @@
|
||||
import type { ReactNode } from 'react';
|
||||
import { Button } from '../button';
|
||||
import { Icon } from '../icon';
|
||||
|
||||
export type PaginationProps = {
|
||||
hasPrevPage: boolean;
|
||||
hasNextPage: boolean;
|
||||
isLoading?: boolean;
|
||||
children?: ReactNode;
|
||||
onBack: () => void;
|
||||
onNext: () => void;
|
||||
onFirst?: () => void;
|
||||
onLast?: () => void;
|
||||
};
|
||||
|
||||
const buttonClass = 'rounded-full w-[34px] h-[34px]';
|
||||
|
||||
export const Pagination = ({
|
||||
hasPrevPage,
|
||||
hasNextPage,
|
||||
isLoading,
|
||||
children,
|
||||
onBack,
|
||||
onNext,
|
||||
onFirst,
|
||||
onLast,
|
||||
}: PaginationProps) => {
|
||||
return (
|
||||
<div className={'flex gap-2 my-2 items-center justify-center'}>
|
||||
{onFirst && (
|
||||
<Button
|
||||
size="sm"
|
||||
data-testid="goto-first-page"
|
||||
disabled={isLoading || !hasPrevPage}
|
||||
className={buttonClass}
|
||||
onClick={onFirst}
|
||||
>
|
||||
<Icon name="double-chevron-left" ariaLabel="Back" />
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
size="sm"
|
||||
data-testid="goto-previous-page"
|
||||
disabled={isLoading || !hasPrevPage}
|
||||
className={buttonClass}
|
||||
onClick={onBack}
|
||||
>
|
||||
<Icon name="chevron-left" ariaLabel="Back" />
|
||||
</Button>
|
||||
{children}
|
||||
<Button
|
||||
size="sm"
|
||||
data-testid="goto-next-page"
|
||||
disabled={isLoading || !hasNextPage}
|
||||
className={buttonClass}
|
||||
onClick={onNext}
|
||||
>
|
||||
<Icon name="chevron-right" ariaLabel="Next" />
|
||||
</Button>
|
||||
{onLast && (
|
||||
<Button
|
||||
size="sm"
|
||||
data-testid="goto-last-page"
|
||||
disabled={isLoading || !hasNextPage}
|
||||
className={buttonClass}
|
||||
onClick={onLast}
|
||||
>
|
||||
<Icon name="double-chevron-right" ariaLabel="Back" />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -45,7 +45,7 @@ type CombinedData = {
|
||||
|
||||
type SubscriptionData = QueryData;
|
||||
type Delta = Data;
|
||||
type Variables = { var: string };
|
||||
type Variables = { var: string; filter?: string[] };
|
||||
|
||||
const update = jest.fn<
|
||||
ReturnType<Update<Data, Delta, Variables>>,
|
||||
@@ -231,10 +231,14 @@ describe('data provider', () => {
|
||||
clientSubscribeSubscribe.mockClear();
|
||||
});
|
||||
it('memoize instance and unsubscribe if no subscribers', () => {
|
||||
const subscription1 = subscribe(jest.fn(), client, variables);
|
||||
const subscription2 = subscribe(jest.fn(), client, { ...variables });
|
||||
// const subscription1 = subscribe(jest.fn(), client);
|
||||
// const subscription2 = subscribe(jest.fn(), client);
|
||||
const subscription1 = subscribe(jest.fn(), client, {
|
||||
...variables,
|
||||
filter: ['1', '2'],
|
||||
});
|
||||
const subscription2 = subscribe(jest.fn(), client, {
|
||||
...variables,
|
||||
filter: ['2', '1'],
|
||||
});
|
||||
expect(clientSubscribeSubscribe.mock.calls.length).toEqual(1);
|
||||
subscription1.unsubscribe();
|
||||
expect(clientSubscribeUnsubscribe.mock.calls.length).toEqual(0);
|
||||
|
||||
@@ -10,7 +10,7 @@ import type {
|
||||
} from '@apollo/client';
|
||||
import type { GraphQLErrors } from '@apollo/client/errors';
|
||||
import type { Subscription } from 'zen-observable-ts';
|
||||
import isEqual from 'lodash/isEqual';
|
||||
import isEqualWith from 'lodash/isEqualWith';
|
||||
import { isNotFoundGraphQLError } from './apollo-client';
|
||||
import type * as Schema from '@vegaprotocol/types';
|
||||
interface UpdateData<Data, Delta> {
|
||||
@@ -104,7 +104,11 @@ interface GetTotalCount<QueryData> {
|
||||
}
|
||||
|
||||
interface GetDelta<SubscriptionData, Delta, Variables> {
|
||||
(subscriptionData: SubscriptionData, variables?: Variables): Delta;
|
||||
(
|
||||
subscriptionData: SubscriptionData,
|
||||
variables: Variables,
|
||||
client: ApolloClient<object>
|
||||
): Delta;
|
||||
}
|
||||
|
||||
export type Node = { id: string };
|
||||
@@ -420,7 +424,7 @@ function makeDataProviderInternal<
|
||||
if (!subscriptionData || !getDelta || !update) {
|
||||
return;
|
||||
}
|
||||
const delta = getDelta(subscriptionData, variables);
|
||||
const delta = getDelta(subscriptionData, variables, client);
|
||||
if (loading) {
|
||||
updateQueue.push(delta);
|
||||
} else {
|
||||
@@ -512,11 +516,26 @@ function makeDataProviderInternal<
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two arrays assuming that they are sets of primitive values, used to compare gql query variables
|
||||
*/
|
||||
export const variablesIsEqualCustomizer: NonNullable<
|
||||
Parameters<typeof isEqualWith>['2']
|
||||
> = (value, other) => {
|
||||
if (Array.isArray(value) && Array.isArray(other)) {
|
||||
return (
|
||||
value.length === other.length &&
|
||||
new Set([...value, ...other]).size === value.length
|
||||
);
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
/**
|
||||
* Memoizes data provider instances using query variables as cache key
|
||||
*
|
||||
* @param fn
|
||||
* @returns subscibe function
|
||||
* @returns subscribe function
|
||||
*/
|
||||
const memoize = <
|
||||
Data,
|
||||
@@ -530,7 +549,9 @@ const memoize = <
|
||||
variables?: Variables;
|
||||
}[] = [];
|
||||
return (variables?: Variables) => {
|
||||
const cached = cache.find((c) => isEqual(c.variables, variables));
|
||||
const cached = cache.find((c) =>
|
||||
isEqualWith(c.variables, variables, variablesIsEqualCustomizer)
|
||||
);
|
||||
if (cached) {
|
||||
return cached.subscribe;
|
||||
}
|
||||
@@ -582,8 +603,10 @@ export function makeDataProvider<
|
||||
const getInstance = memoize<Data, Delta, Variables>(() =>
|
||||
makeDataProviderInternal(params)
|
||||
);
|
||||
return (callback, client, variables) =>
|
||||
getInstance(variables)(callback, client, variables);
|
||||
return (callback, client, variables) => {
|
||||
const instance = getInstance(variables)(callback, client, variables);
|
||||
return instance;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -605,7 +628,9 @@ export type CombineDerivedData<
|
||||
> = (
|
||||
data: DerivedPart<Variables>['data'][],
|
||||
variables: Variables,
|
||||
prevData: Data | null
|
||||
prevData: Data | null,
|
||||
parts: DerivedPart<Variables>[],
|
||||
subscriptions?: ReturnType<DependencySubscribe<Variables>>[]
|
||||
) => Data | null;
|
||||
|
||||
export type CombineDerivedDelta<
|
||||
@@ -687,7 +712,9 @@ function makeDerivedDataProviderInternal<
|
||||
? combineData(
|
||||
parts.map((part) => part.data),
|
||||
variables,
|
||||
data
|
||||
data,
|
||||
parts,
|
||||
subscriptions
|
||||
)
|
||||
: data;
|
||||
if (
|
||||
|
||||
Reference in New Issue
Block a user