fix: circ dep by moving proposed markets to app

This commit is contained in:
Matthew Russell 2024-03-09 15:55:00 +00:00
parent 05b39e2c08
commit d67c7efb4f
No known key found for this signature in database
14 changed files with 116 additions and 96 deletions

View File

@ -0,0 +1 @@
export { ProposalsList } from './proposals-list';

View File

@ -6,7 +6,7 @@ import {
ActionsDropdown, ActionsDropdown,
} from '@vegaprotocol/ui-toolkit'; } from '@vegaprotocol/ui-toolkit';
import { DApp, TOKEN_PROPOSAL, useLinks } from '@vegaprotocol/environment'; import { DApp, TOKEN_PROPOSAL, useLinks } from '@vegaprotocol/environment';
import { useT } from '../use-t'; import { useT } from '../../../lib/use-t';
export const ProposalActionsDropdown = ({ id }: { id: string }) => { export const ProposalActionsDropdown = ({ id }: { id: string }) => {
const t = useT(); const t = useT();
@ -18,6 +18,7 @@ export const ProposalActionsDropdown = ({ id }: { id: string }) => {
<Link <Link
href={linkCreator(TOKEN_PROPOSAL.replace(':id', id))} href={linkCreator(TOKEN_PROPOSAL.replace(':id', id))}
target="_blank" target="_blank"
className="flex items-center gap-2"
> >
<VegaIcon name={VegaIconNames.OPEN_EXTERNAL} size={16} /> <VegaIcon name={VegaIconNames.OPEN_EXTERNAL} size={16} />
{t('View proposal')} {t('View proposal')}

View File

@ -0,0 +1,37 @@
import type { FC } from 'react';
import { AgGrid } from '@vegaprotocol/datagrid';
import { useProposedMarketsList } from '@vegaprotocol/markets';
import { type ProposalListFieldsFragment } from '@vegaprotocol/proposals';
import { useColumnDefs } from './use-column-defs';
import { useT } from '../../../lib/use-t';
const defaultColDef = {
sortable: true,
filter: true,
resizable: true,
filterParams: { buttons: ['reset'] },
};
interface ProposalListProps {
cellRenderers: {
[name: string]: FC<{ value: string; data: ProposalListFieldsFragment }>;
};
}
export const ProposalsList = ({ cellRenderers }: ProposalListProps) => {
const t = useT();
const { data } = useProposedMarketsList();
const columnDefs = useColumnDefs();
return (
<AgGrid
columnDefs={columnDefs}
rowData={data}
defaultColDef={defaultColDef}
getRowId={({ data }) => data.id}
overlayNoRowsTemplate={t('No proposed markets')}
components={cellRenderers}
rowHeight={45}
/>
);
};

View File

@ -13,12 +13,13 @@ import type {
VegaValueFormatterParams, VegaValueFormatterParams,
} from '@vegaprotocol/datagrid'; } from '@vegaprotocol/datagrid';
import { import {
ProposalProductTypeShortName, MarketStateMapping,
ProposalStateMapping, ProductTypeMapping,
ProductTypeShortName,
} from '@vegaprotocol/types'; } from '@vegaprotocol/types';
import type { ProposalListFieldsFragment } from '../../lib/proposals-data-provider/__generated__/Proposals'; import { ProposalActionsDropdown } from './proposal-actions-dropdown';
import { ProposalActionsDropdown } from '../proposal-actions-dropdown'; import { type MarketFieldsFragment, getProductType } from '@vegaprotocol/markets';
import { useT } from '../../use-t'; import { useT } from '../../..//lib/use-t';
export const useColumnDefs = () => { export const useColumnDefs = () => {
const t = useT(); const t = useT();
@ -28,7 +29,7 @@ export const useColumnDefs = () => {
{ {
colId: 'market', colId: 'market',
headerName: t('Market'), headerName: t('Market'),
field: 'terms.change.instrument.code', field: 'tradableInstrument.instrument.code',
pinned: true, pinned: true,
cellStyle: { lineHeight: '14px' }, cellStyle: { lineHeight: '14px' },
cellRenderer: ({ cellRenderer: ({
@ -36,20 +37,10 @@ export const useColumnDefs = () => {
data, data,
}: { }: {
value: string; value: string;
data: ProposalListFieldsFragment; data: MarketFieldsFragment;
}) => { }) => {
if (!value || !data) return '-'; if (!value || !data) return '-';
const getProductType = (data: ProposalListFieldsFragment) => {
if (
data.terms.__typename === 'ProposalTerms' &&
data.terms.change.__typename === 'NewMarket'
) {
return data.terms.change.instrument.product?.__typename;
}
return undefined;
};
const productType = getProductType(data); const productType = getProductType(data);
return ( return (
productType && ( productType && (
@ -57,10 +48,10 @@ export const useColumnDefs = () => {
primary={value} primary={value}
secondary={ secondary={
<span <span
title={ProposalProductTypeShortName[productType]} title={ProductTypeMapping[productType]}
className="uppercase" className="uppercase"
> >
{ProposalProductTypeShortName[productType]} {ProductTypeShortName[productType]}
</span> </span>
} }
/> />
@ -71,7 +62,7 @@ export const useColumnDefs = () => {
{ {
colId: 'asset', colId: 'asset',
headerName: t('Settlement asset'), headerName: t('Settlement asset'),
field: 'terms.change.instrument.product.settlementAsset.symbol', field: 'tradableInstrument.instrument.product.settlementAsset.symbol',
}, },
{ {
colId: 'state', colId: 'state',
@ -79,39 +70,42 @@ export const useColumnDefs = () => {
field: 'state', field: 'state',
valueFormatter: ({ valueFormatter: ({
value, value,
}: VegaValueFormatterParams<ProposalListFieldsFragment, 'state'>) => }: VegaValueFormatterParams<MarketFieldsFragment, 'state'>) => {
value ? ProposalStateMapping[value] : '-', return value ? MarketStateMapping[value] : '-';
},
filter: SetFilter, filter: SetFilter,
filterParams: { filterParams: {
set: ProposalStateMapping, set: MarketStateMapping,
}, },
}, },
{ {
headerName: t('Parent market'), headerName: t('Parent market'),
field: 'terms.change.successorConfiguration.parentMarketId', field: 'parentMarketID',
cellRenderer: 'ParentMarketCell', cellRenderer: 'ParentMarketCell',
}, },
{ {
colId: 'closing-date', colId: 'closing-date',
headerName: t('Closing date'), headerName: t('Closing date'),
field: 'terms.closingDatetime', field: 'marketTimestamps.pending',
valueFormatter: ({ valueFormatter: ({
value, value,
}: VegaValueFormatterParams< }: VegaValueFormatterParams<
ProposalListFieldsFragment, MarketFieldsFragment,
'terms.closingDatetime' 'marketTimestamps.pending'
>) => (value ? getDateTimeFormat().format(new Date(value)) : '-'), >) => {
return value ? getDateTimeFormat().format(new Date(value)) : '-';
},
filter: DateRangeFilter, filter: DateRangeFilter,
}, },
{ {
colId: 'enactment-date', colId: 'enactment-date',
headerName: t('Enactment date'), headerName: t('Enactment date'),
field: 'terms.enactmentDatetime', field: 'marketTimestamps.open',
valueFormatter: ({ valueFormatter: ({
value, value,
}: VegaValueFormatterParams< }: VegaValueFormatterParams<
ProposalListFieldsFragment, MarketFieldsFragment,
'terms.enactmentDatetime' 'marketTimestamps.open'
>) => (value ? getDateTimeFormat().format(new Date(value)) : '-'), >) => (value ? getDateTimeFormat().format(new Date(value)) : '-'),
filter: DateRangeFilter, filter: DateRangeFilter,
}, },
@ -120,10 +114,10 @@ export const useColumnDefs = () => {
...COL_DEFS.actions, ...COL_DEFS.actions,
cellRenderer: ({ cellRenderer: ({
data, data,
}: VegaICellRendererParams<ProposalListFieldsFragment>) => { }: VegaICellRendererParams<MarketFieldsFragment>) => {
if (!data?.id) return null; if (!data?.marketProposal?.id) return null;
return <ProposalActionsDropdown id={data.id} />; return <ProposalActionsDropdown id={data.marketProposal.id} />;
}, },
}, },
]); ]);

View File

@ -1,4 +1,4 @@
import { ProposalsList } from '@vegaprotocol/proposals'; import { ProposalsList } from './proposals-list';
import { ParentMarketCell } from './parent-market-cell'; import { ParentMarketCell } from './parent-market-cell';
const cellRenderers = { const cellRenderers = {

File diff suppressed because one or more lines are too long

View File

@ -123,6 +123,16 @@ export const filterAndSortClosedMarkets = (markets: MarketMaybeWithData[]) => {
}); });
}; };
export const filterAndSortProposedMarkets = (
markets: MarketMaybeWithData[]
) => {
return markets.filter((m) => {
return [MarketState.STATE_PROPOSED].includes(
m.data?.marketState || m.state
);
});
};
export const calcCandleLow = (candles: Candle[]): string | undefined => { export const calcCandleLow = (candles: Candle[]): string | undefined => {
return candles return candles
?.reduce((acc: BigNumber, c) => { ?.reduce((acc: BigNumber, c) => {

View File

@ -27,6 +27,7 @@ import * as Schema from '@vegaprotocol/types';
import { import {
filterAndSortClosedMarkets, filterAndSortClosedMarkets,
filterAndSortMarkets, filterAndSortMarkets,
filterAndSortProposedMarkets,
} from './market-utils'; } from './market-utils';
import type { Candle } from './market-candles-provider'; import type { Candle } from './market-candles-provider';
@ -114,6 +115,11 @@ export const closedMarketsProvider = makeDerivedDataProvider<Market[], never>(
([markets]) => filterAndSortClosedMarkets(markets) ([markets]) => filterAndSortClosedMarkets(markets)
); );
export const proposedMarketsProvider = makeDerivedDataProvider<Market[], never>(
[marketsProvider],
([markets]) => filterAndSortProposedMarkets(markets)
);
export type MarketMaybeWithCandles = Market & { candles?: Candle[] }; export type MarketMaybeWithCandles = Market & { candles?: Candle[] };
const addCandles = <T extends Market>( const addCandles = <T extends Market>(
@ -241,3 +247,10 @@ export const useMarketList = () => {
reload, reload,
}; };
}; };
export const useProposedMarketsList = () => {
return useDataProvider({
dataProvider: proposedMarketsProvider,
variables: undefined,
});
};

View File

@ -36,9 +36,19 @@ fragment MarketFields on Market {
} }
} }
marketTimestamps { marketTimestamps {
proposed
pending
open open
close close
} }
marketProposal {
... on Proposal {
id
}
... on BatchProposal {
id
}
}
} }
query Markets { query Markets {

View File

@ -1,6 +1,5 @@
export * from './asset-proposal-notification'; export * from './asset-proposal-notification';
export * from './market-proposal-notification'; export * from './market-proposal-notification';
export * from './proposals-list';
export * from './protocol-upgrade-countdown'; export * from './protocol-upgrade-countdown';
export * from './protocol-upgrade-in-progress-notification'; export * from './protocol-upgrade-in-progress-notification';
export * from './protocol-upgrade-proposal-notification'; export * from './protocol-upgrade-proposal-notification';

View File

@ -1 +0,0 @@
export * from './proposals-list';

View File

@ -1,56 +0,0 @@
import type { FC } from 'react';
import { AgGrid } from '@vegaprotocol/datagrid';
import * as Types from '@vegaprotocol/types';
import { removePaginationWrapper } from '@vegaprotocol/utils';
import type { ProposalListFieldsFragment } from '../../lib/proposals-data-provider/__generated__/Proposals';
import { useProposalsListQuery } from '../../lib/proposals-data-provider/__generated__/Proposals';
import { useColumnDefs } from './use-column-defs';
import { useT } from '../../use-t';
export const getNewMarketProposals = (data: ProposalListFieldsFragment[]) =>
data.filter((proposal) =>
[
Types.ProposalState.STATE_OPEN,
Types.ProposalState.STATE_PASSED,
Types.ProposalState.STATE_WAITING_FOR_NODE_VOTE,
].includes(proposal.state)
);
const defaultColDef = {
sortable: true,
filter: true,
resizable: true,
filterParams: { buttons: ['reset'] },
};
interface ProposalListProps {
cellRenderers: {
[name: string]: FC<{ value: string; data: ProposalListFieldsFragment }>;
};
}
export const ProposalsList = ({ cellRenderers }: ProposalListProps) => {
const t = useT();
const { data } = useProposalsListQuery({
variables: {
proposalType: Types.ProposalType.TYPE_NEW_MARKET,
},
errorPolicy: 'all', // currently there are some proposals failing due to proposals existing without settlement asset ids
});
const filteredData = getNewMarketProposals(
removePaginationWrapper(data?.proposalsConnection?.edges)
);
const columnDefs = useColumnDefs();
return (
<AgGrid
columnDefs={columnDefs}
rowData={filteredData}
defaultColDef={defaultColDef}
getRowId={({ data }) => data.id}
overlayNoRowsTemplate={t('No proposed markets')}
components={cellRenderers}
rowHeight={45}
/>
);
};

View File

@ -256,6 +256,8 @@ export type AggregatedLedgerEntry = {
toAccountPartyId?: Maybe<Scalars['ID']>; toAccountPartyId?: Maybe<Scalars['ID']>;
/** Account type, if query was grouped by receiver account type - else null */ /** Account type, if query was grouped by receiver account type - else null */
toAccountType?: Maybe<AccountType>; toAccountType?: Maybe<AccountType>;
/** Transfer ID associated with this aggregated ledger entry */
transferId: Scalars['ID'];
/** Type of the transfer for this ledger entry */ /** Type of the transfer for this ledger entry */
transferType?: Maybe<TransferType>; transferType?: Maybe<TransferType>;
/** RFC3339Nano time from at which this ledger entries records were relevant */ /** RFC3339Nano time from at which this ledger entries records were relevant */