After changing about commission dispatch and adding sharing card4

This commit is contained in:
Your Name 2026-08-02 08:30:01 +02:00
parent b11b79722b
commit f08fe0ca8f
12 changed files with 134 additions and 26 deletions

View File

@ -16,7 +16,12 @@ import type { Transaction } from '../models';
export type ShareableBetStatus = 'won' | 'lost' | 'refunded';
export type StakeAccountKind = 'main' | 'bonus' | 'test';
export type ShareableWalletOpType = 'deposit' | 'withdrawal' | 'transfer';
export type ShareableWalletOpType =
| 'deposit'
| 'withdrawal'
| 'transfer'
| 'bonus'
| 'admin_adjustment';
const STAKE_DECIMALS = 6;
@ -59,7 +64,14 @@ export function canShareWalletOperation(
input: { type: string }
): boolean {
if (!settings.enabled || !settings.wallet_ops_enabled) return false;
if (input.type === 'deposit') return settings.allow_deposit;
// Deposits tab also lists bonus credits and admin balance adjustments.
if (
input.type === 'deposit' ||
input.type === 'bonus' ||
input.type === 'admin_adjustment'
) {
return settings.allow_deposit;
}
if (input.type === 'withdrawal') return settings.allow_withdrawal;
if (input.type === 'transfer') return settings.allow_transfer;
return false;
@ -76,18 +88,27 @@ function rawToDisplay(raw: bigint, decimals = STAKE_DECIMALS): string {
return neg ? `-${body}` : body;
}
function computeResultAmount(status: ShareableBetStatus, stakeRaw: bigint, payoutRaw: bigint): {
/**
* Amount shown on share cards — matches Wallet/Recent Predictions UI:
* - won: full payout (stake + profit), e.g. +9.5
* - lost: −stake
* - refunded: +payout when stake is returned, else 0
*/
export function computeResultAmount(
status: ShareableBetStatus,
stakeRaw: bigint,
payoutRaw: bigint
): {
resultSignedDisplay: string;
resultRaw: string;
pnlSign: '+' | '-' | '';
} {
if (status === 'won') {
const pnl = payoutRaw - stakeRaw;
const display = rawToDisplay(pnl);
const display = rawToDisplay(payoutRaw);
return {
resultSignedDisplay: pnl >= 0n ? `+${display}` : display,
resultRaw: pnl.toString(),
pnlSign: pnl >= 0n ? '+' : '-',
resultSignedDisplay: `+${display}`,
resultRaw: payoutRaw.toString(),
pnlSign: '+',
};
}
if (status === 'lost') {
@ -98,6 +119,14 @@ function computeResultAmount(status: ShareableBetStatus, stakeRaw: bigint, payou
pnlSign: '-',
};
}
if (payoutRaw > 0n) {
const display = rawToDisplay(payoutRaw);
return {
resultSignedDisplay: `+${display}`,
resultRaw: payoutRaw.toString(),
pnlSign: '+',
};
}
return {
resultSignedDisplay: '0',
resultRaw: '0',
@ -233,7 +262,11 @@ async function buildWalletOpCardPayload(
: `${getPublicWebBaseUrl()}/register`;
const signedDisplay =
tx.type === 'deposit' ? `+${amountDisplay}` : tx.type === 'withdrawal' ? `-${amountDisplay}` : amountDisplay;
tx.type === 'withdrawal'
? `-${amountDisplay}`
: tx.type === 'transfer'
? amountDisplay
: `+${amountDisplay}`;
return {
kind: 'wallet' as const,
@ -385,6 +418,7 @@ export async function getPublicVerifyPayload(token: string) {
sequence: card.sequence,
multiLevel: card.multiLevel,
predictionMode: card.predictionMode,
isAuto: card.isAuto,
status: card.status,
resultSignedDisplay: card.resultSignedDisplay,
stakeDisplay: card.stakeDisplay,

View File

@ -3,6 +3,7 @@ import assert from 'node:assert/strict';
import {
canSharePredictionResult,
canShareWalletOperation,
computeResultAmount,
createShareVerifyToken,
parseShareVerifyToken,
} from '../services/shareCardService';
@ -71,10 +72,16 @@ describe('share card eligibility', () => {
test('wallet ops respect global and per-type flags', () => {
assert.equal(canShareWalletOperation(settings(), { type: 'deposit' }), true);
assert.equal(canShareWalletOperation(settings(), { type: 'bonus' }), true);
assert.equal(canShareWalletOperation(settings(), { type: 'admin_adjustment' }), true);
assert.equal(
canShareWalletOperation(settings({ wallet_ops_enabled: false }), { type: 'deposit' }),
false
);
assert.equal(
canShareWalletOperation(settings({ allow_deposit: false }), { type: 'bonus' }),
false
);
assert.equal(
canShareWalletOperation(settings({ allow_transfer: false }), { type: 'transfer' }),
false
@ -83,6 +90,19 @@ describe('share card eligibility', () => {
});
});
describe('share card result amount', () => {
test('won uses full payout including stake', () => {
// stake 5 USDT, payout 9.5 USDT → +9.5 (not net +4.5)
const result = computeResultAmount('won', 5_000_000n, 9_500_000n);
assert.equal(result.resultSignedDisplay, '+9.5');
});
test('lost uses minus stake', () => {
const result = computeResultAmount('lost', 5_000_000n, 0n);
assert.equal(result.resultSignedDisplay, '-5');
});
});
describe('share card verify token', () => {
test('round-trips bet and user ids', () => {
const betId = '11111111-1111-1111-1111-111111111111';

View File

@ -63,6 +63,8 @@ class ShareCardConfig {
if (!enabled || !walletOpsEnabled) return false;
switch (operationType) {
case 'deposit':
case 'bonus':
case 'admin_adjustment':
return allowDeposit;
case 'withdrawal':
return allowWithdrawal;

View File

@ -206,6 +206,7 @@ class _PredictionCard extends StatelessWidget {
amountLine: '${payload.resultSignedDisplay ?? '0'} USDT',
subtitle: statusLabel,
rows: [
_KV(s.t('Mode', 'Mode'), _modeLabel(s)),
_KV(s.t('Prediction', 'Prédiction'), direction),
_KV(s.t('Interval', 'Intervalle'), '${payload.intervalMinutes ?? 1} min'),
_KV(s.t('Stake', 'Mise'), '${payload.stakeDisplay ?? 0} USDT'),
@ -216,6 +217,14 @@ class _PredictionCard extends StatelessWidget {
}
String _dirLabel(String d) => d == 'short' ? 'Short' : 'Long';
String _modeLabel(AppStrings s) {
if (payload.isAuto) return s.t('Auto', 'Auto');
if (payload.predictionMode == 'multi_candle') {
return s.t('Multi candle', 'Multi candle');
}
return s.t('Single candle', 'Single candle');
}
}
class _WalletCard extends StatelessWidget {
@ -225,6 +234,8 @@ class _WalletCard extends StatelessWidget {
Color get _accent {
switch (payload.operationType) {
case 'deposit':
case 'bonus':
case 'admin_adjustment':
return const Color(0xFF3DDC97);
case 'withdrawal':
return const Color(0xFF5EB2D6);
@ -241,6 +252,8 @@ class _WalletCard extends StatelessWidget {
'deposit' => s.t('Deposit', 'Dépôt'),
'withdrawal' => s.t('Withdrawal', 'Retrait'),
'transfer' => s.t('Transfer', 'Transfert'),
'bonus' => s.t('Bonus credit', 'Crédit bonus'),
'admin_adjustment' => s.t('Balance adjustment', 'Ajustement de solde'),
_ => payload.operationType ?? '',
};
final statusLabel = switch (payload.txStatus) {

View File

@ -889,8 +889,11 @@ class _StatusTxTile extends StatelessWidget {
);
final status = transactionStatusLabel(tx.status, strings);
final statusColor = _statusColor(tx.status);
final canShare =
tx.type == 'deposit' || tx.type == 'withdrawal' || tx.type == 'transfer';
final canShare = tx.type == 'deposit' ||
tx.type == 'withdrawal' ||
tx.type == 'transfer' ||
tx.type == 'bonus' ||
tx.type == 'admin_adjustment';
return PredCard(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),

View File

@ -21,7 +21,7 @@ type PredictionProps = {
type WalletProps = {
kind: 'wallet';
transactionId: string;
operationType: 'deposit' | 'withdrawal' | 'transfer';
operationType: 'deposit' | 'withdrawal' | 'transfer' | 'bonus' | 'admin_adjustment';
size?: 'small' | 'medium';
};

View File

@ -21,6 +21,8 @@ const PREDICTION_COLOR: Record<ShareCardPredictionPayload['status'], string> = {
const OP_COLOR: Record<ShareCardWalletPayload['operationType'], string> = {
deposit: '#3DDC97',
bonus: '#3DDC97',
admin_adjustment: '#7DDEA2',
withdrawal: '#5EB2D6',
transfer: '#C4A4FF',
};
@ -32,6 +34,15 @@ export function ShareResultCard({ payload, cardRef }: Props) {
return <PredictionCard payload={payload} cardRef={cardRef} />;
}
function predictionModeLabel(
payload: ShareCardPredictionPayload,
t: (key: string) => string
): string {
if (payload.isAuto) return t('shareCard.modeAuto');
if (payload.predictionMode === 'multi_candle') return t('shareCard.modeMulti');
return t('shareCard.modeSingle');
}
function PredictionCard({
payload,
cardRef,
@ -68,6 +79,7 @@ function PredictionCard({
{t(`shareCard.status.${payload.status}`)}
</Typography>
<Stack spacing={0.75} sx={{ mb: 2.5 }}>
<Row label={t('shareCard.mode')} value={predictionModeLabel(payload, t)} />
<Row label={t('shareCard.prediction')} value={directionLabel} />
<Row
label={t('shareCard.interval')}
@ -78,10 +90,6 @@ function PredictionCard({
label={t('shareCard.settledAt')}
value={settled.toLocaleString(undefined, { dateStyle: 'medium', timeStyle: 'short' })}
/>
{payload.isAuto ? <Row label={t('shareCard.mode')} value={t('shareCard.modeAuto')} /> : null}
{payload.predictionMode === 'multi_candle' ? (
<Row label={t('shareCard.mode')} value={t('shareCard.modeMulti')} />
) : null}
</Stack>
<VerifyFooter verifyUrl={payload.verifyUrl} />
</CardShell>

View File

@ -78,7 +78,12 @@ export function ShareResultVerifyPage() {
{t(`shareCard.status.${data.status}`)} · {data.gameName}
</Typography>
<Typography variant="body2" color="text.secondary">
{t(`shareCard.direction.${data.direction}`)} ·{' '}
{data.isAuto
? t('shareCard.modeAuto')
: data.predictionMode === 'multi_candle'
? t('shareCard.modeMulti')
: t('shareCard.modeSingle')}{' '}
· {t(`shareCard.direction.${data.direction}`)} ·{' '}
{t('shareCard.intervalValue', { minutes: data.intervalMinutes })} ·{' '}
{new Date(data.settledAt).toLocaleString()}
</Typography>

View File

@ -41,7 +41,7 @@ export type ShareCardPredictionPayload = {
export type ShareCardWalletPayload = {
kind: 'wallet';
transactionId: string;
operationType: 'deposit' | 'withdrawal' | 'transfer';
operationType: 'deposit' | 'withdrawal' | 'transfer' | 'bonus' | 'admin_adjustment';
status: string;
amountRaw: string;
amountDisplay: string;
@ -70,6 +70,7 @@ export type ShareCardVerifyPayload =
sequence: ('short' | 'long')[] | null;
multiLevel: number | null;
predictionMode: string;
isAuto?: boolean;
status: 'won' | 'lost' | 'refunded';
resultSignedDisplay: string;
stakeDisplay: number;
@ -81,7 +82,7 @@ export type ShareCardVerifyPayload =
| {
authentic: true;
kind: 'wallet';
operationType: 'deposit' | 'withdrawal' | 'transfer';
operationType: 'deposit' | 'withdrawal' | 'transfer' | 'bonus' | 'admin_adjustment';
status: string;
amountSignedDisplay: string;
amountDisplay: string;
@ -142,7 +143,13 @@ export function isWalletOpShareEligible(
): boolean {
const c = normalizeShareCardConfig(config ?? undefined);
if (!c?.enabled || !c.walletOpsEnabled) return false;
if (operationType === 'deposit') return c.allowDeposit;
if (
operationType === 'deposit' ||
operationType === 'bonus' ||
operationType === 'admin_adjustment'
) {
return c.allowDeposit;
}
if (operationType === 'withdrawal') return c.allowWithdrawal;
if (operationType === 'transfer') return c.allowTransfer;
return false;

View File

@ -59,8 +59,17 @@ function predictionShareMeta(tx: WalletTransaction): {
function walletOpShareMeta(
tx: WalletTransaction
): { transactionId: string; operationType: 'deposit' | 'withdrawal' | 'transfer' } | null {
if (tx.type === 'deposit' || tx.type === 'withdrawal' || tx.type === 'transfer') {
): {
transactionId: string;
operationType: 'deposit' | 'withdrawal' | 'transfer' | 'bonus' | 'admin_adjustment';
} | null {
if (
tx.type === 'deposit' ||
tx.type === 'withdrawal' ||
tx.type === 'transfer' ||
tx.type === 'bonus' ||
tx.type === 'admin_adjustment'
) {
return { transactionId: tx.id, operationType: tx.type };
}
return null;

View File

@ -241,7 +241,8 @@ export const en = {
settledAt: 'Settled',
mode: 'Mode',
modeAuto: 'Auto',
modeMulti: 'Multi-candle',
modeSingle: 'Single candle',
modeMulti: 'Multi candle',
verifyTitle: 'Scan to verify',
verifyHint: 'Authentic Prediqo result',
verifyPageTitle: 'Verified Prediqo share',
@ -258,6 +259,8 @@ export const en = {
deposit: 'Deposit',
withdrawal: 'Withdrawal',
transfer: 'Transfer',
bonus: 'Bonus credit',
admin_adjustment: 'Balance adjustment',
},
txStatusLabel: {
pending: 'Pending',
@ -1755,7 +1758,8 @@ export const en = {
allowRefunded: 'Refunded (neutral)',
walletOpsTitle: 'Wallet operations',
walletOpsEnabled: 'Enable wallet operation sharing',
walletOpsHelper: 'Allow users to share deposits, withdrawals, and transfers from Wallet Activity.',
walletOpsHelper:
'Allow users to share deposits (including bonus & balance adjustments), withdrawals, and transfers from Wallet Activity.',
walletOpsOffHint:
'Turn on “Enable wallet operation sharing” above — Deposit / Withdrawal / Transfer switches stay greyed out until that master switch is on.',
allowDeposit: 'Deposits',

View File

@ -248,7 +248,8 @@ export const fr = {
settledAt: 'Validé le',
mode: 'Mode',
modeAuto: 'Auto',
modeMulti: 'Multi-bougies',
modeSingle: 'Single candle',
modeMulti: 'Multi candle',
verifyTitle: 'Scanner pour vérifier',
verifyHint: 'Résultat Prediqo authentique',
verifyPageTitle: 'Partage Prediqo vérifié',
@ -265,6 +266,8 @@ export const fr = {
deposit: 'Dépôt',
withdrawal: 'Retrait',
transfer: 'Transfert',
bonus: 'Crédit bonus',
admin_adjustment: 'Ajustement de solde',
},
txStatusLabel: {
pending: 'En attente',
@ -1772,7 +1775,7 @@ export const fr = {
walletOpsTitle: 'Opérations Wallet',
walletOpsEnabled: 'Activer le partage des opérations Wallet',
walletOpsHelper:
'Autoriser les utilisateurs à partager dépôts, retraits et transferts depuis l’Activity du Wallet.',
'Autoriser les utilisateurs à partager dépôts (y compris bonus et ajustements), retraits et transferts depuis l’Activity du Wallet.',
walletOpsOffHint:
'Activez d’abord « Activer le partage des opérations Wallet » — les interrupteurs Dépôts / Retraits / Transferts restent grisés tant que ce switch maître est off.',
allowDeposit: 'Dépôts',