chore: update with getAsset
This commit is contained in:
@@ -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 &&
|
||||
|
||||
@@ -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 = [
|
||||
|
||||
@@ -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 || '',
|
||||
};
|
||||
|
||||
|
||||
@@ -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<MarketDataUpdateSubscription> = {
|
||||
request: {
|
||||
|
||||
@@ -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 = ({
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
{/* TODO to handle baseAsset for Spots */}
|
||||
{instrument.product && 'settlementAsset' in instrument.product && (
|
||||
{instrument.product && (
|
||||
<div
|
||||
className="w-1/5 text-xs lg:text-sm whitespace-nowrap text-ellipsis overflow-hidden"
|
||||
title={instrument.product.settlementAsset.symbol}
|
||||
title={symbol}
|
||||
data-testid="market-selector-price"
|
||||
role="gridcell"
|
||||
>
|
||||
{price} {instrument.product.settlementAsset.symbol}
|
||||
{price} {symbol}
|
||||
</div>
|
||||
)}
|
||||
<div
|
||||
|
||||
@@ -30,6 +30,7 @@ import BigNumber from 'bignumber.js';
|
||||
import type { Trade } from './fills-data-provider';
|
||||
import type { FillFieldsFragment } from './__generated__/Fills';
|
||||
import { FillActionsDropdown } from './fill-actions-dropdown';
|
||||
import { getAsset } from '@vegaprotocol/markets';
|
||||
|
||||
const TAKER = 'Taker';
|
||||
const MAKER = 'Maker';
|
||||
@@ -141,11 +142,7 @@ const formatPrice = ({
|
||||
if (!data?.market || !isNumeric(value)) {
|
||||
return '-';
|
||||
}
|
||||
const asset =
|
||||
'settlementAsset' in data.market.tradableInstrument.instrument.product
|
||||
? data?.market.tradableInstrument.instrument.product.settlementAsset
|
||||
.symbol
|
||||
: '';
|
||||
const asset = getAsset(data.market);
|
||||
const valueFormatted = addDecimalsFormatNumber(
|
||||
value,
|
||||
data?.market.decimalPlaces
|
||||
@@ -195,10 +192,9 @@ const formatTotal = ({
|
||||
if (!data?.market || !isNumeric(value)) {
|
||||
return '-';
|
||||
}
|
||||
const { symbol: assetSymbol, decimals: assetDecimals } =
|
||||
('settlementAsset' in data.market.tradableInstrument.instrument.product
|
||||
? data?.market.tradableInstrument.instrument.product.settlementAsset
|
||||
: null) ?? {};
|
||||
const { symbol: assetSymbol, decimals: assetDecimals } = getAsset(
|
||||
data.market
|
||||
);
|
||||
const size = new BigNumber(
|
||||
addDecimal(data?.size, data?.market.positionDecimalPlaces)
|
||||
);
|
||||
|
||||
@@ -87,7 +87,11 @@ export const calcCandleVolume = (candles: Candle[]): string | undefined =>
|
||||
candles &&
|
||||
candles.reduce((acc, c) => new BigNumber(acc).plus(c.volume).toString(), '0');
|
||||
|
||||
export const getAsset = (market: Pick<Market, 'tradableInstrument'>) => {
|
||||
export const getAsset = (market: Partial<Market>) => {
|
||||
if (!market.tradableInstrument?.instrument.product) {
|
||||
throw new Error('Invalid tradable instrument');
|
||||
}
|
||||
|
||||
const product = market.tradableInstrument.instrument.product;
|
||||
|
||||
if (product.__typename === 'Perpetual' || product.__typename === 'Future') {
|
||||
|
||||
Reference in New Issue
Block a user