diff --git a/backend/src/services/shareCardService.ts b/backend/src/services/shareCardService.ts index 67e4e3fb..41acfa07 100644 --- a/backend/src/services/shareCardService.ts +++ b/backend/src/services/shareCardService.ts @@ -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, diff --git a/backend/src/tests/shareCardService.test.ts b/backend/src/tests/shareCardService.test.ts index 8cf3346c..f7cdb743 100644 --- a/backend/src/tests/shareCardService.test.ts +++ b/backend/src/tests/shareCardService.test.ts @@ -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'; diff --git a/prediqo_mobile/lib/data/models/share_card_models.dart b/prediqo_mobile/lib/data/models/share_card_models.dart index 32fb4cd1..7de2e725 100644 --- a/prediqo_mobile/lib/data/models/share_card_models.dart +++ b/prediqo_mobile/lib/data/models/share_card_models.dart @@ -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; diff --git a/prediqo_mobile/lib/features/share_cards/presentation/share_result_widgets.dart b/prediqo_mobile/lib/features/share_cards/presentation/share_result_widgets.dart index fbdd6d24..4f6a8098 100644 --- a/prediqo_mobile/lib/features/share_cards/presentation/share_result_widgets.dart +++ b/prediqo_mobile/lib/features/share_cards/presentation/share_result_widgets.dart @@ -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) { diff --git a/prediqo_mobile/lib/features/wallet/presentation/wallet_overview_screen.dart b/prediqo_mobile/lib/features/wallet/presentation/wallet_overview_screen.dart index de498d3b..f0a1ddc9 100644 --- a/prediqo_mobile/lib/features/wallet/presentation/wallet_overview_screen.dart +++ b/prediqo_mobile/lib/features/wallet/presentation/wallet_overview_screen.dart @@ -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), diff --git a/prediqo_web/src/features/share-cards/ShareResultButton.tsx b/prediqo_web/src/features/share-cards/ShareResultButton.tsx index c547d65c..2d15a8c5 100644 --- a/prediqo_web/src/features/share-cards/ShareResultButton.tsx +++ b/prediqo_web/src/features/share-cards/ShareResultButton.tsx @@ -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'; }; diff --git a/prediqo_web/src/features/share-cards/ShareResultCard.tsx b/prediqo_web/src/features/share-cards/ShareResultCard.tsx index 98efd141..fcc24a90 100644 --- a/prediqo_web/src/features/share-cards/ShareResultCard.tsx +++ b/prediqo_web/src/features/share-cards/ShareResultCard.tsx @@ -21,6 +21,8 @@ const PREDICTION_COLOR: Record = { const OP_COLOR: Record = { deposit: '#3DDC97', + bonus: '#3DDC97', + admin_adjustment: '#7DDEA2', withdrawal: '#5EB2D6', transfer: '#C4A4FF', }; @@ -32,6 +34,15 @@ export function ShareResultCard({ payload, cardRef }: Props) { return ; } +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}`)} + - {payload.isAuto ? : null} - {payload.predictionMode === 'multi_candle' ? ( - - ) : null} diff --git a/prediqo_web/src/features/share-cards/ShareResultVerifyPage.tsx b/prediqo_web/src/features/share-cards/ShareResultVerifyPage.tsx index a2d39de4..610a3550 100644 --- a/prediqo_web/src/features/share-cards/ShareResultVerifyPage.tsx +++ b/prediqo_web/src/features/share-cards/ShareResultVerifyPage.tsx @@ -78,7 +78,12 @@ export function ShareResultVerifyPage() { {t(`shareCard.status.${data.status}`)} · {data.gameName} - {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()} diff --git a/prediqo_web/src/features/share-cards/types.ts b/prediqo_web/src/features/share-cards/types.ts index eee4b076..37e08dae 100644 --- a/prediqo_web/src/features/share-cards/types.ts +++ b/prediqo_web/src/features/share-cards/types.ts @@ -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; diff --git a/prediqo_web/src/features/wallet/components/TransactionList.tsx b/prediqo_web/src/features/wallet/components/TransactionList.tsx index 203914dd..3f1d6642 100644 --- a/prediqo_web/src/features/wallet/components/TransactionList.tsx +++ b/prediqo_web/src/features/wallet/components/TransactionList.tsx @@ -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; diff --git a/prediqo_web/src/shared/i18n/locales/en.ts b/prediqo_web/src/shared/i18n/locales/en.ts index 840521d7..f58ae3c1 100644 --- a/prediqo_web/src/shared/i18n/locales/en.ts +++ b/prediqo_web/src/shared/i18n/locales/en.ts @@ -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', diff --git a/prediqo_web/src/shared/i18n/locales/fr.ts b/prediqo_web/src/shared/i18n/locales/fr.ts index f4408244..e4f6e409 100644 --- a/prediqo_web/src/shared/i18n/locales/fr.ts +++ b/prediqo_web/src/shared/i18n/locales/fr.ts @@ -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',