feat: add market termination warning banner - refactoring along other banners
This commit is contained in:
@@ -3,12 +3,17 @@ import type { SingleExecutionResult } from '@apollo/client';
|
||||
import type { MockedResponse } from '@apollo/react-testing';
|
||||
import { MockedProvider } from '@apollo/react-testing';
|
||||
import { MarketSuccessorProposalBanner } from './market-successor-proposal-banner';
|
||||
import type { SuccessorProposalsListQuery } from '@vegaprotocol/proposals';
|
||||
import { SuccessorProposalsListDocument } from '@vegaprotocol/proposals';
|
||||
import type { MarketViewProposalsQuery } from '@vegaprotocol/proposals';
|
||||
import { MarketViewProposalsDocument } from '@vegaprotocol/proposals';
|
||||
import * as Types from '@vegaprotocol/types';
|
||||
|
||||
const marketProposalMock: MockedResponse<SuccessorProposalsListQuery> = {
|
||||
const marketProposalMock: MockedResponse<MarketViewProposalsQuery> = {
|
||||
request: {
|
||||
query: SuccessorProposalsListDocument,
|
||||
query: MarketViewProposalsDocument,
|
||||
variables: {
|
||||
inState: Types.ProposalState.STATE_OPEN,
|
||||
proposalType: Types.ProposalType.TYPE_NEW_MARKET,
|
||||
},
|
||||
},
|
||||
result: {
|
||||
data: {
|
||||
@@ -18,8 +23,11 @@ const marketProposalMock: MockedResponse<SuccessorProposalsListQuery> = {
|
||||
node: {
|
||||
__typename: 'Proposal',
|
||||
id: 'proposal-1',
|
||||
state: Types.ProposalState.STATE_OPEN,
|
||||
terms: {
|
||||
__typename: 'ProposalTerms',
|
||||
closingDatetime: '2023-09-27',
|
||||
enactmentDatetime: '2023-09-28',
|
||||
change: {
|
||||
__typename: 'NewMarket',
|
||||
instrument: {
|
||||
@@ -66,7 +74,7 @@ describe('MarketSuccessorProposalBanner', () => {
|
||||
proposalsConnection: {
|
||||
edges: [
|
||||
...((
|
||||
marketProposalMock?.result as SingleExecutionResult<SuccessorProposalsListQuery>
|
||||
marketProposalMock?.result as SingleExecutionResult<MarketViewProposalsQuery>
|
||||
)?.data?.proposalsConnection?.edges ?? []),
|
||||
{
|
||||
node: {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Fragment, useState } from 'react';
|
||||
import type {
|
||||
SuccessorProposalListFieldsFragment,
|
||||
MarketViewProposalFieldsFragment,
|
||||
NewMarketSuccessorFieldsFragment,
|
||||
} from '@vegaprotocol/proposals';
|
||||
import { useSuccessorProposalsListQuery } from '@vegaprotocol/proposals';
|
||||
import { useMarketViewProposals } from '@vegaprotocol/proposals';
|
||||
import {
|
||||
ExternalLink,
|
||||
Intent,
|
||||
@@ -11,23 +11,26 @@ import {
|
||||
} from '@vegaprotocol/ui-toolkit';
|
||||
import { t } from '@vegaprotocol/i18n';
|
||||
import { DApp, TOKEN_PROPOSAL, useLinks } from '@vegaprotocol/environment';
|
||||
import * as Types from '@vegaprotocol/types';
|
||||
|
||||
export const MarketSuccessorProposalBanner = ({
|
||||
marketId,
|
||||
}: {
|
||||
marketId?: string;
|
||||
}) => {
|
||||
const { data: proposals } = useSuccessorProposalsListQuery({
|
||||
const proposals = useMarketViewProposals({
|
||||
skip: !marketId,
|
||||
inState: Types.ProposalState.STATE_OPEN,
|
||||
proposalType: Types.ProposalType.TYPE_NEW_MARKET,
|
||||
typename: 'NewMarket',
|
||||
});
|
||||
|
||||
const successors =
|
||||
proposals?.proposalsConnection?.edges
|
||||
?.map((item) => item?.node as SuccessorProposalListFieldsFragment)
|
||||
.filter(
|
||||
(item: SuccessorProposalListFieldsFragment) =>
|
||||
(item.terms?.change as NewMarketSuccessorFieldsFragment)
|
||||
?.successorConfiguration?.parentMarketId === marketId
|
||||
) ?? [];
|
||||
proposals?.filter(
|
||||
(item: MarketViewProposalFieldsFragment) =>
|
||||
(item.terms?.change as NewMarketSuccessorFieldsFragment)
|
||||
?.successorConfiguration?.parentMarketId === marketId
|
||||
) ?? [];
|
||||
const [visible, setVisible] = useState(true);
|
||||
const tokenLink = useLinks(DApp.Governance);
|
||||
if (visible && successors.length) {
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
import { render, screen, waitFor } from '@testing-library/react';
|
||||
import * as Types from '@vegaprotocol/types';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
import type { MockedResponse } from '@apollo/client/testing';
|
||||
import { MockedProvider } from '@apollo/client/testing';
|
||||
import type { TerminateProposalsListQuery } from '@vegaprotocol/proposals';
|
||||
import { TerminateProposalsListDocument } from '@vegaprotocol/proposals';
|
||||
import type { MarketViewProposalsQuery } from '@vegaprotocol/proposals';
|
||||
import { MarketViewProposalsDocument } from '@vegaprotocol/proposals';
|
||||
import { MarketTerminationBanner } from './market-termination-banner';
|
||||
|
||||
const proposalMock: MockedResponse<TerminateProposalsListQuery> = {
|
||||
const proposalMock: MockedResponse<MarketViewProposalsQuery> = {
|
||||
request: {
|
||||
query: TerminateProposalsListDocument,
|
||||
variables: undefined,
|
||||
query: MarketViewProposalsDocument,
|
||||
variables: { inState: Types.ProposalState.STATE_PASSED },
|
||||
},
|
||||
result: {
|
||||
data: {
|
||||
@@ -18,6 +19,7 @@ const proposalMock: MockedResponse<TerminateProposalsListQuery> = {
|
||||
{
|
||||
node: {
|
||||
id: 'first-id',
|
||||
state: Types.ProposalState.STATE_PASSED,
|
||||
terms: {
|
||||
closingDatetime: '2023-09-27T11:48:18Z',
|
||||
enactmentDatetime: '2023-09-30T11:48:18',
|
||||
@@ -29,7 +31,8 @@ const proposalMock: MockedResponse<TerminateProposalsListQuery> = {
|
||||
id: 'market-1',
|
||||
tradableInstrument: {
|
||||
instrument: {
|
||||
name: 'Market one',
|
||||
name: 'Market one name',
|
||||
code: 'Market one',
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -40,6 +43,7 @@ const proposalMock: MockedResponse<TerminateProposalsListQuery> = {
|
||||
{
|
||||
node: {
|
||||
id: 'second-id',
|
||||
state: Types.ProposalState.STATE_PASSED,
|
||||
terms: {
|
||||
closingDatetime: '2023-09-27T11:48:18Z',
|
||||
enactmentDatetime: '2023-10-01T11:48:18',
|
||||
@@ -51,7 +55,8 @@ const proposalMock: MockedResponse<TerminateProposalsListQuery> = {
|
||||
id: 'market-2',
|
||||
tradableInstrument: {
|
||||
instrument: {
|
||||
name: 'Market two',
|
||||
name: 'Market two name',
|
||||
code: 'Market two',
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -61,7 +66,7 @@ const proposalMock: MockedResponse<TerminateProposalsListQuery> = {
|
||||
},
|
||||
],
|
||||
},
|
||||
} as unknown as TerminateProposalsListQuery,
|
||||
} as unknown as MarketViewProposalsQuery,
|
||||
},
|
||||
};
|
||||
const mocks: MockedResponse[] = [proposalMock];
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import { Link } from 'react-router-dom';
|
||||
import { Intent, NotificationBanner } from '@vegaprotocol/ui-toolkit';
|
||||
import { useState } from 'react';
|
||||
import { useGetTerminationProposals } from '@vegaprotocol/proposals';
|
||||
import { format, formatDuration, intervalToDuration } from 'date-fns';
|
||||
import { Intent, NotificationBanner } from '@vegaprotocol/ui-toolkit';
|
||||
import { useMarketViewProposals } from '@vegaprotocol/proposals';
|
||||
import { t } from '@vegaprotocol/i18n';
|
||||
import { formatDateWithLocalTimezone } from '@vegaprotocol/utils';
|
||||
import { formatDuration, intervalToDuration } from 'date-fns';
|
||||
import { Links } from '../../lib/links';
|
||||
import * as Types from '@vegaprotocol/types';
|
||||
|
||||
export const MarketTerminationBanner = ({
|
||||
marketId,
|
||||
@@ -13,26 +11,29 @@ export const MarketTerminationBanner = ({
|
||||
marketId?: string;
|
||||
}) => {
|
||||
const [visible, setVisible] = useState(true);
|
||||
|
||||
const skip = !marketId || !visible;
|
||||
const proposalsData = useGetTerminationProposals({ skip });
|
||||
const proposalsData = useMarketViewProposals({
|
||||
skip,
|
||||
inState: Types.ProposalState.STATE_PASSED,
|
||||
typename: 'UpdateMarketState',
|
||||
});
|
||||
|
||||
if (!marketId) return null;
|
||||
const marketFound = (proposalsData || []).find(
|
||||
(item) =>
|
||||
item.terms.change.__typename === 'UpdateMarketState' &&
|
||||
item.terms.change.market.id === marketId
|
||||
item.terms.change.market.id === marketId &&
|
||||
item.state === Types.ProposalState.STATE_PASSED // subscription doesn't have state parameter
|
||||
);
|
||||
|
||||
const enactmentDatetime = new Date(marketFound?.terms.enactmentDatetime);
|
||||
const name =
|
||||
marketFound?.terms.change.__typename === 'UpdateMarketState'
|
||||
? marketFound.terms.change.market.tradableInstrument.instrument.name
|
||||
? marketFound.terms.change.market.tradableInstrument.instrument.code
|
||||
: '';
|
||||
|
||||
if (name && enactmentDatetime && enactmentDatetime.getTime() > Date.now()) {
|
||||
const dayMonthDate = formatDateWithLocalTimezone(
|
||||
enactmentDatetime,
|
||||
'dd MMMM'
|
||||
);
|
||||
if (name && enactmentDatetime.getTime() > Date.now()) {
|
||||
const dayMonthDate = format(enactmentDatetime, 'dd MMMM');
|
||||
const duration = intervalToDuration({
|
||||
start: new Date(),
|
||||
end: enactmentDatetime,
|
||||
@@ -53,9 +54,8 @@ export const MarketTerminationBanner = ({
|
||||
{t('Trading on Market %s will stop on %s', [name, dayMonthDate])}
|
||||
</div>
|
||||
<div>
|
||||
{t('Market')} <Link to={Links.MARKET(marketId)}>{name}</Link>
|
||||
{t(
|
||||
'will close to trading in %s. You will not be able to hold a position on this market after %s.',
|
||||
'This market will close to trading in %s. You will not be able to hold a position on this market after %s.',
|
||||
[formattedDuration, dayMonthDate]
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -4,6 +4,7 @@ fragment UpdateMarketStateFields on UpdateMarketState {
|
||||
tradableInstrument {
|
||||
instrument {
|
||||
name
|
||||
code
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -421,32 +422,9 @@ fragment NewMarketSuccessorFields on NewMarket {
|
||||
}
|
||||
}
|
||||
|
||||
fragment SuccessorProposalListFields on Proposal {
|
||||
id
|
||||
terms {
|
||||
change {
|
||||
... on NewMarket {
|
||||
...NewMarketSuccessorFields
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
query SuccessorProposalsList {
|
||||
proposalsConnection(proposalType: TYPE_NEW_MARKET, inState: STATE_OPEN) {
|
||||
edges {
|
||||
node {
|
||||
...SuccessorProposalListFields
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fragment TerminateProposalsListFields on Proposal {
|
||||
fragment MarketViewProposalFields on Proposal {
|
||||
id
|
||||
state
|
||||
datetime
|
||||
rejectionReason
|
||||
terms {
|
||||
closingDatetime
|
||||
enactmentDatetime
|
||||
@@ -455,22 +433,28 @@ fragment TerminateProposalsListFields on Proposal {
|
||||
... on UpdateMarketState {
|
||||
...UpdateMarketStateFields
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
query TerminateProposalsList {
|
||||
proposalsConnection(inState: STATE_PASSED) {
|
||||
edges {
|
||||
node {
|
||||
...TerminateProposalsListFields
|
||||
... on NewMarket {
|
||||
...NewMarketSuccessorFields
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
subscription TerminateLiveProposals {
|
||||
query MarketViewProposals(
|
||||
$proposalType: ProposalType
|
||||
$inState: ProposalState
|
||||
) {
|
||||
proposalsConnection(proposalType: $proposalType, inState: $inState) {
|
||||
edges {
|
||||
node {
|
||||
...MarketViewProposalFields
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
subscription MarketViewLiveProposals {
|
||||
proposals {
|
||||
...TerminateProposalsListFields
|
||||
...MarketViewProposalFields
|
||||
}
|
||||
}
|
||||
|
||||
+61
-110
@@ -3,7 +3,7 @@ import * as Types from '@vegaprotocol/types';
|
||||
import { gql } from '@apollo/client';
|
||||
import * as Apollo from '@apollo/client';
|
||||
const defaultOptions = {} as const;
|
||||
export type UpdateMarketStateFieldsFragment = { __typename?: 'UpdateMarketState', updateType: Types.MarketUpdateType, price?: string | null, market: { __typename?: 'Market', id: string, tradableInstrument: { __typename?: 'TradableInstrument', instrument: { __typename?: 'Instrument', name: string } } } };
|
||||
export type UpdateMarketStateFieldsFragment = { __typename?: 'UpdateMarketState', updateType: Types.MarketUpdateType, price?: string | null, market: { __typename?: 'Market', id: string, tradableInstrument: { __typename?: 'TradableInstrument', instrument: { __typename?: 'Instrument', name: string, code: string } } } };
|
||||
|
||||
export type NewMarketFieldsFragment = { __typename?: 'NewMarket', decimalPlaces: number, metadata?: Array<string> | null, instrument: { __typename?: 'InstrumentConfiguration', name: string, code: string, futureProduct?: { __typename?: 'FutureProduct', quoteName: string, settlementAsset: { __typename?: 'Asset', id: string, name: string, symbol: string, decimals: number, quantum: string }, dataSourceSpecForSettlementData: { __typename?: 'DataSourceDefinition', sourceType: { __typename?: 'DataSourceDefinitionExternal', sourceType: { __typename?: 'DataSourceSpecConfiguration', signers?: Array<{ __typename?: 'Signer', signer: { __typename?: 'ETHAddress', address?: string | null } | { __typename?: 'PubKey', key?: string | null } }> | null, filters?: Array<{ __typename?: 'Filter', key: { __typename?: 'PropertyKey', name?: string | null, type: Types.PropertyKeyType }, conditions?: Array<{ __typename?: 'Condition', operator: Types.ConditionOperator, value?: string | null }> | null }> | null } | { __typename?: 'EthCallSpec' } } | { __typename?: 'DataSourceDefinitionInternal' } }, dataSourceSpecForTradingTermination: { __typename?: 'DataSourceDefinition', sourceType: { __typename?: 'DataSourceDefinitionExternal', sourceType: { __typename?: 'DataSourceSpecConfiguration', signers?: Array<{ __typename?: 'Signer', signer: { __typename?: 'ETHAddress', address?: string | null } | { __typename?: 'PubKey', key?: string | null } }> | null, filters?: Array<{ __typename?: 'Filter', key: { __typename?: 'PropertyKey', name?: string | null, type: Types.PropertyKeyType }, conditions?: Array<{ __typename?: 'Condition', operator: Types.ConditionOperator, value?: string | null }> | null }> | null } | { __typename?: 'EthCallSpec' } } | { __typename?: 'DataSourceDefinitionInternal' } }, dataSourceSpecBinding: { __typename?: 'DataSourceSpecToFutureBinding', settlementDataProperty: string, tradingTerminationProperty: string } } | null }, riskParameters: { __typename?: 'LogNormalRiskModel', riskAversionParameter: number, tau: number, params: { __typename?: 'LogNormalModelParams', mu: number, r: number, sigma: number } } | { __typename?: 'SimpleRiskModel', params: { __typename?: 'SimpleRiskModelParams', factorLong: number, factorShort: number } }, successorConfiguration?: { __typename?: 'SuccessorConfiguration', parentMarketId: string } | null };
|
||||
|
||||
@@ -27,24 +27,20 @@ export type ProposalsListQuery = { __typename?: 'Query', proposalsConnection?: {
|
||||
|
||||
export type NewMarketSuccessorFieldsFragment = { __typename?: 'NewMarket', instrument: { __typename?: 'InstrumentConfiguration', name: string }, successorConfiguration?: { __typename?: 'SuccessorConfiguration', parentMarketId: string } | null };
|
||||
|
||||
export type SuccessorProposalListFieldsFragment = { __typename?: 'Proposal', id?: string | null, terms: { __typename?: 'ProposalTerms', change: { __typename?: 'CancelTransfer' } | { __typename?: 'NewAsset' } | { __typename?: 'NewFreeform' } | { __typename?: 'NewMarket', instrument: { __typename?: 'InstrumentConfiguration', name: string }, successorConfiguration?: { __typename?: 'SuccessorConfiguration', parentMarketId: string } | null } | { __typename?: 'NewSpotMarket' } | { __typename?: 'NewTransfer' } | { __typename?: 'UpdateAsset' } | { __typename?: 'UpdateMarket' } | { __typename?: 'UpdateMarketState' } | { __typename?: 'UpdateNetworkParameter' } | { __typename?: 'UpdateReferralProgram' } | { __typename?: 'UpdateSpotMarket' } | { __typename?: 'UpdateVolumeDiscountProgram' } } };
|
||||
export type MarketViewProposalFieldsFragment = { __typename?: 'Proposal', id?: string | null, state: Types.ProposalState, terms: { __typename?: 'ProposalTerms', closingDatetime: any, enactmentDatetime?: any | null, change: { __typename: 'CancelTransfer' } | { __typename: 'NewAsset' } | { __typename: 'NewFreeform' } | { __typename: 'NewMarket', instrument: { __typename?: 'InstrumentConfiguration', name: string }, successorConfiguration?: { __typename?: 'SuccessorConfiguration', parentMarketId: string } | null } | { __typename: 'NewSpotMarket' } | { __typename: 'NewTransfer' } | { __typename: 'UpdateAsset' } | { __typename: 'UpdateMarket' } | { __typename: 'UpdateMarketState', updateType: Types.MarketUpdateType, price?: string | null, market: { __typename?: 'Market', id: string, tradableInstrument: { __typename?: 'TradableInstrument', instrument: { __typename?: 'Instrument', name: string, code: string } } } } | { __typename: 'UpdateNetworkParameter' } | { __typename: 'UpdateReferralProgram' } | { __typename: 'UpdateSpotMarket' } | { __typename: 'UpdateVolumeDiscountProgram' } } };
|
||||
|
||||
export type SuccessorProposalsListQueryVariables = Types.Exact<{ [key: string]: never; }>;
|
||||
export type MarketViewProposalsQueryVariables = Types.Exact<{
|
||||
proposalType?: Types.InputMaybe<Types.ProposalType>;
|
||||
inState?: Types.InputMaybe<Types.ProposalState>;
|
||||
}>;
|
||||
|
||||
|
||||
export type SuccessorProposalsListQuery = { __typename?: 'Query', proposalsConnection?: { __typename?: 'ProposalsConnection', edges?: Array<{ __typename?: 'ProposalEdge', node: { __typename?: 'Proposal', id?: string | null, terms: { __typename?: 'ProposalTerms', change: { __typename?: 'CancelTransfer' } | { __typename?: 'NewAsset' } | { __typename?: 'NewFreeform' } | { __typename?: 'NewMarket', instrument: { __typename?: 'InstrumentConfiguration', name: string }, successorConfiguration?: { __typename?: 'SuccessorConfiguration', parentMarketId: string } | null } | { __typename?: 'NewSpotMarket' } | { __typename?: 'NewTransfer' } | { __typename?: 'UpdateAsset' } | { __typename?: 'UpdateMarket' } | { __typename?: 'UpdateMarketState' } | { __typename?: 'UpdateNetworkParameter' } | { __typename?: 'UpdateReferralProgram' } | { __typename?: 'UpdateSpotMarket' } | { __typename?: 'UpdateVolumeDiscountProgram' } } } } | null> | null } | null };
|
||||
export type MarketViewProposalsQuery = { __typename?: 'Query', proposalsConnection?: { __typename?: 'ProposalsConnection', edges?: Array<{ __typename?: 'ProposalEdge', node: { __typename?: 'Proposal', id?: string | null, state: Types.ProposalState, terms: { __typename?: 'ProposalTerms', closingDatetime: any, enactmentDatetime?: any | null, change: { __typename: 'CancelTransfer' } | { __typename: 'NewAsset' } | { __typename: 'NewFreeform' } | { __typename: 'NewMarket', instrument: { __typename?: 'InstrumentConfiguration', name: string }, successorConfiguration?: { __typename?: 'SuccessorConfiguration', parentMarketId: string } | null } | { __typename: 'NewSpotMarket' } | { __typename: 'NewTransfer' } | { __typename: 'UpdateAsset' } | { __typename: 'UpdateMarket' } | { __typename: 'UpdateMarketState', updateType: Types.MarketUpdateType, price?: string | null, market: { __typename?: 'Market', id: string, tradableInstrument: { __typename?: 'TradableInstrument', instrument: { __typename?: 'Instrument', name: string, code: string } } } } | { __typename: 'UpdateNetworkParameter' } | { __typename: 'UpdateReferralProgram' } | { __typename: 'UpdateSpotMarket' } | { __typename: 'UpdateVolumeDiscountProgram' } } } } | null> | null } | null };
|
||||
|
||||
export type TerminateProposalsListFieldsFragment = { __typename?: 'Proposal', id?: string | null, state: Types.ProposalState, datetime: any, rejectionReason?: Types.ProposalRejectionReason | null, terms: { __typename?: 'ProposalTerms', closingDatetime: any, enactmentDatetime?: any | null, change: { __typename: 'CancelTransfer' } | { __typename: 'NewAsset' } | { __typename: 'NewFreeform' } | { __typename: 'NewMarket' } | { __typename: 'NewSpotMarket' } | { __typename: 'NewTransfer' } | { __typename: 'UpdateAsset' } | { __typename: 'UpdateMarket' } | { __typename: 'UpdateMarketState', updateType: Types.MarketUpdateType, price?: string | null, market: { __typename?: 'Market', id: string, tradableInstrument: { __typename?: 'TradableInstrument', instrument: { __typename?: 'Instrument', name: string } } } } | { __typename: 'UpdateNetworkParameter' } | { __typename: 'UpdateReferralProgram' } | { __typename: 'UpdateSpotMarket' } | { __typename: 'UpdateVolumeDiscountProgram' } } };
|
||||
|
||||
export type TerminateProposalsListQueryVariables = Types.Exact<{ [key: string]: never; }>;
|
||||
export type MarketViewLiveProposalsSubscriptionVariables = Types.Exact<{ [key: string]: never; }>;
|
||||
|
||||
|
||||
export type TerminateProposalsListQuery = { __typename?: 'Query', proposalsConnection?: { __typename?: 'ProposalsConnection', edges?: Array<{ __typename?: 'ProposalEdge', node: { __typename?: 'Proposal', id?: string | null, state: Types.ProposalState, datetime: any, rejectionReason?: Types.ProposalRejectionReason | null, terms: { __typename?: 'ProposalTerms', closingDatetime: any, enactmentDatetime?: any | null, change: { __typename: 'CancelTransfer' } | { __typename: 'NewAsset' } | { __typename: 'NewFreeform' } | { __typename: 'NewMarket' } | { __typename: 'NewSpotMarket' } | { __typename: 'NewTransfer' } | { __typename: 'UpdateAsset' } | { __typename: 'UpdateMarket' } | { __typename: 'UpdateMarketState', updateType: Types.MarketUpdateType, price?: string | null, market: { __typename?: 'Market', id: string, tradableInstrument: { __typename?: 'TradableInstrument', instrument: { __typename?: 'Instrument', name: string } } } } | { __typename: 'UpdateNetworkParameter' } | { __typename: 'UpdateReferralProgram' } | { __typename: 'UpdateSpotMarket' } | { __typename: 'UpdateVolumeDiscountProgram' } } } } | null> | null } | null };
|
||||
|
||||
export type TerminateLiveProposalsSubscriptionVariables = Types.Exact<{ [key: string]: never; }>;
|
||||
|
||||
|
||||
export type TerminateLiveProposalsSubscription = { __typename?: 'Subscription', proposals: { __typename?: 'Proposal', id?: string | null, state: Types.ProposalState, datetime: any, rejectionReason?: Types.ProposalRejectionReason | null, terms: { __typename?: 'ProposalTerms', closingDatetime: any, enactmentDatetime?: any | null, change: { __typename: 'CancelTransfer' } | { __typename: 'NewAsset' } | { __typename: 'NewFreeform' } | { __typename: 'NewMarket' } | { __typename: 'NewSpotMarket' } | { __typename: 'NewTransfer' } | { __typename: 'UpdateAsset' } | { __typename: 'UpdateMarket' } | { __typename: 'UpdateMarketState', updateType: Types.MarketUpdateType, price?: string | null, market: { __typename?: 'Market', id: string, tradableInstrument: { __typename?: 'TradableInstrument', instrument: { __typename?: 'Instrument', name: string } } } } | { __typename: 'UpdateNetworkParameter' } | { __typename: 'UpdateReferralProgram' } | { __typename: 'UpdateSpotMarket' } | { __typename: 'UpdateVolumeDiscountProgram' } } } };
|
||||
export type MarketViewLiveProposalsSubscription = { __typename?: 'Subscription', proposals: { __typename?: 'Proposal', id?: string | null, state: Types.ProposalState, terms: { __typename?: 'ProposalTerms', closingDatetime: any, enactmentDatetime?: any | null, change: { __typename: 'CancelTransfer' } | { __typename: 'NewAsset' } | { __typename: 'NewFreeform' } | { __typename: 'NewMarket', instrument: { __typename?: 'InstrumentConfiguration', name: string }, successorConfiguration?: { __typename?: 'SuccessorConfiguration', parentMarketId: string } | null } | { __typename: 'NewSpotMarket' } | { __typename: 'NewTransfer' } | { __typename: 'UpdateAsset' } | { __typename: 'UpdateMarket' } | { __typename: 'UpdateMarketState', updateType: Types.MarketUpdateType, price?: string | null, market: { __typename?: 'Market', id: string, tradableInstrument: { __typename?: 'TradableInstrument', instrument: { __typename?: 'Instrument', name: string, code: string } } } } | { __typename: 'UpdateNetworkParameter' } | { __typename: 'UpdateReferralProgram' } | { __typename: 'UpdateSpotMarket' } | { __typename: 'UpdateVolumeDiscountProgram' } } } };
|
||||
|
||||
export const NewMarketFieldsFragmentDoc = gql`
|
||||
fragment NewMarketFields on NewMarket {
|
||||
@@ -429,6 +425,21 @@ ${UpdateMarketFieldsFragmentDoc}
|
||||
${NewAssetFieldsFragmentDoc}
|
||||
${UpdateAssetFieldsFragmentDoc}
|
||||
${UpdateNetworkParameterFieldsFragmentDoc}`;
|
||||
export const UpdateMarketStateFieldsFragmentDoc = gql`
|
||||
fragment UpdateMarketStateFields on UpdateMarketState {
|
||||
market {
|
||||
id
|
||||
tradableInstrument {
|
||||
instrument {
|
||||
name
|
||||
code
|
||||
}
|
||||
}
|
||||
}
|
||||
updateType
|
||||
price
|
||||
}
|
||||
`;
|
||||
export const NewMarketSuccessorFieldsFragmentDoc = gql`
|
||||
fragment NewMarketSuccessorFields on NewMarket {
|
||||
instrument {
|
||||
@@ -439,38 +450,10 @@ export const NewMarketSuccessorFieldsFragmentDoc = gql`
|
||||
}
|
||||
}
|
||||
`;
|
||||
export const SuccessorProposalListFieldsFragmentDoc = gql`
|
||||
fragment SuccessorProposalListFields on Proposal {
|
||||
id
|
||||
terms {
|
||||
change {
|
||||
... on NewMarket {
|
||||
...NewMarketSuccessorFields
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
${NewMarketSuccessorFieldsFragmentDoc}`;
|
||||
export const UpdateMarketStateFieldsFragmentDoc = gql`
|
||||
fragment UpdateMarketStateFields on UpdateMarketState {
|
||||
market {
|
||||
id
|
||||
tradableInstrument {
|
||||
instrument {
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
updateType
|
||||
price
|
||||
}
|
||||
`;
|
||||
export const TerminateProposalsListFieldsFragmentDoc = gql`
|
||||
fragment TerminateProposalsListFields on Proposal {
|
||||
export const MarketViewProposalFieldsFragmentDoc = gql`
|
||||
fragment MarketViewProposalFields on Proposal {
|
||||
id
|
||||
state
|
||||
datetime
|
||||
rejectionReason
|
||||
terms {
|
||||
closingDatetime
|
||||
enactmentDatetime
|
||||
@@ -479,10 +462,14 @@ export const TerminateProposalsListFieldsFragmentDoc = gql`
|
||||
... on UpdateMarketState {
|
||||
...UpdateMarketStateFields
|
||||
}
|
||||
... on NewMarket {
|
||||
...NewMarketSuccessorFields
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
${UpdateMarketStateFieldsFragmentDoc}`;
|
||||
${UpdateMarketStateFieldsFragmentDoc}
|
||||
${NewMarketSuccessorFieldsFragmentDoc}`;
|
||||
export const ProposalsListDocument = gql`
|
||||
query ProposalsList($proposalType: ProposalType, $inState: ProposalState) {
|
||||
proposalsConnection(proposalType: $proposalType, inState: $inState) {
|
||||
@@ -523,108 +510,72 @@ export function useProposalsListLazyQuery(baseOptions?: Apollo.LazyQueryHookOpti
|
||||
export type ProposalsListQueryHookResult = ReturnType<typeof useProposalsListQuery>;
|
||||
export type ProposalsListLazyQueryHookResult = ReturnType<typeof useProposalsListLazyQuery>;
|
||||
export type ProposalsListQueryResult = Apollo.QueryResult<ProposalsListQuery, ProposalsListQueryVariables>;
|
||||
export const SuccessorProposalsListDocument = gql`
|
||||
query SuccessorProposalsList {
|
||||
proposalsConnection(proposalType: TYPE_NEW_MARKET, inState: STATE_OPEN) {
|
||||
export const MarketViewProposalsDocument = gql`
|
||||
query MarketViewProposals($proposalType: ProposalType, $inState: ProposalState) {
|
||||
proposalsConnection(proposalType: $proposalType, inState: $inState) {
|
||||
edges {
|
||||
node {
|
||||
...SuccessorProposalListFields
|
||||
...MarketViewProposalFields
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
${SuccessorProposalListFieldsFragmentDoc}`;
|
||||
${MarketViewProposalFieldsFragmentDoc}`;
|
||||
|
||||
/**
|
||||
* __useSuccessorProposalsListQuery__
|
||||
* __useMarketViewProposalsQuery__
|
||||
*
|
||||
* To run a query within a React component, call `useSuccessorProposalsListQuery` and pass it any options that fit your needs.
|
||||
* When your component renders, `useSuccessorProposalsListQuery` returns an object from Apollo Client that contains loading, error, and data properties
|
||||
* To run a query within a React component, call `useMarketViewProposalsQuery` and pass it any options that fit your needs.
|
||||
* When your component renders, `useMarketViewProposalsQuery` returns an object from Apollo Client that contains loading, error, and data properties
|
||||
* you can use to render your UI.
|
||||
*
|
||||
* @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
|
||||
*
|
||||
* @example
|
||||
* const { data, loading, error } = useSuccessorProposalsListQuery({
|
||||
* const { data, loading, error } = useMarketViewProposalsQuery({
|
||||
* variables: {
|
||||
* proposalType: // value for 'proposalType'
|
||||
* inState: // value for 'inState'
|
||||
* },
|
||||
* });
|
||||
*/
|
||||
export function useSuccessorProposalsListQuery(baseOptions?: Apollo.QueryHookOptions<SuccessorProposalsListQuery, SuccessorProposalsListQueryVariables>) {
|
||||
export function useMarketViewProposalsQuery(baseOptions?: Apollo.QueryHookOptions<MarketViewProposalsQuery, MarketViewProposalsQueryVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useQuery<SuccessorProposalsListQuery, SuccessorProposalsListQueryVariables>(SuccessorProposalsListDocument, options);
|
||||
return Apollo.useQuery<MarketViewProposalsQuery, MarketViewProposalsQueryVariables>(MarketViewProposalsDocument, options);
|
||||
}
|
||||
export function useSuccessorProposalsListLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<SuccessorProposalsListQuery, SuccessorProposalsListQueryVariables>) {
|
||||
export function useMarketViewProposalsLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<MarketViewProposalsQuery, MarketViewProposalsQueryVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useLazyQuery<SuccessorProposalsListQuery, SuccessorProposalsListQueryVariables>(SuccessorProposalsListDocument, options);
|
||||
return Apollo.useLazyQuery<MarketViewProposalsQuery, MarketViewProposalsQueryVariables>(MarketViewProposalsDocument, options);
|
||||
}
|
||||
export type SuccessorProposalsListQueryHookResult = ReturnType<typeof useSuccessorProposalsListQuery>;
|
||||
export type SuccessorProposalsListLazyQueryHookResult = ReturnType<typeof useSuccessorProposalsListLazyQuery>;
|
||||
export type SuccessorProposalsListQueryResult = Apollo.QueryResult<SuccessorProposalsListQuery, SuccessorProposalsListQueryVariables>;
|
||||
export const TerminateProposalsListDocument = gql`
|
||||
query TerminateProposalsList {
|
||||
proposalsConnection(inState: STATE_PASSED) {
|
||||
edges {
|
||||
node {
|
||||
...TerminateProposalsListFields
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
${TerminateProposalsListFieldsFragmentDoc}`;
|
||||
|
||||
/**
|
||||
* __useTerminateProposalsListQuery__
|
||||
*
|
||||
* To run a query within a React component, call `useTerminateProposalsListQuery` and pass it any options that fit your needs.
|
||||
* When your component renders, `useTerminateProposalsListQuery` returns an object from Apollo Client that contains loading, error, and data properties
|
||||
* you can use to render your UI.
|
||||
*
|
||||
* @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
|
||||
*
|
||||
* @example
|
||||
* const { data, loading, error } = useTerminateProposalsListQuery({
|
||||
* variables: {
|
||||
* },
|
||||
* });
|
||||
*/
|
||||
export function useTerminateProposalsListQuery(baseOptions?: Apollo.QueryHookOptions<TerminateProposalsListQuery, TerminateProposalsListQueryVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useQuery<TerminateProposalsListQuery, TerminateProposalsListQueryVariables>(TerminateProposalsListDocument, options);
|
||||
}
|
||||
export function useTerminateProposalsListLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<TerminateProposalsListQuery, TerminateProposalsListQueryVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useLazyQuery<TerminateProposalsListQuery, TerminateProposalsListQueryVariables>(TerminateProposalsListDocument, options);
|
||||
}
|
||||
export type TerminateProposalsListQueryHookResult = ReturnType<typeof useTerminateProposalsListQuery>;
|
||||
export type TerminateProposalsListLazyQueryHookResult = ReturnType<typeof useTerminateProposalsListLazyQuery>;
|
||||
export type TerminateProposalsListQueryResult = Apollo.QueryResult<TerminateProposalsListQuery, TerminateProposalsListQueryVariables>;
|
||||
export const TerminateLiveProposalsDocument = gql`
|
||||
subscription TerminateLiveProposals {
|
||||
export type MarketViewProposalsQueryHookResult = ReturnType<typeof useMarketViewProposalsQuery>;
|
||||
export type MarketViewProposalsLazyQueryHookResult = ReturnType<typeof useMarketViewProposalsLazyQuery>;
|
||||
export type MarketViewProposalsQueryResult = Apollo.QueryResult<MarketViewProposalsQuery, MarketViewProposalsQueryVariables>;
|
||||
export const MarketViewLiveProposalsDocument = gql`
|
||||
subscription MarketViewLiveProposals {
|
||||
proposals {
|
||||
...TerminateProposalsListFields
|
||||
...MarketViewProposalFields
|
||||
}
|
||||
}
|
||||
${TerminateProposalsListFieldsFragmentDoc}`;
|
||||
${MarketViewProposalFieldsFragmentDoc}`;
|
||||
|
||||
/**
|
||||
* __useTerminateLiveProposalsSubscription__
|
||||
* __useMarketViewLiveProposalsSubscription__
|
||||
*
|
||||
* To run a query within a React component, call `useTerminateLiveProposalsSubscription` and pass it any options that fit your needs.
|
||||
* When your component renders, `useTerminateLiveProposalsSubscription` returns an object from Apollo Client that contains loading, error, and data properties
|
||||
* To run a query within a React component, call `useMarketViewLiveProposalsSubscription` and pass it any options that fit your needs.
|
||||
* When your component renders, `useMarketViewLiveProposalsSubscription` returns an object from Apollo Client that contains loading, error, and data properties
|
||||
* you can use to render your UI.
|
||||
*
|
||||
* @param baseOptions options that will be passed into the subscription, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
|
||||
*
|
||||
* @example
|
||||
* const { data, loading, error } = useTerminateLiveProposalsSubscription({
|
||||
* const { data, loading, error } = useMarketViewLiveProposalsSubscription({
|
||||
* variables: {
|
||||
* },
|
||||
* });
|
||||
*/
|
||||
export function useTerminateLiveProposalsSubscription(baseOptions?: Apollo.SubscriptionHookOptions<TerminateLiveProposalsSubscription, TerminateLiveProposalsSubscriptionVariables>) {
|
||||
export function useMarketViewLiveProposalsSubscription(baseOptions?: Apollo.SubscriptionHookOptions<MarketViewLiveProposalsSubscription, MarketViewLiveProposalsSubscriptionVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useSubscription<TerminateLiveProposalsSubscription, TerminateLiveProposalsSubscriptionVariables>(TerminateLiveProposalsDocument, options);
|
||||
return Apollo.useSubscription<MarketViewLiveProposalsSubscription, MarketViewLiveProposalsSubscriptionVariables>(MarketViewLiveProposalsDocument, options);
|
||||
}
|
||||
export type TerminateLiveProposalsSubscriptionHookResult = ReturnType<typeof useTerminateLiveProposalsSubscription>;
|
||||
export type TerminateLiveProposalsSubscriptionResult = Apollo.SubscriptionResult<TerminateLiveProposalsSubscription>;
|
||||
export type MarketViewLiveProposalsSubscriptionHookResult = ReturnType<typeof useMarketViewLiveProposalsSubscription>;
|
||||
export type MarketViewLiveProposalsSubscriptionResult = Apollo.SubscriptionResult<MarketViewLiveProposalsSubscription>;
|
||||
@@ -4,14 +4,15 @@ import type {
|
||||
ProposalsListQuery,
|
||||
ProposalsListQueryVariables,
|
||||
ProposalListFieldsFragment,
|
||||
TerminateLiveProposalsSubscription,
|
||||
TerminateProposalsListFieldsFragment,
|
||||
TerminateProposalsListQuery,
|
||||
MarketViewLiveProposalsSubscription,
|
||||
MarketViewProposalFieldsFragment,
|
||||
MarketViewProposalsQuery,
|
||||
MarketViewProposalsQueryVariables,
|
||||
} from './__generated__/Proposals';
|
||||
import {
|
||||
MarketViewLiveProposalsDocument,
|
||||
MarketViewProposalsDocument,
|
||||
ProposalsListDocument,
|
||||
TerminateLiveProposalsDocument,
|
||||
TerminateProposalsListDocument,
|
||||
} from './__generated__/Proposals';
|
||||
import { removePaginationWrapper } from '@vegaprotocol/utils';
|
||||
|
||||
@@ -42,8 +43,8 @@ export const proposalsDataProvider = makeDataProvider<
|
||||
});
|
||||
|
||||
const update = (
|
||||
data: TerminateProposalsListFieldsFragment[] | null,
|
||||
delta: TerminateProposalsListFieldsFragment
|
||||
data: MarketViewProposalFieldsFragment[] | null,
|
||||
delta: MarketViewProposalFieldsFragment
|
||||
) => {
|
||||
const updateData = produce(data || [], (draft) => {
|
||||
const { id } = delta;
|
||||
@@ -61,20 +62,21 @@ const update = (
|
||||
return updateData;
|
||||
};
|
||||
|
||||
const getTerminateProposalsData = (
|
||||
responseData: TerminateProposalsListQuery | null
|
||||
const getMarketProposalsData = (
|
||||
responseData: MarketViewProposalsQuery | null
|
||||
) => removePaginationWrapper(responseData?.proposalsConnection?.edges) || [];
|
||||
|
||||
export const proposalTerminateDataProvider = makeDataProvider<
|
||||
TerminateProposalsListQuery,
|
||||
TerminateProposalsListFieldsFragment[],
|
||||
TerminateLiveProposalsSubscription,
|
||||
TerminateProposalsListFieldsFragment
|
||||
export const marketViewProposalsDataProvider = makeDataProvider<
|
||||
MarketViewProposalsQuery,
|
||||
MarketViewProposalFieldsFragment[],
|
||||
MarketViewLiveProposalsSubscription,
|
||||
MarketViewProposalFieldsFragment,
|
||||
MarketViewProposalsQueryVariables
|
||||
>({
|
||||
query: TerminateProposalsListDocument,
|
||||
subscriptionQuery: TerminateLiveProposalsDocument,
|
||||
query: MarketViewProposalsDocument,
|
||||
subscriptionQuery: MarketViewLiveProposalsDocument,
|
||||
update,
|
||||
getDelta: (subscriptionData: TerminateLiveProposalsSubscription) =>
|
||||
getDelta: (subscriptionData: MarketViewLiveProposalsSubscription) =>
|
||||
subscriptionData.proposals,
|
||||
getData: getTerminateProposalsData,
|
||||
getData: getMarketProposalsData,
|
||||
});
|
||||
|
||||
@@ -4,4 +4,4 @@ export * from './use-proposal-submit';
|
||||
export * from './use-update-proposal';
|
||||
export * from './use-update-network-paramaters-toasts';
|
||||
export * from './use-successor-market-proposal-details';
|
||||
export * from './use-get-termination-proposals';
|
||||
export * from './use-market-view-proposals';
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
import { useDataProvider } from '@vegaprotocol/data-provider';
|
||||
import { proposalTerminateDataProvider } from '../proposals-data-provider';
|
||||
|
||||
export const useGetTerminationProposals = ({
|
||||
skip = false,
|
||||
}: {
|
||||
skip?: boolean;
|
||||
}) => {
|
||||
const { data } = useDataProvider({
|
||||
dataProvider: proposalTerminateDataProvider,
|
||||
skip,
|
||||
variables: undefined,
|
||||
});
|
||||
return (data || []).filter(
|
||||
(item) => item.terms.change.__typename === 'UpdateMarketState'
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
import { useDataProvider } from '@vegaprotocol/data-provider';
|
||||
import { marketViewProposalsDataProvider } from '../proposals-data-provider';
|
||||
import type * as Types from '@vegaprotocol/types';
|
||||
|
||||
export const useMarketViewProposals = ({
|
||||
skip = false,
|
||||
typename,
|
||||
proposalType,
|
||||
inState,
|
||||
}: {
|
||||
typename: string;
|
||||
skip?: boolean;
|
||||
inState: Types.ProposalState;
|
||||
proposalType?: Types.ProposalType;
|
||||
}) => {
|
||||
const variables = {
|
||||
inState,
|
||||
...(proposalType ? { proposalType } : null),
|
||||
};
|
||||
|
||||
const { data } = useDataProvider({
|
||||
dataProvider: marketViewProposalsDataProvider,
|
||||
skip,
|
||||
variables,
|
||||
});
|
||||
return (data || []).filter(
|
||||
(item) => item.terms.change.__typename === typename
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user