fix: add market state translations

This commit is contained in:
madalinaraicu 2022-07-14 15:40:34 +03:00
parent 483ce89706
commit 1e91b7fd69
2 changed files with 26 additions and 7 deletions

View File

@ -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`,
});
}
);

View File

@ -19,6 +19,15 @@ export type ValidationProps = {
fieldErrors?: FieldErrors<Order>;
};
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`
),
};
}