From 738c93606b30a8efd0080b278326523493eb5727 Mon Sep 17 00:00:00 2001 From: "m.ray" <16125548+MadalinaRaicu@users.noreply.github.com> Date: Fri, 19 Aug 2022 08:39:46 +0200 Subject: [PATCH] fix: apollo in memory tradable instrument (#1036) * fix: update appolo client and set key fields for instruments * fix: use in-memory cache and tradable instrument id * fix: revert switch case * fix: add more info in gen market list for home.cy.ts * fix: instrument keyfield still false * fix: revert simple trading app and explorer updates - fixing tests * fix: remove id from instrument data provider in simple trading app * fix: remove id from market selector market names query * Update apps/trading-e2e/src/support/mocks/generate-market-list.ts * Update apps/trading-e2e/src/support/mocks/generate-market-list.ts * Update apps/trading-e2e/src/support/mocks/generate-market-list.ts * Update apps/trading-e2e/src/support/mocks/generate-market-list.ts --- apps/trading-e2e/src/integration/home.cy.ts | 2 +- .../src/support/mocks/generate-market-list.ts | 54 ++++++++++++++++--- apps/trading/lib/apollo-client.ts | 6 +++ .../trading/pages/markets/[marketId].page.tsx | 1 + .../pages/markets/__generated__/Market.ts | 4 ++ .../__generated__/DealTicketQuery.ts | 4 ++ .../src/components/deal-ticket-container.tsx | 1 + .../src/lib/__generated__/MarketList.ts | 4 ++ .../src/lib/markets-data-provider.ts | 1 + .../lib/components/mocks/generate-orders.ts | 1 + .../__generated__/OrderFields.ts | 4 ++ .../__generated__/OrderSub.ts | 4 ++ .../__generated__/Orders.ts | 4 ++ .../order-data-provider.ts | 1 + .../lib/components/order-list/order-list.tsx | 6 +-- 15 files changed, 87 insertions(+), 10 deletions(-) diff --git a/apps/trading-e2e/src/integration/home.cy.ts b/apps/trading-e2e/src/integration/home.cy.ts index e9c21313c..725a94668 100644 --- a/apps/trading-e2e/src/integration/home.cy.ts +++ b/apps/trading-e2e/src/integration/home.cy.ts @@ -65,7 +65,7 @@ describe('home', () => { } }); - // the oldest market trading in continous mode shown at top of overlay table + // the oldest market trading in continuos mode shown at top of overlay table cy.get('table tr') .eq(1) .within(() => diff --git a/apps/trading-e2e/src/support/mocks/generate-market-list.ts b/apps/trading-e2e/src/support/mocks/generate-market-list.ts index 86793871c..1ab9cb83c 100644 --- a/apps/trading-e2e/src/support/mocks/generate-market-list.ts +++ b/apps/trading-e2e/src/support/mocks/generate-market-list.ts @@ -18,14 +18,16 @@ export const generateMarketList = ( positionDecimalPlaces: 0, state: MarketState.Active, tradingMode: MarketTradingMode.Continuous, + positionDecimalPlaces: 2, + name: 'Market 0', fees: { - factors: { - makerFee: '0.0002', - infrastructureFee: '0.0005', - liquidityFee: '0.001', - __typename: 'FeeFactors', - }, __typename: 'Fees', + factors: { + __typename: 'FeeFactors', + makerFee: '0.001', + liquidityFee: '0.001', + infrastructureFee: '0.001', + }, }, data: { market: { @@ -33,6 +35,8 @@ export const generateMarketList = ( state: MarketState.Active, tradingMode: MarketTradingMode.Continuous, __typename: 'Market', + state: MarketState.Active, + tradingMode: MarketTradingMode.Continuous, }, bestBidPrice: '2411432389', bestOfferPrice: '2346732714', @@ -40,9 +44,21 @@ export const generateMarketList = ( trigger: AuctionTrigger.Price, indicativeVolume: '1216', __typename: 'MarketData', + bestBidPrice: '4612690058', + bestOfferPrice: '4612690058', + trigger: AuctionTrigger.Liquidity, + indicativeVolume: '0', }, tradableInstrument: { instrument: { + id: '10cd0a793ad2887b340940337fa6d97a212e0e517fe8e9eab2b5ef3a38633f35', + product: { + __typename: 'Future', + settlementAsset: { + __typename: 'Asset', + symbol: 'ETH', + }, + }, name: 'BTC/USD Monthly', code: 'BTCUSD.MF21', metadata: { @@ -83,22 +99,48 @@ export const generateMarketList = ( positionDecimalPlaces: 0, state: MarketState.Suspended, tradingMode: MarketTradingMode.MonitoringAuction, + name: 'BTC/USD Monthly', + positionDecimalPlaces: 2, + fees: { + __typename: 'Fees', + factors: { + __typename: 'FeeFactors', + makerFee: '0.001', + liquidityFee: '0.001', + infrastructureFee: '0.001', + }, + }, data: { market: { id: '34d95e10faa00c21d19d382d6d7e6fc9722a96985369f0caec041b0f44b775ed', state: MarketState.Suspended, tradingMode: MarketTradingMode.MonitoringAuction, __typename: 'Market', + state: MarketState.Suspended, + tradingMode: MarketTradingMode.MonitoringAuction, }, bestBidPrice: '17065127', bestOfferPrice: '17017654', markPrice: '8441', indicativeVolume: '249', __typename: 'MarketData', + bestBidPrice: '4612690058', + bestOfferPrice: '4612690058', + trigger: AuctionTrigger.Liquidity, + + indicativeVolume: '0', }, tradableInstrument: { instrument: { + product: { + __typename: 'Future', + settlementAsset: { + __typename: 'Asset', + symbol: 'ETH', + }, + }, name: 'SOL/USD', + id: '34d95e10faa00c21d19d382d6d7e6fc9722a96985369f0caec041b0f44b775ed', code: 'SOLUSD', metadata: { __typename: 'InstrumentMetadata', diff --git a/apps/trading/lib/apollo-client.ts b/apps/trading/lib/apollo-client.ts index 38313d1f3..671262243 100644 --- a/apps/trading/lib/apollo-client.ts +++ b/apps/trading/lib/apollo-client.ts @@ -33,6 +33,12 @@ export function createClient(base?: string) { Instrument: { keyFields: false, }, + TradableInstrument: { + keyFields: ['instrument'], + }, + Product: { + keyFields: ['settlementAsset', ['id']], + }, MarketData: { keyFields: ['market', ['id']], }, diff --git a/apps/trading/pages/markets/[marketId].page.tsx b/apps/trading/pages/markets/[marketId].page.tsx index f2529e8d9..25364135c 100644 --- a/apps/trading/pages/markets/[marketId].page.tsx +++ b/apps/trading/pages/markets/[marketId].page.tsx @@ -40,6 +40,7 @@ const MARKET_QUERY = gql` } tradableInstrument { instrument { + id name code metadata { diff --git a/apps/trading/pages/markets/__generated__/Market.ts b/apps/trading/pages/markets/__generated__/Market.ts index 17fd60b89..74a04c52d 100644 --- a/apps/trading/pages/markets/__generated__/Market.ts +++ b/apps/trading/pages/markets/__generated__/Market.ts @@ -111,6 +111,10 @@ export interface Market_market_tradableInstrument_instrument_product { export interface Market_market_tradableInstrument_instrument { __typename: "Instrument"; + /** + * Uniquely identify an instrument across all instruments available on Vega (string) + */ + id: string; /** * Full and fairly descriptive name for the instrument */ diff --git a/libs/deal-ticket/src/components/__generated__/DealTicketQuery.ts b/libs/deal-ticket/src/components/__generated__/DealTicketQuery.ts index 610d413c1..6ef458eb1 100644 --- a/libs/deal-ticket/src/components/__generated__/DealTicketQuery.ts +++ b/libs/deal-ticket/src/components/__generated__/DealTicketQuery.ts @@ -39,6 +39,10 @@ export interface DealTicketQuery_market_tradableInstrument_instrument_product { export interface DealTicketQuery_market_tradableInstrument_instrument { __typename: "Instrument"; + /** + * Uniquely identify an instrument across all instruments available on Vega (string) + */ + id: string; /** * A reference to or instance of a fully specified product, including all required product parameters for that product (Product union) */ diff --git a/libs/deal-ticket/src/components/deal-ticket-container.tsx b/libs/deal-ticket/src/components/deal-ticket-container.tsx index 3caa63666..a031309f0 100644 --- a/libs/deal-ticket/src/components/deal-ticket-container.tsx +++ b/libs/deal-ticket/src/components/deal-ticket-container.tsx @@ -15,6 +15,7 @@ const DEAL_TICKET_QUERY = gql` tradingMode tradableInstrument { instrument { + id product { ... on Future { quoteName diff --git a/libs/market-list/src/lib/__generated__/MarketList.ts b/libs/market-list/src/lib/__generated__/MarketList.ts index f54e6caad..7d50683c8 100644 --- a/libs/market-list/src/lib/__generated__/MarketList.ts +++ b/libs/market-list/src/lib/__generated__/MarketList.ts @@ -103,6 +103,10 @@ export interface MarketList_markets_tradableInstrument_instrument_product { export interface MarketList_markets_tradableInstrument_instrument { __typename: "Instrument"; + /** + * Uniquely identify an instrument across all instruments available on Vega (string) + */ + id: string; /** * Full and fairly descriptive name for the instrument */ diff --git a/libs/market-list/src/lib/markets-data-provider.ts b/libs/market-list/src/lib/markets-data-provider.ts index a3c04e71f..a24c8e353 100644 --- a/libs/market-list/src/lib/markets-data-provider.ts +++ b/libs/market-list/src/lib/markets-data-provider.ts @@ -53,6 +53,7 @@ export const MARKET_LIST_QUERY = gql` } tradableInstrument { instrument { + id name code metadata { diff --git a/libs/orders/src/lib/components/mocks/generate-orders.ts b/libs/orders/src/lib/components/mocks/generate-orders.ts index 3e41ee971..47d3638f4 100644 --- a/libs/orders/src/lib/components/mocks/generate-orders.ts +++ b/libs/orders/src/lib/components/mocks/generate-orders.ts @@ -23,6 +23,7 @@ export const generateOrder = ( tradableInstrument: { __typename: 'TradableInstrument', instrument: { + id: 'instrument-id', __typename: 'Instrument', code: 'instrument-code', }, diff --git a/libs/orders/src/lib/components/order-data-provider/__generated__/OrderFields.ts b/libs/orders/src/lib/components/order-data-provider/__generated__/OrderFields.ts index cac0eff56..329ef0a82 100644 --- a/libs/orders/src/lib/components/order-data-provider/__generated__/OrderFields.ts +++ b/libs/orders/src/lib/components/order-data-provider/__generated__/OrderFields.ts @@ -11,6 +11,10 @@ import { OrderType, Side, OrderStatus, OrderRejectionReason, OrderTimeInForce } export interface OrderFields_market_tradableInstrument_instrument { __typename: "Instrument"; + /** + * Uniquely identify an instrument across all instruments available on Vega (string) + */ + id: string; /** * A short non necessarily unique code used to easily describe the instrument (e.g: FX:BTCUSD/DEC18) (string) */ diff --git a/libs/orders/src/lib/components/order-data-provider/__generated__/OrderSub.ts b/libs/orders/src/lib/components/order-data-provider/__generated__/OrderSub.ts index 99cdb2aae..904cf1fff 100644 --- a/libs/orders/src/lib/components/order-data-provider/__generated__/OrderSub.ts +++ b/libs/orders/src/lib/components/order-data-provider/__generated__/OrderSub.ts @@ -11,6 +11,10 @@ import { OrderType, Side, OrderStatus, OrderRejectionReason, OrderTimeInForce } export interface OrderSub_orders_market_tradableInstrument_instrument { __typename: "Instrument"; + /** + * Uniquely identify an instrument across all instruments available on Vega (string) + */ + id: string; /** * A short non necessarily unique code used to easily describe the instrument (e.g: FX:BTCUSD/DEC18) (string) */ diff --git a/libs/orders/src/lib/components/order-data-provider/__generated__/Orders.ts b/libs/orders/src/lib/components/order-data-provider/__generated__/Orders.ts index 7136bc536..4812fbd20 100644 --- a/libs/orders/src/lib/components/order-data-provider/__generated__/Orders.ts +++ b/libs/orders/src/lib/components/order-data-provider/__generated__/Orders.ts @@ -11,6 +11,10 @@ import { Pagination, OrderType, Side, OrderStatus, OrderRejectionReason, OrderTi export interface Orders_party_ordersConnection_edges_node_market_tradableInstrument_instrument { __typename: "Instrument"; + /** + * Uniquely identify an instrument across all instruments available on Vega (string) + */ + id: string; /** * A short non necessarily unique code used to easily describe the instrument (e.g: FX:BTCUSD/DEC18) (string) */ diff --git a/libs/orders/src/lib/components/order-data-provider/order-data-provider.ts b/libs/orders/src/lib/components/order-data-provider/order-data-provider.ts index 6c82ff2bf..833e17180 100644 --- a/libs/orders/src/lib/components/order-data-provider/order-data-provider.ts +++ b/libs/orders/src/lib/components/order-data-provider/order-data-provider.ts @@ -24,6 +24,7 @@ const ORDER_FRAGMENT = gql` positionDecimalPlaces tradableInstrument { instrument { + id code } } diff --git a/libs/orders/src/lib/components/order-list/order-list.tsx b/libs/orders/src/lib/components/order-list/order-list.tsx index 8bf923892..852e3e32a 100644 --- a/libs/orders/src/lib/components/order-list/order-list.tsx +++ b/libs/orders/src/lib/components/order-list/order-list.tsx @@ -120,12 +120,12 @@ export const OrderListTable = forwardRef( data, }: { data: Orders_party_ordersConnection_edges_node; - }) => data.side === Side.Buy, + }) => data?.side === Side.Buy, 'text-vega-red-dark dark:text-vega-red': ({ data, }: { data: Orders_party_ordersConnection_edges_node; - }) => data.side === Side.Sell, + }) => data?.side === Side.Sell, }} valueFormatter={({ value, @@ -136,7 +136,7 @@ export const OrderListTable = forwardRef( if (value === undefined || !data || !data.market) { return undefined; } - const prefix = data.side === Side.Buy ? '+' : '-'; + const prefix = data ? (data.side === Side.Buy ? '+' : '-') : ''; return ( prefix + addDecimal(value, data.market.positionDecimalPlaces) );