fix: add market state translations
This commit is contained in:
parent
483ce89706
commit
1e91b7fd69
@ -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`,
|
||||
});
|
||||
}
|
||||
);
|
||||
|
@ -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`
|
||||
),
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user