diff --git a/prediqo_web/src/features/candle-predict/CandlePredictPage.tsx b/prediqo_web/src/features/candle-predict/CandlePredictPage.tsx index 505edeef..992d81a0 100644 --- a/prediqo_web/src/features/candle-predict/CandlePredictPage.tsx +++ b/prediqo_web/src/features/candle-predict/CandlePredictPage.tsx @@ -69,7 +69,6 @@ export function CandlePredictPage() { const { isAdmin } = useAuth(); const theme = useTheme(); const isCompact = useMediaQuery(theme.breakpoints.down('md')); - const chartHeight = isCompact ? 300 : 380; const [selectedIntervalMinutes, setSelectedIntervalMinutes] = useState( undefined @@ -123,6 +122,7 @@ export function CandlePredictPage() { const state = stateQ.data; const config = state?.config; + const chartHeight = isCompact ? 300 : 380; const predictionTypes = config?.predictionTypes ?? { single: true, auto: true, @@ -468,6 +468,20 @@ export function CandlePredictPage() { ); } + const autoPanelProps = { + config, + interval, + intervals, + settings: state?.autoSettings ?? null, + mainBalanceLabel: walletLabels.main, + bonusBalanceLabel: walletLabels.bonus, + testBalanceLabel: walletLabels.test, + saveError: autoSaveError, + onClearSaveError: () => setAutoSaveError(null), + onSave: saveAuto, + saving: autoMut.isPending, + }; + return ( - + {isAdmin && } @@ -591,64 +606,53 @@ export function CandlePredictPage() { {showAutoPanel && ( - setAutoSaveError(null)} - onSave={saveAuto} - saving={autoMut.isPending} - /> + )} - {candlesQ.isLoading ? ( - - ) : ( - void candlesQ.loadOlder()} - /> - )} - - + + {candlesQ.isLoading ? ( + + ) : ( + void candlesQ.loadOlder()} + /> + )} + - + {renderBettingPanels()} - {showAutoPanel && ( - - setAutoSaveError(null)} - onSave={saveAuto} - saving={autoMut.isPending} - /> - - )} + {showAutoPanel && ( + + + + )} + + + + + Promise; saving?: boolean; + /** Compact horizontal bar when auto is already enabled (desktop layout). */ + layout?: 'vertical' | 'horizontal'; }; function intervalLabel(intervals: CandlePredictInterval[], minutes: number): string { return intervals.find((i) => i.intervalMinutes === minutes)?.label ?? `${minutes} min`; } +function stakeAccountShort(kind: StakeAccountKind): string { + if (kind === 'bonus') return 'Bonus'; + if (kind === 'test') return 'Test'; + return 'Main'; +} + +function modeShort(mode: 'each_round' | 'interval'): string { + return mode === 'interval' ? 'Délai minimum' : 'Chaque manche'; +} + /** Auto Prediction configuration panel. */ export function AutoPredictionPanel({ config, @@ -57,9 +69,11 @@ export function AutoPredictionPanel({ onClearSaveError, onSave, saving, + layout = 'vertical', }: Props) { const serverEnabled = settings?.enabled ?? false; const [configuring, setConfiguring] = useState(false); + const [editing, setEditing] = useState(false); const current = settings ?? { enabled: false, @@ -72,7 +86,9 @@ export function AutoPredictionPanel({ lastAutoBetAt: null, }; - const showForm = serverEnabled || configuring; + const isHorizontal = layout === 'horizontal'; + const showCompact = serverEnabled && !editing && !configuring; + const showForm = (serverEnabled || configuring) && !showCompact; const switchChecked = serverEnabled || configuring; const [mode, setMode] = useState<'each_round' | 'interval'>(current.mode ?? 'each_round'); @@ -85,6 +101,7 @@ export function AutoPredictionPanel({ useEffect(() => { if (serverEnabled) { setConfiguring(false); + setEditing(false); } }, [serverEnabled]); @@ -127,6 +144,239 @@ export function AutoPredictionPanel({ }); }; + const settingsForm = showForm ? ( + { + e.preventDefault(); + if (!stakeFieldValid) return; + const fd = new FormData(e.currentTarget); + const selectedMode = fd.get('mode') as 'each_round' | 'interval'; + void onSave({ + enabled: true, + direction: fd.get('direction') as 'short' | 'long', + stakeDisplay: stakeValue, + mode: selectedMode, + stakeAccountKind, + validateWalletBalance: true, + attemptImmediateBet: true, + intervalSeconds: + selectedMode === 'interval' + ? Number(fd.get('intervalSeconds') || 60) + : current.intervalSeconds ?? 60, + }).then(() => setEditing(false)); + }} + > + + + + Target period: + + + + {viewingDifferentPeriod ? ( + + You are viewing {interval.label}. Save to move auto to {interval.label}. + + ) : ( + + Set from the prediction period you select when saving. One auto config per account. + + )} + + + + Direction + + + + { + onClearSaveError?.(); + setStakeAccountKind(kind); + }} + mainBalanceLabel={mainBalanceLabel} + bonusBalanceLabel={bonusBalanceLabel} + testBalanceLabel={testBalanceLabel} + /> + + + + + Mode + + + {mode === 'interval' + ? 'Une mise par manche maximum. Attend au moins le délai indiqué depuis la dernière mise auto avant de parier sur la manche suivante (ou au save).' + : 'Place une mise dès l’ouverture de la fenêtre de prédiction de chaque nouvelle manche.'} + + + + {mode === 'interval' && ( + + )} + + + + {serverEnabled && ( + + )} + + + ) : null; + + if (!serverEnabled && !configuring && isHorizontal) { + return ( + + + + + + Auto Prediction + + Activez pour parier automatiquement à chaque manche. + + + + void handleToggle(e.target.checked)} /> + } + label="Activer la prédiction auto" + /> + + {current.lastAutoBetAt && ( + + Dernière mise auto : {new Date(current.lastAutoBetAt).toLocaleString()} + + )} + + ); + } + + if (showCompact && isHorizontal) { + const directionLabel = current.direction === 'long' ? 'Long' : 'Short'; + const accountKind = current.stakeAccountKind ?? 'main'; + + return ( + + + + + + Prédiction auto active + + + + void handleToggle(e.target.checked)} + /> + } + label="Désactiver" + /> + + + + + + + + + + + + {current.lastAutoBetAt && ( + + Dernière mise auto : {new Date(current.lastAutoBetAt).toLocaleString()} + + )} + + + ); + } + return ( - - Place automatiquement une prédiction par manche sur la période cible, avec - les paramètres ci-dessous. La mise est prélevée sur le portefeuille sélectionné. Rien n'est - envoyé tant que vous n'avez pas cliqué sur Enregistrer. - + {!showCompact && ( + + Place automatiquement une prédiction par manche sur la période cible, avec + les paramètres ci-dessous. La mise est prélevée sur le portefeuille sélectionné. Rien n'est + envoyé tant que vous n'avez pas cliqué sur Enregistrer. + + )} {saveError && showForm && {saveError}} - void handleToggle(e.target.checked)} /> - } - label="Activer la prédiction auto" - /> + {showCompact && !isHorizontal ? ( + <> + + + + + + + + + + {current.lastAutoBetAt && ( + + Dernière mise auto : {new Date(current.lastAutoBetAt).toLocaleString()} + + )} + + ) : null} + + {(showCompact || !serverEnabled) && ( + void handleToggle(e.target.checked)} /> + } + label="Activer la prédiction auto" + /> + )} {configuring && !serverEnabled && ( @@ -166,126 +456,9 @@ export function AutoPredictionPanel({ )} - {showForm && ( - { - e.preventDefault(); - if (!stakeFieldValid) return; - const fd = new FormData(e.currentTarget); - const selectedMode = fd.get('mode') as 'each_round' | 'interval'; - void onSave({ - enabled: true, - direction: fd.get('direction') as 'short' | 'long', - stakeDisplay: stakeValue, - mode: selectedMode, - stakeAccountKind, - validateWalletBalance: true, - attemptImmediateBet: true, - intervalSeconds: - selectedMode === 'interval' ? Number(fd.get('intervalSeconds') || 60) : current.intervalSeconds ?? 60, - }); - }} - > - - - - Target period: - - - - {viewingDifferentPeriod ? ( - - You are viewing {interval.label}. Save to move auto to {interval.label}. - - ) : ( - - Set from the prediction period you select when saving. One auto config per account. - - )} - + {settingsForm} - - Direction - - - - { - onClearSaveError?.(); - setStakeAccountKind(kind); - }} - mainBalanceLabel={mainBalanceLabel} - bonusBalanceLabel={bonusBalanceLabel} - testBalanceLabel={testBalanceLabel} - /> - - - - - Mode - - - {mode === 'interval' - ? 'Une mise par manche maximum. Attend au moins le délai indiqué depuis la dernière mise auto avant de parier sur la manche suivante (ou au save).' - : 'Place une mise dès l’ouverture de la fenêtre de prédiction de chaque nouvelle manche.'} - - - - {mode === 'interval' && ( - - )} - - - - )} - - {current.lastAutoBetAt && ( + {!showCompact && current.lastAutoBetAt && ( Dernière mise auto : {new Date(current.lastAutoBetAt).toLocaleString()} diff --git a/prediqo_web/src/features/candle-predict/components/CandlestickChart.tsx b/prediqo_web/src/features/candle-predict/components/CandlestickChart.tsx index 903a1af6..8987cf80 100644 --- a/prediqo_web/src/features/candle-predict/components/CandlestickChart.tsx +++ b/prediqo_web/src/features/candle-predict/components/CandlestickChart.tsx @@ -13,6 +13,8 @@ const LOAD_MORE_THRESHOLD = 8; type Props = { candles: OhlcCandle[]; height?: number; + /** Grow to fill the parent flex/grid cell (height from ResizeObserver). */ + fillHeight?: boolean; hasMoreOlder?: boolean; loadingOlder?: boolean; onLoadOlder?: () => void; @@ -54,6 +56,7 @@ function applyFixedViewport(chart: IChartApi, barCount: number, followLatest: bo export function CandlestickChart({ candles, height = 380, + fillHeight = false, hasMoreOlder = false, loadingOlder = false, onLoadOlder, @@ -76,8 +79,11 @@ export function CandlestickChart({ useEffect(() => { if (!containerRef.current) return; - const chart = createChart(containerRef.current, { - height, + const container = containerRef.current; + const measuredHeight = fillHeight ? container.clientHeight || height : height; + + const chart = createChart(container, { + height: measuredHeight, layout: { background: { type: ColorType.Solid, color: 'transparent' }, textColor: 'rgba(255,255,255,0.72)', @@ -150,10 +156,15 @@ export function CandlestickChart({ chart.timeScale().subscribeVisibleLogicalRangeChange(onRangeChange); const ro = new ResizeObserver(() => { - if (containerRef.current) { - chart.applyOptions({ width: containerRef.current.clientWidth }); - applyFixedViewport(chart, series.data().length, followLatestRef.current); - } + if (!containerRef.current) return; + const nextHeight = fillHeight + ? containerRef.current.clientHeight || height + : height; + chart.applyOptions({ + width: containerRef.current.clientWidth, + height: nextHeight, + }); + applyFixedViewport(chart, series.data().length, followLatestRef.current); }); ro.observe(containerRef.current); @@ -164,7 +175,7 @@ export function CandlestickChart({ chartRef.current = null; seriesRef.current = null; }; - }, [height]); + }, [height, fillHeight]); useEffect(() => { if (!seriesRef.current || !chartRef.current) return; @@ -209,12 +220,12 @@ export function CandlestickChart({ }, [candles]); return ( - + ); } return ( - + {prediction.isAuto && ( - + )} ); @@ -329,6 +337,53 @@ function PredictionCell({ prediction }: { prediction: CandlePredictPrediction }) return ; } +function PeriodCell({ + prediction, + period, +}: { + prediction: CandlePredictPrediction; + period: ReturnType; +}) { + const meta = [period.detail, period.placedAt].filter(Boolean).join(' · '); + + return ( + + + + {period.range} + + + + {meta && ( + + {meta} + + )} + + ); +} + +const predictionsTableSx = { + width: '100%', + '& th': { + fontWeight: 700, + whiteSpace: 'nowrap', + py: 1.25, + }, + '& td': { + verticalAlign: 'middle', + py: 1.25, + }, +} as const; + /** Paginated list of the user's latest Candle Predict predictions. */ export function RecentPredictionsPanel({ refreshKey, @@ -361,7 +416,7 @@ export function RecentPredictionsPanel({ const total = predictionsQ.data?.total ?? 0; return ( - + ) : ( <> - - - - Mode - Prediction - Period - Stake - Account - Status - Payout - - - - {items.map((p) => { - const period = formatCandlePeriod(p); - const progressDetail = multiProgressDetail(p); - return ( - - - - - - - - - - - - {period.range} - - - - {period.detail && ( - - {period.detail} - - )} - - {period.placedAt} - - - - {p.stakeDisplay} - - - - - - - {progressDetail && ( - - {progressDetail} - - )} - - - {p.payoutDisplay > 0 ? p.payoutDisplay : '—'} - - ); - })} - {!items.length && ( + +
+ - - No predictions yet + Mode + Prediction + Period + + Stake + + Account + Status + + Payout - )} - -
+ + + {items.map((p) => { + const period = formatCandlePeriod(p); + const progressDetail = multiProgressDetail(p); + return ( + + + + + + + + + + + + {p.stakeDisplay} + + + + + + + + + + {progressDetail && ( + + {progressDetail} + + )} + + + + {p.payoutDisplay > 0 ? p.payoutDisplay : '—'} + + + ); + })} + {!items.length && ( + + + No predictions yet + + + )} + + + {total > PREDICTIONS_PAGE_SIZE && ( diff --git a/prediqo_web/src/features/catalog/CandlePredictMultiLevelsPanel.tsx b/prediqo_web/src/features/catalog/CandlePredictMultiLevelsPanel.tsx index eb888431..affb0654 100644 --- a/prediqo_web/src/features/catalog/CandlePredictMultiLevelsPanel.tsx +++ b/prediqo_web/src/features/catalog/CandlePredictMultiLevelsPanel.tsx @@ -20,6 +20,7 @@ import { useUpdateAdminMultiLevels, } from '../candle-predict/hooks/useCandlePredict'; import type { MultiCandleLevel } from '../candle-predict/types'; +import { ScrollableTable } from '../../shared/components/ScrollableTable'; /** Admin panel for multi-candle level configuration. */ export function CandlePredictMultiLevelsPanel() { @@ -67,67 +68,69 @@ export function CandlePredictMultiLevelsPanel() { )} - - - - Level - Candles - Enabled - Pool multiplier - Payout multiplier - Sort - - - - {rows.map((row) => ( - - {row.level} - {row.candleCount} - - updateRow(row.level, { enabled: e.target.checked })} - /> - - - - updateRow(row.level, { poolMultiplier: Number(e.target.value) || 1 }) - } - sx={{ width: 100 }} - /> - - - - updateRow(row.level, { payoutMultiplier: Number(e.target.value) || 1 }) - } - sx={{ width: 100 }} - /> - - - - updateRow(row.level, { sortOrder: Number(e.target.value) || row.level }) - } - sx={{ width: 72 }} - /> - + +
+ + + Level + Candles + Enabled + Pool multiplier + Payout multiplier + Sort - ))} - -
+ + + {rows.map((row) => ( + + {row.level} + {row.candleCount} + + updateRow(row.level, { enabled: e.target.checked })} + /> + + + + updateRow(row.level, { poolMultiplier: Number(e.target.value) || 1 }) + } + sx={{ width: 100 }} + /> + + + + updateRow(row.level, { payoutMultiplier: Number(e.target.value) || 1 }) + } + sx={{ width: 100 }} + /> + + + + updateRow(row.level, { sortOrder: Number(e.target.value) || row.level }) + } + sx={{ width: 72 }} + /> + + + ))} + + +