From 3452b15cf1a36fdec4f076704f2df1c182c3f7c0 Mon Sep 17 00:00:00 2001
From: Madalina Raicu
Date: Wed, 23 Aug 2023 17:40:56 +0100
Subject: [PATCH] chore: update with getAsset
---
.../src/integration/closed-markets.cy.ts | 4 ++--
apps/trading/client-pages/markets/closed.spec.tsx | 6 ++----
apps/trading/client-pages/markets/closed.tsx | 12 ++----------
.../market-selector/market-selector-item.spec.tsx | 7 ++-----
.../market-selector/market-selector-item.tsx | 10 +++++-----
libs/fills/src/lib/fills-table.tsx | 14 +++++---------
libs/markets/src/lib/market-utils.ts | 6 +++++-
7 files changed, 23 insertions(+), 36 deletions(-)
diff --git a/apps/trading-e2e/src/integration/closed-markets.cy.ts b/apps/trading-e2e/src/integration/closed-markets.cy.ts
index 85da8d650..32b067b98 100644
--- a/apps/trading-e2e/src/integration/closed-markets.cy.ts
+++ b/apps/trading-e2e/src/integration/closed-markets.cy.ts
@@ -23,6 +23,7 @@ import {
addDecimalsFormatNumber,
getDateTimeFormat,
} from '@vegaprotocol/utils';
+import { getAsset } from '@vegaprotocol/markets';
describe('Closed markets', { tags: '@smoke' }, () => {
const settlementDataProperty = 'settlement-data-property';
@@ -367,8 +368,7 @@ describe('Closed markets', { tags: '@smoke' }, () => {
)
);
- const settlementAssetSymbol =
- 'settlementAsset' in product ? product.settlementAsset.symbol : '';
+ const settlementAssetSymbol = getAsset(settledMarket).symbol;
// 6001-MARK-018
settlementAssetSymbol &&
diff --git a/apps/trading/client-pages/markets/closed.spec.tsx b/apps/trading/client-pages/markets/closed.spec.tsx
index 4cbb0d5ab..b983ca831 100644
--- a/apps/trading/client-pages/markets/closed.spec.tsx
+++ b/apps/trading/client-pages/markets/closed.spec.tsx
@@ -17,6 +17,7 @@ import {
MarketsDataDocument,
MarketsDocument,
SuccessorMarketIdsDocument,
+ getAsset,
} from '@vegaprotocol/markets';
import type { VegaWalletContextShape } from '@vegaprotocol/wallet';
import { VegaWalletContext } from '@vegaprotocol/wallet';
@@ -232,10 +233,7 @@ describe('Closed', () => {
expect(headers).toHaveLength(expectedHeaders.length);
expect(headers.map((h) => h.textContent?.trim())).toEqual(expectedHeaders);
- const assetSymbol =
- 'settlementAsset' in market.tradableInstrument.instrument.product
- ? market.tradableInstrument.instrument.product.settlementAsset.symbol
- : '';
+ const assetSymbol = getAsset(market).symbol;
const cells = screen.getAllByRole('gridcell');
const expectedValues = [
diff --git a/apps/trading/client-pages/markets/closed.tsx b/apps/trading/client-pages/markets/closed.tsx
index e787a8329..81be01ed5 100644
--- a/apps/trading/client-pages/markets/closed.tsx
+++ b/apps/trading/client-pages/markets/closed.tsx
@@ -21,6 +21,7 @@ import type { DataSourceFilterFragment } from '@vegaprotocol/markets';
import {
MarketActionsDropdown,
closedMarketsWithDataProvider,
+ getAsset,
} from '@vegaprotocol/markets';
import { useAssetDetailsDialogStore } from '@vegaprotocol/assets';
import type { ColDef } from 'ag-grid-community';
@@ -101,16 +102,7 @@ export const Closed = () => {
'dataSourceSpecForTradingTermination' in instrument.product
? instrument.product.dataSourceSpecForTradingTermination.id
: '',
- settlementAsset:
- 'settlementAsset' in instrument.product
- ? instrument.product.settlementAsset
- : {
- id: '',
- decimals: 0,
- quantum: '0',
- name: '',
- symbol: '',
- },
+ settlementAsset: getAsset({ tradableInstrument: { instrument } }),
productType: instrument.product.__typename || '',
};
diff --git a/apps/trading/components/market-selector/market-selector-item.spec.tsx b/apps/trading/components/market-selector/market-selector-item.spec.tsx
index bd23a6d2d..ce4249499 100644
--- a/apps/trading/components/market-selector/market-selector-item.spec.tsx
+++ b/apps/trading/components/market-selector/market-selector-item.spec.tsx
@@ -10,7 +10,7 @@ import type {
MarketDataUpdateFieldsFragment,
MarketDataUpdateSubscription,
} from '@vegaprotocol/markets';
-import { MarketCandlesDocument } from '@vegaprotocol/markets';
+import { MarketCandlesDocument, getAsset } from '@vegaprotocol/markets';
import { MarketDataUpdateDocument } from '@vegaprotocol/markets';
import {
AuctionTrigger,
@@ -118,10 +118,7 @@ describe('MarketSelectorItem', () => {
});
it('renders market information', async () => {
- const symbol =
- 'settlementAsset' in market.tradableInstrument.instrument.product
- ? market.tradableInstrument.instrument.product.settlementAsset.symbol
- : '';
+ const symbol = getAsset(market).symbol;
const mock: MockedResponse = {
request: {
diff --git a/apps/trading/components/market-selector/market-selector-item.tsx b/apps/trading/components/market-selector/market-selector-item.tsx
index 2284331b1..094e0a7e6 100644
--- a/apps/trading/components/market-selector/market-selector-item.tsx
+++ b/apps/trading/components/market-selector/market-selector-item.tsx
@@ -3,7 +3,7 @@ import { Link } from 'react-router-dom';
import classNames from 'classnames';
import { addDecimalsFormatNumber } from '@vegaprotocol/utils';
import type { MarketMaybeWithDataAndCandles } from '@vegaprotocol/markets';
-import { calcCandleVolume } from '@vegaprotocol/markets';
+import { calcCandleVolume, getAsset } from '@vegaprotocol/markets';
import { useCandles } from '@vegaprotocol/markets';
import { useMarketDataUpdateSubscription } from '@vegaprotocol/markets';
import { Sparkline } from '@vegaprotocol/ui-toolkit';
@@ -90,6 +90,7 @@ const MarketData = ({
: '0.00';
const productType = market.tradableInstrument.instrument.product.__typename;
+ const symbol = getAsset(market).symbol || '';
return (
<>
@@ -106,15 +107,14 @@ const MarketData = ({
)}
- {/* TODO to handle baseAsset for Spots */}
- {instrument.product && 'settlementAsset' in instrument.product && (
+ {instrument.product && (
- {price} {instrument.product.settlementAsset.symbol}
+ {price} {symbol}
)}
candles &&
candles.reduce((acc, c) => new BigNumber(acc).plus(c.volume).toString(), '0');
-export const getAsset = (market: Pick) => {
+export const getAsset = (market: Partial) => {
+ if (!market.tradableInstrument?.instrument.product) {
+ throw new Error('Invalid tradable instrument');
+ }
+
const product = market.tradableInstrument.instrument.product;
if (product.__typename === 'Perpetual' || product.__typename === 'Future') {