diff --git a/backend/src/db/schema.sql b/backend/src/db/schema.sql index b78bf4b9..1dc8e241 100644 --- a/backend/src/db/schema.sql +++ b/backend/src/db/schema.sql @@ -2794,6 +2794,7 @@ CREATE TABLE IF NOT EXISTS marketing_live_activity_settings ( cache_ttl_seconds INT NOT NULL DEFAULT 12 CHECK (cache_ttl_seconds > 0), max_synthetic_withdrawals INT NOT NULL DEFAULT 12 CHECK (max_synthetic_withdrawals >= 0 AND max_synthetic_withdrawals <= 100), synthetic_withdrawal_amounts INT[] NOT NULL DEFAULT ARRAY[20,35,50,80,100,120,200,250,300,450,500,800], + withdrawal_real_window_hours INT NOT NULL DEFAULT 48 CHECK (withdrawal_real_window_hours > 0 AND withdrawal_real_window_hours <= 720), updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW() ); @@ -2831,6 +2832,15 @@ BEGIN ADD COLUMN display_active_spread INT NOT NULL DEFAULT 40 CHECK (display_active_spread >= 0 AND display_active_spread <= 500); END IF; + IF NOT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' AND table_name = 'marketing_live_activity_settings' + AND column_name = 'withdrawal_real_window_hours' + ) THEN + ALTER TABLE marketing_live_activity_settings + ADD COLUMN withdrawal_real_window_hours INT NOT NULL DEFAULT 48 + CHECK (withdrawal_real_window_hours > 0 AND withdrawal_real_window_hours <= 720); + END IF; END $$; INSERT INTO marketing_personas (public_id, is_active, sort_order) diff --git a/backend/src/repositories/marketingLiveActivitySettingsRepository.ts b/backend/src/repositories/marketingLiveActivitySettingsRepository.ts index 14cce314..ec22bcf7 100644 --- a/backend/src/repositories/marketingLiveActivitySettingsRepository.ts +++ b/backend/src/repositories/marketingLiveActivitySettingsRepository.ts @@ -18,6 +18,7 @@ export type MarketingLiveActivitySettingsRow = { cache_ttl_seconds: number; max_synthetic_withdrawals: number; synthetic_withdrawal_amounts: number[] | string | null; + withdrawal_real_window_hours: number; updated_at: Date; }; @@ -34,6 +35,7 @@ export type MarketingLiveActivitySettings = { cacheTtlSeconds: number; maxSyntheticWithdrawals: number; syntheticWithdrawalAmounts: number[]; + withdrawalRealWindowHours: number; updatedAt: string; }; @@ -50,6 +52,7 @@ const DEFAULTS: Omit = { cacheTtlSeconds: 12, maxSyntheticWithdrawals: 12, syntheticWithdrawalAmounts: [...DEFAULT_SYNTHETIC_WITHDRAWAL_AMOUNTS], + withdrawalRealWindowHours: 48, }; function parseAmounts(raw: number[] | string | null | undefined): number[] { @@ -84,6 +87,8 @@ function mapRow(row: MarketingLiveActivitySettingsRow): MarketingLiveActivitySet maxSyntheticWithdrawals: Number(row.max_synthetic_withdrawals) || 0, syntheticWithdrawalAmounts: amounts.length > 0 ? amounts : [...DEFAULT_SYNTHETIC_WITHDRAWAL_AMOUNTS], + withdrawalRealWindowHours: + Number(row.withdrawal_real_window_hours) || DEFAULTS.withdrawalRealWindowHours, updatedAt: row.updated_at.toISOString(), }; } @@ -91,7 +96,7 @@ function mapRow(row: MarketingLiveActivitySettingsRow): MarketingLiveActivitySet const SELECT_COLS = `id, enabled, real_active_threshold, max_synthetic_entries, display_active_target, display_active_spread, active_window_minutes, feed_real_fetch, client_refresh_seconds, list_rotate_seconds, cache_ttl_seconds, max_synthetic_withdrawals, - synthetic_withdrawal_amounts, updated_at`; + synthetic_withdrawal_amounts, withdrawal_real_window_hours, updated_at`; export async function getLiveActivitySettings(): Promise { const rows = await query( @@ -117,6 +122,7 @@ export type LiveActivitySettingsPatch = Partial<{ cacheTtlSeconds: number; maxSyntheticWithdrawals: number; syntheticWithdrawalAmounts: number[]; + withdrawalRealWindowHours: number; }>; export async function updateLiveActivitySettings( @@ -137,6 +143,8 @@ export async function updateLiveActivitySettings( maxSyntheticWithdrawals: patch.maxSyntheticWithdrawals ?? current.maxSyntheticWithdrawals, syntheticWithdrawalAmounts: patch.syntheticWithdrawalAmounts ?? current.syntheticWithdrawalAmounts, + withdrawalRealWindowHours: + patch.withdrawalRealWindowHours ?? current.withdrawalRealWindowHours, }; if (!Array.isArray(next.syntheticWithdrawalAmounts) || next.syntheticWithdrawalAmounts.length === 0) { @@ -157,6 +165,7 @@ export async function updateLiveActivitySettings( cache_ttl_seconds = $10, max_synthetic_withdrawals = $11, synthetic_withdrawal_amounts = $12::int[], + withdrawal_real_window_hours = $13, updated_at = NOW() WHERE id = 1 RETURNING ${SELECT_COLS}`, @@ -173,6 +182,7 @@ export async function updateLiveActivitySettings( next.cacheTtlSeconds, next.maxSyntheticWithdrawals, next.syntheticWithdrawalAmounts, + next.withdrawalRealWindowHours, ] ); if (!rows[0]) { diff --git a/backend/src/repositories/marketingRepository.ts b/backend/src/repositories/marketingRepository.ts index 4043f56f..41590439 100644 --- a/backend/src/repositories/marketingRepository.ts +++ b/backend/src/repositories/marketingRepository.ts @@ -92,14 +92,21 @@ export type RealWithdrawalRow = { created_at: Date; }; -/** Completed withdrawals only (confirmed payouts). */ -export async function listRecentRealWithdrawals(limit: number): Promise { +/** + * Recent completed withdrawals within [windowHours] (default 48). + * Avoids stale multi-day payouts sticking forever when volume is low. + */ +export async function listRecentRealWithdrawals( + limit: number, + windowHours = 48 +): Promise { return query( `SELECT id, user_id, amount::text AS amount, status, created_at FROM transactions WHERE type = 'withdrawal' AND status = 'completed' + AND created_at >= NOW() - ($2::int * INTERVAL '1 hour') ORDER BY created_at DESC LIMIT $1`, - [limit] + [limit, windowHours] ); } diff --git a/backend/src/services/marketingService.ts b/backend/src/services/marketingService.ts index cd04a5d7..e406d093 100644 --- a/backend/src/services/marketingService.ts +++ b/backend/src/services/marketingService.ts @@ -268,7 +268,7 @@ export async function getWithdrawalFeed(): Promise<{ items: MarketingWithdrawalI return cached('withdrawal-feed', ttlMs, async () => { const pad = settings.maxSyntheticWithdrawals; const [rows, realActive, personas] = await Promise.all([ - marketingRepository.listRecentRealWithdrawals(8), + marketingRepository.listRecentRealWithdrawals(8, settings.withdrawalRealWindowHours), marketingRepository.countRecentDistinctPlayers(settings.activeWindowMinutes), loadActivePersonasCached(ttlMs, Math.max(pad, settings.maxSyntheticEntries)), ]); diff --git a/backend/src/validation/adminResourceSchemas.ts b/backend/src/validation/adminResourceSchemas.ts index 96b44b1c..8e8fa4a0 100644 --- a/backend/src/validation/adminResourceSchemas.ts +++ b/backend/src/validation/adminResourceSchemas.ts @@ -250,6 +250,7 @@ export const marketingLiveActivitySettingsBodySchema = atLeastOneField( .min(1) .max(50) .optional(), + withdrawalRealWindowHours: z.number().int().positive().max(720).optional(), }) ); diff --git a/prediqo_web/src/features/marketing/MarketingAdminPage.tsx b/prediqo_web/src/features/marketing/MarketingAdminPage.tsx index 3a3f3bbf..c12d93cf 100644 --- a/prediqo_web/src/features/marketing/MarketingAdminPage.tsx +++ b/prediqo_web/src/features/marketing/MarketingAdminPage.tsx @@ -42,6 +42,7 @@ type LiveActivitySettings = { cacheTtlSeconds: number; maxSyntheticWithdrawals: number; syntheticWithdrawalAmounts: number[]; + withdrawalRealWindowHours: number; updatedAt: string; }; @@ -103,6 +104,7 @@ export function MarketingAdminPage() { syntheticWithdrawalAmounts: settingsQuery.data.syntheticWithdrawalAmounts?.length ? settingsQuery.data.syntheticWithdrawalAmounts : [20, 35, 50, 80, 100, 120, 200, 250, 300, 450, 500, 800], + withdrawalRealWindowHours: settingsQuery.data.withdrawalRealWindowHours ?? 48, }; setForm(data); setAmountsText(data.syntheticWithdrawalAmounts.join(', ')); @@ -179,6 +181,7 @@ export function MarketingAdminPage() { form.listRotateSeconds !== settingsQuery.data.listRotateSeconds || form.cacheTtlSeconds !== settingsQuery.data.cacheTtlSeconds || form.maxSyntheticWithdrawals !== settingsQuery.data.maxSyntheticWithdrawals || + form.withdrawalRealWindowHours !== settingsQuery.data.withdrawalRealWindowHours || !amountsEqual(parsedAmounts, settingsQuery.data.syntheticWithdrawalAmounts)); if (settingsQuery.isLoading || !form) { @@ -314,15 +317,25 @@ export function MarketingAdminPage() { fullWidth /> setAmountsText(e.target.value)} - helperText={t('admin.marketing.syntheticWithdrawalAmountsHelper')} + label={t('admin.marketing.withdrawalRealWindowHours')} + type="number" + value={form.withdrawalRealWindowHours} + onChange={(e) => + setForm({ ...form, withdrawalRealWindowHours: Number(e.target.value) || 0 }) + } + helperText={t('admin.marketing.withdrawalRealWindowHoursHelper')} fullWidth - multiline - minRows={2} /> + setAmountsText(e.target.value)} + helperText={t('admin.marketing.syntheticWithdrawalAmountsHelper')} + fullWidth + multiline + minRows={2} + /> {saveMut.isError && ( @@ -353,6 +366,7 @@ export function MarketingAdminPage() { cacheTtlSeconds: form.cacheTtlSeconds, maxSyntheticWithdrawals: form.maxSyntheticWithdrawals, syntheticWithdrawalAmounts: parsedAmounts, + withdrawalRealWindowHours: form.withdrawalRealWindowHours, }); }} > diff --git a/prediqo_web/src/shared/i18n/locales/en.ts b/prediqo_web/src/shared/i18n/locales/en.ts index 67b7a6ae..704239f3 100644 --- a/prediqo_web/src/shared/i18n/locales/en.ts +++ b/prediqo_web/src/shared/i18n/locales/en.ts @@ -2187,6 +2187,9 @@ export const en = { maxSyntheticWithdrawals: 'Max synthetic withdrawals', maxSyntheticWithdrawalsHelper: 'Cap of fictive rows added to the withdrawals feed (0–100). Same enable/threshold as Live Activity.', + withdrawalRealWindowHours: 'Real withdrawals window (hours)', + withdrawalRealWindowHoursHelper: + 'Only show real completed payouts newer than this (default 48). Older ones drop out so the feed can rotate with synthetics.', syntheticWithdrawalAmounts: 'Withdrawal amounts', syntheticWithdrawalAmountsHelper: 'Comma-separated display amounts (e.g. 20, 35, 50, 100). Rotated across active personas.', diff --git a/prediqo_web/src/shared/i18n/locales/fr.ts b/prediqo_web/src/shared/i18n/locales/fr.ts index b719a43f..270c5592 100644 --- a/prediqo_web/src/shared/i18n/locales/fr.ts +++ b/prediqo_web/src/shared/i18n/locales/fr.ts @@ -2207,6 +2207,9 @@ export const fr = { maxSyntheticWithdrawals: 'Max retraits synthétiques', maxSyntheticWithdrawalsHelper: 'Plafond de lignes fictives ajoutées au feed retraits (0–100). Même activation/seuil que Live Activity.', + withdrawalRealWindowHours: 'Fenêtre retraits réels (heures)', + withdrawalRealWindowHoursHelper: + 'N’afficher que les vrais retraits completed plus récents que cette durée (défaut 48 h). Les plus anciens sortent pour laisser tourner les fictifs.', syntheticWithdrawalAmounts: 'Montants de retraits', syntheticWithdrawalAmountsHelper: 'Montants affichés séparés par des virgules (ex. 20, 35, 50, 100). Rotation sur les personas actifs.',