77 lines
3.1 KiB
TypeScript
77 lines
3.1 KiB
TypeScript
import { Alert, Chip, Stack, Typography } from '@mui/material';
|
|
import { useTranslation } from 'react-i18next';
|
|
import type { CandlePredictConfig, CandlePredictInterval, CandlePredictRound } from '../types';
|
|
import { PoolBar } from './PoolBar';
|
|
|
|
type Props = {
|
|
config: CandlePredictConfig;
|
|
interval: CandlePredictInterval;
|
|
round: CandlePredictRound | null;
|
|
};
|
|
|
|
/** Admin-only live pool totals and internal settlement rule summary. */
|
|
export function AdminPoolInsights({ config, interval, round }: Props) {
|
|
const { t } = useTranslation();
|
|
|
|
if (!config.poolWinnerRule) return null;
|
|
|
|
const isDailyRevenue = config.poolWinnerRule === 'daily_revenue';
|
|
const parts: string[] = [];
|
|
const tieTolerancePercent = interval.tieTolerancePercent ?? config.tieTolerancePercent ?? 0;
|
|
const tieToleranceMaxPercent = interval.tieToleranceMaxPercent ?? config.tieToleranceMaxPercent ?? 100;
|
|
// Prefer global catalog toggles as master switch (same as settlement).
|
|
// Interval may only further disable — never re-enable rules the catalog turned off.
|
|
const tieToleranceMinEnabled =
|
|
(config.tieToleranceMinEnabled ?? true) && interval.tieToleranceMinEnabled !== false;
|
|
const tieToleranceMaxEnabled =
|
|
(config.tieToleranceMaxEnabled ?? true) && interval.tieToleranceMaxEnabled !== false;
|
|
|
|
if (tieToleranceMinEnabled) {
|
|
parts.push(t('candlePredict.adminInsights.neutralMin', { percent: tieTolerancePercent }));
|
|
}
|
|
if (tieToleranceMaxEnabled) {
|
|
parts.push(t('candlePredict.adminInsights.neutralMax', { percent: tieToleranceMaxPercent }));
|
|
}
|
|
|
|
const neutralityPart =
|
|
parts.length > 0 ? parts.join(' · ') : t('candlePredict.adminInsights.neutralNone');
|
|
|
|
const rulesSummary = isDailyRevenue
|
|
? [
|
|
t('candlePredict.adminInsights.dailyRevenueSummary', {
|
|
target: config.dailyRevenueTarget ?? 0,
|
|
net: config.dailyRevenueNetToday ?? 0,
|
|
}),
|
|
t('candlePredict.adminInsights.dailyRevenueNeutralityPrefix'),
|
|
neutralityPart,
|
|
].join(' ')
|
|
: neutralityPart;
|
|
|
|
const poolWinnerLabel =
|
|
config.poolWinnerRule === 'majority'
|
|
? t('candlePredict.adminInsights.poolWinnerMajority')
|
|
: config.poolWinnerRule === 'daily_revenue'
|
|
? t('candlePredict.adminInsights.poolWinnerDailyRevenue')
|
|
: t('candlePredict.adminInsights.poolWinnerMinority');
|
|
|
|
return (
|
|
<Stack spacing={2}>
|
|
<Alert severity="warning" sx={{ borderRadius: 2 }}>
|
|
<Typography variant="subtitle2" sx={{ fontWeight: 800, mb: 0.5 }}>
|
|
{t('candlePredict.adminInsights.title')}
|
|
</Typography>
|
|
<Stack direction="row" spacing={1} useFlexGap sx={{ flexWrap: 'wrap', mb: 0.75 }}>
|
|
<Chip size="small" label={poolWinnerLabel} color="warning" />
|
|
</Stack>
|
|
<Typography variant="body2" sx={{ opacity: 0.85 }}>
|
|
{rulesSummary}
|
|
</Typography>
|
|
<Typography variant="caption" sx={{ display: 'block', mt: 0.75, opacity: 0.65 }}>
|
|
{t('candlePredict.adminInsights.footer')}
|
|
</Typography>
|
|
</Alert>
|
|
{round && <PoolBar round={round} poolWinnerRule={config.poolWinnerRule} />}
|
|
</Stack>
|
|
);
|
|
}
|