From 5daff151962675c2c6ad6b37ab54509e753a993b Mon Sep 17 00:00:00 2001 From: Amiram_se Date: Thu, 5 Nov 2026 19:01:42 +0400 Subject: [PATCH] fix(signals): send the entry form when publishing a signal Without entryType the API reads an exact entry, so every range signal from the composer was refused with 422. Co-Authored-By: Claude Opus 5.5 --- .../post/repositories/post/mappers.test.ts | 42 +++++++++++++++++++ .../post/repositories/post/mappers.ts | 1 + .../features/post/repositories/post/types.ts | 3 ++ .../use-prediction-composer-page.test.tsx | 7 +++- .../use-prediction-composer-page.ts | 1 + 5 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 platforms/market/src/features/post/repositories/post/mappers.test.ts diff --git a/platforms/market/src/features/post/repositories/post/mappers.test.ts b/platforms/market/src/features/post/repositories/post/mappers.test.ts new file mode 100644 index 0000000..d4f106d --- /dev/null +++ b/platforms/market/src/features/post/repositories/post/mappers.test.ts @@ -0,0 +1,42 @@ +import { describe, expect, it } from 'vitest'; + +import { toCreatePostDto } from './mappers'; + +const prediction = { + symbol: 'btc-usdt', + market: 'crypto', + direction: 'long' as const, + targetPrices: [75000], + stopLoss: 65000, + horizon: '1w', +}; + +describe('toCreatePostDto', () => { + it('sends a range with its entry form, or the API reads an exact entry', () => { + const dto = toCreatePostDto({ + type: 'prediction', + prediction: { + ...prediction, + entryType: 'range', + entryLow: 69000, + entryHigh: 70000, + }, + }); + expect(dto.prediction).toMatchObject({ + entryType: 'range', + entryLow: 69000, + entryHigh: 70000, + }); + }); + + it('sends an exact entry with its entry form', () => { + const dto = toCreatePostDto({ + type: 'prediction', + prediction: { ...prediction, entryType: 'exact', entryPrice: 69500 }, + }); + expect(dto.prediction).toMatchObject({ + entryType: 'exact', + entryPrice: 69500, + }); + }); +}); diff --git a/platforms/market/src/features/post/repositories/post/mappers.ts b/platforms/market/src/features/post/repositories/post/mappers.ts index c4e7e6b..8248eb3 100644 --- a/platforms/market/src/features/post/repositories/post/mappers.ts +++ b/platforms/market/src/features/post/repositories/post/mappers.ts @@ -113,6 +113,7 @@ function toPredictionDto(args: PredictionArgs): PredictionDto { market: args.market.trim(), direction: args.direction, entryPrice: args.entryPrice ?? undefined, + entryType: args.entryType, entryLow: args.entryLow ?? undefined, entryHigh: args.entryHigh ?? undefined, targetPrices: args.targetPrices, diff --git a/platforms/market/src/features/post/repositories/post/types.ts b/platforms/market/src/features/post/repositories/post/types.ts index 6c83dce..005619b 100644 --- a/platforms/market/src/features/post/repositories/post/types.ts +++ b/platforms/market/src/features/post/repositories/post/types.ts @@ -154,6 +154,8 @@ export type PredictionArgs = { symbol: string; market: string; direction: PredictionDirection; + /** Which entry form the API reads; it takes `exact` when this is left out. */ + entryType?: 'exact' | 'range'; /** Exactly one form to publish: this, or `entryLow` with `entryHigh`. */ entryPrice?: number; entryLow?: number; @@ -203,6 +205,7 @@ export type PredictionDto = { symbol: string; market: string; direction: PredictionDirection; + entryType?: 'exact' | 'range'; entryPrice?: number; entryLow?: number; entryHigh?: number; diff --git a/platforms/market/src/features/prediction/models/prediction-composer/use-prediction-composer-page.test.tsx b/platforms/market/src/features/prediction/models/prediction-composer/use-prediction-composer-page.test.tsx index 971bf9a..a2b043a 100644 --- a/platforms/market/src/features/prediction/models/prediction-composer/use-prediction-composer-page.test.tsx +++ b/platforms/market/src/features/prediction/models/prediction-composer/use-prediction-composer-page.test.tsx @@ -205,6 +205,7 @@ describe('usePredictionComposerPage publishing', () => { await act(async () => result.current.publish()); const [args] = vi.mocked(publishPrediction).mock.calls[0]; expect(args.prediction).toMatchObject({ + entryType: 'exact', entryPrice: 100, stopLoss: 90, targetPrices: [120], @@ -231,7 +232,11 @@ describe('usePredictionComposerPage publishing', () => { await act(async () => result.current.publish()); const [args] = vi.mocked(publishPrediction).mock.calls[0]; - expect(args.prediction).toMatchObject({ entryLow: 98, entryHigh: 102 }); + expect(args.prediction).toMatchObject({ + entryType: 'range', + entryLow: 98, + entryHigh: 102, + }); expect(args.prediction.entryPrice).toBeUndefined(); }); diff --git a/platforms/market/src/features/prediction/models/prediction-composer/use-prediction-composer-page.ts b/platforms/market/src/features/prediction/models/prediction-composer/use-prediction-composer-page.ts index 5a7f4c9..d475c97 100644 --- a/platforms/market/src/features/prediction/models/prediction-composer/use-prediction-composer-page.ts +++ b/platforms/market/src/features/prediction/models/prediction-composer/use-prediction-composer-page.ts @@ -431,6 +431,7 @@ export function usePredictionComposerPage({ symbol: sent.symbol, market: sent.market, direction: sent.direction, + entryType: sent.entryMode, ...(sent.entryMode === 'range' ? { entryLow: sent.entryLow ?? undefined,