From 1e91b7fd696548f2e74af373e34baefbcc6a2a5e Mon Sep 17 00:00:00 2001 From: madalinaraicu Date: Thu, 14 Jul 2022 15:40:34 +0300 Subject: [PATCH] fix: add market state translations --- .../order-hooks/use-order-validation.spec.tsx | 8 +++--- .../lib/order-hooks/use-order-validation.tsx | 25 ++++++++++++++++--- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/libs/orders/src/lib/order-hooks/use-order-validation.spec.tsx b/libs/orders/src/lib/order-hooks/use-order-validation.spec.tsx index becf26f31..4a87d3f80 100644 --- a/libs/orders/src/lib/order-hooks/use-order-validation.spec.tsx +++ b/libs/orders/src/lib/order-hooks/use-order-validation.spec.tsx @@ -9,7 +9,7 @@ import type { VegaKeyExtended, } from '@vegaprotocol/wallet'; import { MarketState, MarketTradingMode } from '@vegaprotocol/types'; -import type { ValidationProps } from './use-order-validation'; +import { marketTranslations, ValidationProps } from './use-order-validation'; import { useOrderValidation } from './use-order-validation'; import { ERROR_SIZE_DECIMAL } from '../utils/validate-size'; import type { Market } from '../market'; @@ -90,7 +90,7 @@ function setup( return renderHook(() => useOrderValidation({ ...defaultOrder, ...props })); } -describe(`useOrderValidation`, () => { +describe('useOrderValidation', () => { it('Returns empty string when given valid data', () => { const { result } = setup(); expect(result.current).toStrictEqual({ isDisabled: false, message: `` }); @@ -119,7 +119,9 @@ describe(`useOrderValidation`, () => { const { result } = setup({ market: { ...defaultOrder.market, state } }); expect(result.current).toStrictEqual({ isDisabled: true, - message: `This market is ${state.toLowerCase()} and no longer accepting orders`, + message: `This market is ${marketTranslations( + state + )} and no longer accepting orders`, }); } ); diff --git a/libs/orders/src/lib/order-hooks/use-order-validation.tsx b/libs/orders/src/lib/order-hooks/use-order-validation.tsx index a750414f6..f702d8a0d 100644 --- a/libs/orders/src/lib/order-hooks/use-order-validation.tsx +++ b/libs/orders/src/lib/order-hooks/use-order-validation.tsx @@ -19,6 +19,15 @@ export type ValidationProps = { fieldErrors?: FieldErrors; }; +export const marketTranslations = (marketState: MarketState) => { + switch (marketState) { + case MarketState.TradingTerminated: + return t('terminated'); + default: + return t(marketState).toLowerCase(); + } +}; + export const useOrderValidation = ({ step, market, @@ -50,7 +59,9 @@ export const useOrderValidation = ({ return { isDisabled: true, message: t( - `This market is ${market.state.toLowerCase()} and no longer accepting orders` + `This market is ${marketTranslations( + market.state + )} and no longer accepting orders` ), }; } @@ -67,7 +78,9 @@ export const useOrderValidation = ({ return { isDisabled: false, message: t( - `This market is ${market.state.toLowerCase()} and only accepting liquidity orders` + `This market is ${marketTranslations( + market.state + )} and only accepting liquidity orders` ), }; } @@ -103,7 +116,9 @@ export const useOrderValidation = ({ return { isDisabled: false, message: t( - `This market is ${market.state.toLowerCase()} and only accepting liquidity orders` + `This market is ${marketTranslations( + market.state + )} and only accepting liquidity orders` ), }; } @@ -115,7 +130,9 @@ export const useOrderValidation = ({ return { isDisabled: false, message: t( - `This market is ${market.state.toLowerCase()} and only accepting liquidity orders` + `This market is ${marketTranslations( + market.state + )} and only accepting liquidity orders` ), }; }