From 51b90b5ce0336405db42b2cedaf97dc66fca650a Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 22 Oct 2026 14:57:05 +0200 Subject: [PATCH] After persist the live activity data for welcome8 --- backend/src/db/schema.sql | 17 ++++++++++++++--- .../marketingLiveActivitySettingsRepository.ts | 2 +- backend/src/services/marketingService.ts | 13 ++----------- backend/src/tests/marketingService.test.ts | 18 ++++++++++++++---- backend/src/validation/adminResourceSchemas.ts | 2 +- .../features/marketing/MarketingAdminPage.tsx | 3 ++- prediqo_web/src/shared/i18n/locales/en.ts | 2 +- prediqo_web/src/shared/i18n/locales/fr.ts | 2 +- 8 files changed, 36 insertions(+), 23 deletions(-) diff --git a/backend/src/db/schema.sql b/backend/src/db/schema.sql index 479a24fd..5c749e19 100644 --- a/backend/src/db/schema.sql +++ b/backend/src/db/schema.sql @@ -2793,7 +2793,7 @@ CREATE TABLE IF NOT EXISTS marketing_live_activity_settings ( list_rotate_seconds INT NOT NULL DEFAULT 8 CHECK (list_rotate_seconds >= 5 AND list_rotate_seconds <= 60), 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], + synthetic_withdrawal_amounts NUMERIC(18,6)[] NOT NULL DEFAULT ARRAY[20,35,50,80,100,120,200,250,300,450,500,800]::NUMERIC(18,6)[], withdrawal_real_window_hours INT NOT NULL DEFAULT 48 CHECK (withdrawal_real_window_hours > 0), updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW() ); @@ -2822,8 +2822,19 @@ BEGIN AND column_name = 'synthetic_withdrawal_amounts' ) THEN ALTER TABLE marketing_live_activity_settings - ADD COLUMN synthetic_withdrawal_amounts INT[] NOT NULL - DEFAULT ARRAY[20,35,50,80,100,120,200,250,300,450,500,800]; + ADD COLUMN synthetic_withdrawal_amounts NUMERIC(18,6)[] NOT NULL + DEFAULT ARRAY[20,35,50,80,100,120,200,250,300,450,500,800]::NUMERIC(18,6)[]; + ELSIF EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = 'public' AND table_name = 'marketing_live_activity_settings' + AND column_name = 'synthetic_withdrawal_amounts' + AND udt_name = '_int4' + ) THEN + -- Allow decimal fictive amounts (was INT[]). + ALTER TABLE marketing_live_activity_settings + ALTER COLUMN synthetic_withdrawal_amounts + TYPE NUMERIC(18,6)[] + USING synthetic_withdrawal_amounts::NUMERIC(18,6)[]; END IF; IF NOT EXISTS ( SELECT 1 FROM information_schema.columns diff --git a/backend/src/repositories/marketingLiveActivitySettingsRepository.ts b/backend/src/repositories/marketingLiveActivitySettingsRepository.ts index ec22bcf7..bd60d12f 100644 --- a/backend/src/repositories/marketingLiveActivitySettingsRepository.ts +++ b/backend/src/repositories/marketingLiveActivitySettingsRepository.ts @@ -164,7 +164,7 @@ export async function updateLiveActivitySettings( list_rotate_seconds = $9, cache_ttl_seconds = $10, max_synthetic_withdrawals = $11, - synthetic_withdrawal_amounts = $12::int[], + synthetic_withdrawal_amounts = $12::numeric[], withdrawal_real_window_hours = $13, updated_at = NOW() WHERE id = 1 diff --git a/backend/src/services/marketingService.ts b/backend/src/services/marketingService.ts index 1aa6ad4e..37d81235 100644 --- a/backend/src/services/marketingService.ts +++ b/backend/src/services/marketingService.ts @@ -152,7 +152,7 @@ export function buildSyntheticWithdrawalsFromPersonas( items.push({ id: `syn-wd-${slot}-${i}`, publicId: personas[idx].public_id, - amountLabel: String(amount), + amountLabel: formatStakeDisplay(amount), statusLabel: 'Completed', createdAt: new Date(now - i * 90_000).toISOString(), synthetic: true, @@ -217,15 +217,6 @@ export function blendAndRotateFeedItems { assert.equal(formatAmountRaw('50000000'), '50.00'); }); - test('formatWithdrawalMarketingAmount rounds to whole units like synthetics', () => { - assert.equal(formatWithdrawalMarketingAmount('3200000'), '3'); - assert.equal(formatWithdrawalMarketingAmount('120000000'), '120'); + test('formatAmountRaw keeps decimals for real withdrawals', () => { + assert.equal(formatAmountRaw('3200000'), '3.20'); + assert.equal(formatAmountRaw('120000000'), '120.00'); + }); + + test('synthetic withdrawals accept decimal amounts', () => { + const items = buildSyntheticWithdrawalsFromPersonas( + personas, + 3, + [3.2, 20.5, 100], + 0 + ); + assert.equal(items.length, 3); + assert.ok(items.some((i) => i.amountLabel.includes('.'))); }); test('blendAndRotateFeedItems mixes real and synthetic without sticky real-first', () => { diff --git a/backend/src/validation/adminResourceSchemas.ts b/backend/src/validation/adminResourceSchemas.ts index 853d4f1b..e480972c 100644 --- a/backend/src/validation/adminResourceSchemas.ts +++ b/backend/src/validation/adminResourceSchemas.ts @@ -246,7 +246,7 @@ export const marketingLiveActivitySettingsBodySchema = atLeastOneField( cacheTtlSeconds: z.number().int().positive().max(300).optional(), maxSyntheticWithdrawals: z.number().int().min(0).max(100).optional(), syntheticWithdrawalAmounts: z - .array(z.number().int().positive().max(1_000_000_000)) + .array(z.number().positive().max(1_000_000_000)) .min(1) .max(50) .optional(), diff --git a/prediqo_web/src/features/marketing/MarketingAdminPage.tsx b/prediqo_web/src/features/marketing/MarketingAdminPage.tsx index c12d93cf..01717f8b 100644 --- a/prediqo_web/src/features/marketing/MarketingAdminPage.tsx +++ b/prediqo_web/src/features/marketing/MarketingAdminPage.tsx @@ -52,11 +52,12 @@ function amountsEqual(a: number[] | undefined, b: number[] | undefined): boolean } function parseAmountsInput(raw: string): number[] { + // Split on commas/spaces; decimals use a dot (e.g. 3.20, 20, 35.5). return raw .split(/[,\s]+/) .map((s) => s.trim()) .filter(Boolean) - .map((s) => Number(s)) + .map((s) => Number(s.replace(',', '.'))) .filter((n) => Number.isFinite(n) && n > 0); } diff --git a/prediqo_web/src/shared/i18n/locales/en.ts b/prediqo_web/src/shared/i18n/locales/en.ts index fe4b3f57..341a59cf 100644 --- a/prediqo_web/src/shared/i18n/locales/en.ts +++ b/prediqo_web/src/shared/i18n/locales/en.ts @@ -2192,7 +2192,7 @@ export const en = { 'Only show real completed payouts newer than this many hours (default 48). No upper cap — 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.', + 'Comma-separated display amounts; decimals allowed with a dot (e.g. 3.20, 20, 35.5, 100). Rotated across active personas.', save: 'Save settings', saving: 'Saving…', saved: 'Settings saved.', diff --git a/prediqo_web/src/shared/i18n/locales/fr.ts b/prediqo_web/src/shared/i18n/locales/fr.ts index 0f975100..0f25f172 100644 --- a/prediqo_web/src/shared/i18n/locales/fr.ts +++ b/prediqo_web/src/shared/i18n/locales/fr.ts @@ -2212,7 +2212,7 @@ export const fr = { 'N’afficher que les vrais retraits completed plus récents que ce nombre d’heures (défaut 48). Pas de plafond — 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.', + 'Montants séparés par des virgules ; décimales avec un point (ex. 3.20, 20, 35.5, 100). Rotation sur les personas actifs.', save: 'Enregistrer les paramètres', saving: 'Enregistrement…', saved: 'Paramètres enregistrés.',