After persist the live activity data for welcome8
This commit is contained in:
parent
4762a8160b
commit
51b90b5ce0
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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<T extends { id: string; publicId?: strin
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Marketing display amount: whole USDT-like units (same look as synthetic labels). */
|
||||
export function formatWithdrawalMarketingAmount(raw: string | number): string {
|
||||
const n = typeof raw === 'number' ? raw : Number(raw);
|
||||
if (!Number.isFinite(n)) return '0';
|
||||
const human = n / 1_000_000;
|
||||
if (!Number.isFinite(human) || human <= 0) return '0';
|
||||
return String(Math.max(1, Math.round(human)));
|
||||
}
|
||||
|
||||
function mapRealPlaying(row: marketingRepository.RealActivityRow): MarketingActivityItem {
|
||||
return {
|
||||
id: row.id,
|
||||
@ -242,7 +233,7 @@ function mapRealWithdrawal(row: marketingRepository.RealWithdrawalRow): Marketin
|
||||
return {
|
||||
id: row.id,
|
||||
publicId: maskPublicId(row.user_id),
|
||||
amountLabel: formatWithdrawalMarketingAmount(row.amount),
|
||||
amountLabel: formatAmountRaw(row.amount),
|
||||
statusLabel: 'Completed',
|
||||
createdAt: row.created_at.toISOString(),
|
||||
synthetic: false,
|
||||
|
||||
@ -11,7 +11,6 @@ import {
|
||||
clearMarketingCache,
|
||||
computeActivePlayersCount,
|
||||
formatAmountRaw,
|
||||
formatWithdrawalMarketingAmount,
|
||||
maskPublicId,
|
||||
mergeFeedItems,
|
||||
shouldUseSynthetic,
|
||||
@ -62,9 +61,20 @@ describe('marketingService helpers', () => {
|
||||
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', () => {
|
||||
|
||||
@ -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(),
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
@ -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.',
|
||||
|
||||
@ -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.',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user