[#128] Capitalize types in position queries
This commit is contained in:
parent
fe29e86c74
commit
444f1b6584
@ -6,8 +6,8 @@ import { AsyncRenderer } from '../../components/async-renderer';
|
||||
import { PositionsTable, getRowNodeId } from '@vegaprotocol/positions';
|
||||
import { useDataProvider } from '@vegaprotocol/react-helpers';
|
||||
import {
|
||||
positions_party_positions,
|
||||
positionSubscribe_positions,
|
||||
Positions_party_positions,
|
||||
PositionSubscribe_positions,
|
||||
positionsDataProvider,
|
||||
} from '@vegaprotocol/graphql';
|
||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
||||
@ -20,17 +20,17 @@ export const Positions = () => {
|
||||
const { keypair } = useVegaWallet();
|
||||
const variables = useMemo(() => ({ partyId: keypair.pub }), [keypair]);
|
||||
const update = useCallback(
|
||||
(delta: positionSubscribe_positions) => {
|
||||
const update: positions_party_positions[] = [];
|
||||
const add: positions_party_positions[] = [];
|
||||
(delta: PositionSubscribe_positions) => {
|
||||
const update: Positions_party_positions[] = [];
|
||||
const add: Positions_party_positions[] = [];
|
||||
if (!gridRef.current) {
|
||||
return false;
|
||||
}
|
||||
const rowNode = gridRef.current.api.getRowNode(getRowNodeId(delta));
|
||||
if (rowNode) {
|
||||
const updatedData = produce<positions_party_positions>(
|
||||
const updatedData = produce<Positions_party_positions>(
|
||||
rowNode.data,
|
||||
(draft: positions_party_positions) => {
|
||||
(draft: Positions_party_positions) => {
|
||||
merge(draft, delta);
|
||||
}
|
||||
);
|
||||
@ -52,8 +52,8 @@ export const Positions = () => {
|
||||
[gridRef]
|
||||
);
|
||||
const { data, error, loading } = useDataProvider<
|
||||
positions_party_positions,
|
||||
positionSubscribe_positions
|
||||
Positions_party_positions,
|
||||
PositionSubscribe_positions
|
||||
>(positionsDataProvider, update, variables);
|
||||
return (
|
||||
<AsyncRenderer loading={loading} error={error} data={data}>
|
||||
|
@ -6,10 +6,10 @@
|
||||
import { MarketTradingMode } from "./globalTypes";
|
||||
|
||||
// ====================================================
|
||||
// GraphQL subscription operation: positionSubscribe
|
||||
// GraphQL subscription operation: PositionSubscribe
|
||||
// ====================================================
|
||||
|
||||
export interface positionSubscribe_positions_market_data_market {
|
||||
export interface PositionSubscribe_positions_market_data_market {
|
||||
__typename: "Market";
|
||||
/**
|
||||
* Market ID
|
||||
@ -17,7 +17,7 @@ export interface positionSubscribe_positions_market_data_market {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export interface positionSubscribe_positions_market_data {
|
||||
export interface PositionSubscribe_positions_market_data {
|
||||
__typename: "MarketData";
|
||||
/**
|
||||
* the mark price (actually an unsigned int)
|
||||
@ -30,10 +30,10 @@ export interface positionSubscribe_positions_market_data {
|
||||
/**
|
||||
* market id of the associated mark price
|
||||
*/
|
||||
market: positionSubscribe_positions_market_data_market;
|
||||
market: PositionSubscribe_positions_market_data_market;
|
||||
}
|
||||
|
||||
export interface positionSubscribe_positions_market_tradableInstrument_instrument_metadata {
|
||||
export interface PositionSubscribe_positions_market_tradableInstrument_instrument_metadata {
|
||||
__typename: "InstrumentMetadata";
|
||||
/**
|
||||
* An arbitrary list of tags to associated to associate to the Instrument (string list)
|
||||
@ -41,7 +41,7 @@ export interface positionSubscribe_positions_market_tradableInstrument_instrumen
|
||||
tags: string[] | null;
|
||||
}
|
||||
|
||||
export interface positionSubscribe_positions_market_tradableInstrument_instrument_product_settlementAsset {
|
||||
export interface PositionSubscribe_positions_market_tradableInstrument_instrument_product_settlementAsset {
|
||||
__typename: "Asset";
|
||||
/**
|
||||
* The id of the asset
|
||||
@ -61,19 +61,19 @@ export interface positionSubscribe_positions_market_tradableInstrument_instrumen
|
||||
decimals: number;
|
||||
}
|
||||
|
||||
export interface positionSubscribe_positions_market_tradableInstrument_instrument_product {
|
||||
export interface PositionSubscribe_positions_market_tradableInstrument_instrument_product {
|
||||
__typename: "Future";
|
||||
/**
|
||||
* The name of the asset (string)
|
||||
*/
|
||||
settlementAsset: positionSubscribe_positions_market_tradableInstrument_instrument_product_settlementAsset;
|
||||
settlementAsset: PositionSubscribe_positions_market_tradableInstrument_instrument_product_settlementAsset;
|
||||
/**
|
||||
* String representing the quote (e.g. BTCUSD -> USD is quote)
|
||||
*/
|
||||
quoteName: string;
|
||||
}
|
||||
|
||||
export interface positionSubscribe_positions_market_tradableInstrument_instrument {
|
||||
export interface PositionSubscribe_positions_market_tradableInstrument_instrument {
|
||||
__typename: "Instrument";
|
||||
/**
|
||||
* Uniquely identify an instrument across all instruments available on Vega (string)
|
||||
@ -86,7 +86,7 @@ export interface positionSubscribe_positions_market_tradableInstrument_instrumen
|
||||
/**
|
||||
* Metadata for this instrument
|
||||
*/
|
||||
metadata: positionSubscribe_positions_market_tradableInstrument_instrument_metadata;
|
||||
metadata: PositionSubscribe_positions_market_tradableInstrument_instrument_metadata;
|
||||
/**
|
||||
* A short non necessarily unique code used to easily describe the instrument (e.g: FX:BTCUSD/DEC18) (string)
|
||||
*/
|
||||
@ -94,18 +94,18 @@ export interface positionSubscribe_positions_market_tradableInstrument_instrumen
|
||||
/**
|
||||
* A reference to or instance of a fully specified product, including all required product parameters for that product (Product union)
|
||||
*/
|
||||
product: positionSubscribe_positions_market_tradableInstrument_instrument_product;
|
||||
product: PositionSubscribe_positions_market_tradableInstrument_instrument_product;
|
||||
}
|
||||
|
||||
export interface positionSubscribe_positions_market_tradableInstrument {
|
||||
export interface PositionSubscribe_positions_market_tradableInstrument {
|
||||
__typename: "TradableInstrument";
|
||||
/**
|
||||
* An instance of or reference to a fully specified instrument.
|
||||
*/
|
||||
instrument: positionSubscribe_positions_market_tradableInstrument_instrument;
|
||||
instrument: PositionSubscribe_positions_market_tradableInstrument_instrument;
|
||||
}
|
||||
|
||||
export interface positionSubscribe_positions_market {
|
||||
export interface PositionSubscribe_positions_market {
|
||||
__typename: "Market";
|
||||
/**
|
||||
* Market ID
|
||||
@ -118,7 +118,7 @@ export interface positionSubscribe_positions_market {
|
||||
/**
|
||||
* marketData for the given market
|
||||
*/
|
||||
data: positionSubscribe_positions_market_data | null;
|
||||
data: PositionSubscribe_positions_market_data | null;
|
||||
/**
|
||||
* decimalPlaces indicates the number of decimal places that an integer must be shifted by in order to get a correct
|
||||
* number denominated in the currency of the Market. (uint64)
|
||||
@ -139,10 +139,10 @@ export interface positionSubscribe_positions_market {
|
||||
/**
|
||||
* An instance of or reference to a tradable instrument.
|
||||
*/
|
||||
tradableInstrument: positionSubscribe_positions_market_tradableInstrument;
|
||||
tradableInstrument: PositionSubscribe_positions_market_tradableInstrument;
|
||||
}
|
||||
|
||||
export interface positionSubscribe_positions {
|
||||
export interface PositionSubscribe_positions {
|
||||
__typename: "Position";
|
||||
/**
|
||||
* Realised Profit and Loss (int64)
|
||||
@ -163,16 +163,16 @@ export interface positionSubscribe_positions {
|
||||
/**
|
||||
* Market relating to this position
|
||||
*/
|
||||
market: positionSubscribe_positions_market;
|
||||
market: PositionSubscribe_positions_market;
|
||||
}
|
||||
|
||||
export interface positionSubscribe {
|
||||
export interface PositionSubscribe {
|
||||
/**
|
||||
* Subscribe to the positions updates
|
||||
*/
|
||||
positions: positionSubscribe_positions;
|
||||
positions: PositionSubscribe_positions;
|
||||
}
|
||||
|
||||
export interface positionSubscribeVariables {
|
||||
export interface PositionSubscribeVariables {
|
||||
partyId: string;
|
||||
}
|
@ -6,10 +6,10 @@
|
||||
import { MarketTradingMode } from "./globalTypes";
|
||||
|
||||
// ====================================================
|
||||
// GraphQL query operation: positions
|
||||
// GraphQL query operation: Positions
|
||||
// ====================================================
|
||||
|
||||
export interface positions_party_positions_market_data_market {
|
||||
export interface Positions_party_positions_market_data_market {
|
||||
__typename: "Market";
|
||||
/**
|
||||
* Market ID
|
||||
@ -17,7 +17,7 @@ export interface positions_party_positions_market_data_market {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export interface positions_party_positions_market_data {
|
||||
export interface Positions_party_positions_market_data {
|
||||
__typename: "MarketData";
|
||||
/**
|
||||
* the mark price (actually an unsigned int)
|
||||
@ -30,10 +30,10 @@ export interface positions_party_positions_market_data {
|
||||
/**
|
||||
* market id of the associated mark price
|
||||
*/
|
||||
market: positions_party_positions_market_data_market;
|
||||
market: Positions_party_positions_market_data_market;
|
||||
}
|
||||
|
||||
export interface positions_party_positions_market_tradableInstrument_instrument_metadata {
|
||||
export interface Positions_party_positions_market_tradableInstrument_instrument_metadata {
|
||||
__typename: "InstrumentMetadata";
|
||||
/**
|
||||
* An arbitrary list of tags to associated to associate to the Instrument (string list)
|
||||
@ -41,7 +41,7 @@ export interface positions_party_positions_market_tradableInstrument_instrument_
|
||||
tags: string[] | null;
|
||||
}
|
||||
|
||||
export interface positions_party_positions_market_tradableInstrument_instrument_product_settlementAsset {
|
||||
export interface Positions_party_positions_market_tradableInstrument_instrument_product_settlementAsset {
|
||||
__typename: "Asset";
|
||||
/**
|
||||
* The id of the asset
|
||||
@ -61,19 +61,19 @@ export interface positions_party_positions_market_tradableInstrument_instrument_
|
||||
decimals: number;
|
||||
}
|
||||
|
||||
export interface positions_party_positions_market_tradableInstrument_instrument_product {
|
||||
export interface Positions_party_positions_market_tradableInstrument_instrument_product {
|
||||
__typename: "Future";
|
||||
/**
|
||||
* The name of the asset (string)
|
||||
*/
|
||||
settlementAsset: positions_party_positions_market_tradableInstrument_instrument_product_settlementAsset;
|
||||
settlementAsset: Positions_party_positions_market_tradableInstrument_instrument_product_settlementAsset;
|
||||
/**
|
||||
* String representing the quote (e.g. BTCUSD -> USD is quote)
|
||||
*/
|
||||
quoteName: string;
|
||||
}
|
||||
|
||||
export interface positions_party_positions_market_tradableInstrument_instrument {
|
||||
export interface Positions_party_positions_market_tradableInstrument_instrument {
|
||||
__typename: "Instrument";
|
||||
/**
|
||||
* Uniquely identify an instrument across all instruments available on Vega (string)
|
||||
@ -86,7 +86,7 @@ export interface positions_party_positions_market_tradableInstrument_instrument
|
||||
/**
|
||||
* Metadata for this instrument
|
||||
*/
|
||||
metadata: positions_party_positions_market_tradableInstrument_instrument_metadata;
|
||||
metadata: Positions_party_positions_market_tradableInstrument_instrument_metadata;
|
||||
/**
|
||||
* A short non necessarily unique code used to easily describe the instrument (e.g: FX:BTCUSD/DEC18) (string)
|
||||
*/
|
||||
@ -94,18 +94,18 @@ export interface positions_party_positions_market_tradableInstrument_instrument
|
||||
/**
|
||||
* A reference to or instance of a fully specified product, including all required product parameters for that product (Product union)
|
||||
*/
|
||||
product: positions_party_positions_market_tradableInstrument_instrument_product;
|
||||
product: Positions_party_positions_market_tradableInstrument_instrument_product;
|
||||
}
|
||||
|
||||
export interface positions_party_positions_market_tradableInstrument {
|
||||
export interface Positions_party_positions_market_tradableInstrument {
|
||||
__typename: "TradableInstrument";
|
||||
/**
|
||||
* An instance of or reference to a fully specified instrument.
|
||||
*/
|
||||
instrument: positions_party_positions_market_tradableInstrument_instrument;
|
||||
instrument: Positions_party_positions_market_tradableInstrument_instrument;
|
||||
}
|
||||
|
||||
export interface positions_party_positions_market {
|
||||
export interface Positions_party_positions_market {
|
||||
__typename: "Market";
|
||||
/**
|
||||
* Market ID
|
||||
@ -118,7 +118,7 @@ export interface positions_party_positions_market {
|
||||
/**
|
||||
* marketData for the given market
|
||||
*/
|
||||
data: positions_party_positions_market_data | null;
|
||||
data: Positions_party_positions_market_data | null;
|
||||
/**
|
||||
* decimalPlaces indicates the number of decimal places that an integer must be shifted by in order to get a correct
|
||||
* number denominated in the currency of the Market. (uint64)
|
||||
@ -139,10 +139,10 @@ export interface positions_party_positions_market {
|
||||
/**
|
||||
* An instance of or reference to a tradable instrument.
|
||||
*/
|
||||
tradableInstrument: positions_party_positions_market_tradableInstrument;
|
||||
tradableInstrument: Positions_party_positions_market_tradableInstrument;
|
||||
}
|
||||
|
||||
export interface positions_party_positions {
|
||||
export interface Positions_party_positions {
|
||||
__typename: "Position";
|
||||
/**
|
||||
* Realised Profit and Loss (int64)
|
||||
@ -163,10 +163,10 @@ export interface positions_party_positions {
|
||||
/**
|
||||
* Market relating to this position
|
||||
*/
|
||||
market: positions_party_positions_market;
|
||||
market: Positions_party_positions_market;
|
||||
}
|
||||
|
||||
export interface positions_party {
|
||||
export interface Positions_party {
|
||||
__typename: "Party";
|
||||
/**
|
||||
* Party identifier
|
||||
@ -175,16 +175,16 @@ export interface positions_party {
|
||||
/**
|
||||
* Trading positions relating to a party
|
||||
*/
|
||||
positions: positions_party_positions[] | null;
|
||||
positions: Positions_party_positions[] | null;
|
||||
}
|
||||
|
||||
export interface positions {
|
||||
export interface Positions {
|
||||
/**
|
||||
* An entity that is trading on the VEGA network
|
||||
*/
|
||||
party: positions_party | null;
|
||||
party: Positions_party | null;
|
||||
}
|
||||
|
||||
export interface positionsVariables {
|
||||
export interface PositionsVariables {
|
||||
partyId: string;
|
||||
}
|
@ -1,14 +1,14 @@
|
||||
import { gql } from '@apollo/client';
|
||||
import {
|
||||
positions,
|
||||
positions_party_positions,
|
||||
} from '../__generated__/positions';
|
||||
Positions,
|
||||
Positions_party_positions,
|
||||
} from '../__generated__/Positions';
|
||||
import { makeDataProvider } from './generic-data-provider';
|
||||
|
||||
import {
|
||||
positionSubscribe,
|
||||
positionSubscribe_positions,
|
||||
} from '../__generated__/positionSubscribe';
|
||||
PositionSubscribe,
|
||||
PositionSubscribe_positions,
|
||||
} from '../__generated__/PositionSubscribe';
|
||||
|
||||
const POSITIONS_FRAGMENT = gql`
|
||||
fragment PositionDetails on Position {
|
||||
@ -54,7 +54,7 @@ const POSITIONS_FRAGMENT = gql`
|
||||
|
||||
const POSITION_QUERY = gql`
|
||||
${POSITIONS_FRAGMENT}
|
||||
query positions($partyId: ID!) {
|
||||
query Positions($partyId: ID!) {
|
||||
party(id: $partyId) {
|
||||
id
|
||||
positions {
|
||||
@ -66,7 +66,7 @@ const POSITION_QUERY = gql`
|
||||
|
||||
export const POSITIONS_SUB = gql`
|
||||
${POSITIONS_FRAGMENT}
|
||||
subscription positionSubscribe($partyId: ID!) {
|
||||
subscription PositionSubscribe($partyId: ID!) {
|
||||
positions(partyId: $partyId) {
|
||||
...PositionDetails
|
||||
}
|
||||
@ -74,8 +74,8 @@ export const POSITIONS_SUB = gql`
|
||||
`;
|
||||
|
||||
const update = (
|
||||
draft: positions_party_positions[],
|
||||
delta: positionSubscribe_positions
|
||||
draft: Positions_party_positions[],
|
||||
delta: PositionSubscribe_positions
|
||||
) => {
|
||||
const index = draft.findIndex((m) => m.market.id === delta.market.id);
|
||||
if (index !== -1) {
|
||||
@ -84,15 +84,15 @@ const update = (
|
||||
draft.push(delta);
|
||||
}
|
||||
};
|
||||
const getData = (responseData: positions): positions_party_positions[] | null =>
|
||||
const getData = (responseData: Positions): Positions_party_positions[] | null =>
|
||||
responseData.party ? responseData.party.positions : null;
|
||||
const getDelta = (
|
||||
subscriptionData: positionSubscribe
|
||||
): positionSubscribe_positions => subscriptionData.positions;
|
||||
subscriptionData: PositionSubscribe
|
||||
): PositionSubscribe_positions => subscriptionData.positions;
|
||||
|
||||
export const positionsDataProvider = makeDataProvider<
|
||||
positions,
|
||||
positions_party_positions,
|
||||
positionSubscribe,
|
||||
positionSubscribe_positions
|
||||
Positions,
|
||||
Positions_party_positions,
|
||||
PositionSubscribe,
|
||||
PositionSubscribe_positions
|
||||
>(POSITION_QUERY, POSITIONS_SUB, update, getData, getDelta);
|
||||
|
@ -14,8 +14,8 @@ export * from './__generated__/Orders';
|
||||
export * from './__generated__/OrderSub';
|
||||
export * from './__generated__/PartyAssetsQuery';
|
||||
export * from './__generated__/PositionDetails';
|
||||
export * from './__generated__/positions';
|
||||
export * from './__generated__/positionSubscribe';
|
||||
export * from './__generated__/Positions';
|
||||
export * from './__generated__/PositionSubscribe';
|
||||
export * from './__generated__/ProposalsQuery';
|
||||
|
||||
export * from './data-providers';
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { act, render, screen } from '@testing-library/react';
|
||||
import PositionsTable from './positions-table';
|
||||
import {
|
||||
positions_party_positions,
|
||||
Positions_party_positions,
|
||||
MarketTradingMode,
|
||||
} from '@vegaprotocol/graphql';
|
||||
|
||||
const singleRow: positions_party_positions = {
|
||||
const singleRow: Positions_party_positions = {
|
||||
realisedPNL: '5',
|
||||
openVolume: '100',
|
||||
unrealisedPNL: '895000',
|
||||
|
@ -11,12 +11,12 @@ import { AgGridColumn } from 'ag-grid-react';
|
||||
import type { AgGridReact } from 'ag-grid-react';
|
||||
import compact from 'lodash/compact';
|
||||
import {
|
||||
positions_party_positions,
|
||||
Positions_party_positions,
|
||||
MarketTradingMode,
|
||||
} from '@vegaprotocol/graphql';
|
||||
|
||||
interface PositionsTableProps {
|
||||
data: positions_party_positions[];
|
||||
data: Positions_party_positions[];
|
||||
onRowClicked: (marketId: string) => void;
|
||||
}
|
||||
|
||||
@ -24,8 +24,8 @@ export const getRowNodeId = (data: { market: { id: string } }) =>
|
||||
data.market.id;
|
||||
|
||||
const sortByName = (
|
||||
a: positions_party_positions,
|
||||
b: positions_party_positions
|
||||
a: Positions_party_positions,
|
||||
b: Positions_party_positions
|
||||
) => {
|
||||
if (
|
||||
a.market.tradableInstrument.instrument.name <
|
||||
@ -45,7 +45,7 @@ const sortByName = (
|
||||
};
|
||||
|
||||
interface PositionsTableValueFormatterParams extends ValueFormatterParams {
|
||||
data: positions_party_positions;
|
||||
data: Positions_party_positions;
|
||||
}
|
||||
|
||||
export const PositionsTable = forwardRef<AgGridReact, PositionsTableProps>(
|
||||
@ -64,7 +64,7 @@ export const PositionsTable = forwardRef<AgGridReact, PositionsTableProps>(
|
||||
flex: 1,
|
||||
resizable: true,
|
||||
}}
|
||||
onRowClicked={({ data }: { data: positions_party_positions }) =>
|
||||
onRowClicked={({ data }: { data: Positions_party_positions }) =>
|
||||
onRowClicked(getRowNodeId(data))
|
||||
}
|
||||
components={{ PriceCell }}
|
||||
|
Loading…
Reference in New Issue
Block a user