After changing about commission dispatch and adding sharing card3
This commit is contained in:
parent
facf920825
commit
b11b79722b
@ -22,17 +22,17 @@ const STAKE_DECIMALS = 6;
|
||||
|
||||
export function mapSettingsForClient(row: ShareCardSettingsRow) {
|
||||
return {
|
||||
enabled: row.enabled,
|
||||
allowMainWallet: row.allow_main_wallet,
|
||||
allowBonusWallet: row.allow_bonus_wallet,
|
||||
allowTestWallet: row.allow_test_wallet,
|
||||
allowWon: row.allow_won,
|
||||
allowLost: row.allow_lost,
|
||||
allowRefunded: row.allow_refunded,
|
||||
walletOpsEnabled: row.wallet_ops_enabled,
|
||||
allowDeposit: row.allow_deposit,
|
||||
allowWithdrawal: row.allow_withdrawal,
|
||||
allowTransfer: row.allow_transfer,
|
||||
enabled: Boolean(row.enabled),
|
||||
allowMainWallet: Boolean(row.allow_main_wallet),
|
||||
allowBonusWallet: Boolean(row.allow_bonus_wallet),
|
||||
allowTestWallet: Boolean(row.allow_test_wallet),
|
||||
allowWon: Boolean(row.allow_won),
|
||||
allowLost: Boolean(row.allow_lost),
|
||||
allowRefunded: Boolean(row.allow_refunded),
|
||||
walletOpsEnabled: row.wallet_ops_enabled !== false,
|
||||
allowDeposit: row.allow_deposit !== false,
|
||||
allowWithdrawal: row.allow_withdrawal !== false,
|
||||
allowTransfer: row.allow_transfer !== false,
|
||||
updatedAt: row.updated_at.toISOString(),
|
||||
};
|
||||
}
|
||||
|
||||
@ -441,8 +441,24 @@ class _ShareResultIconButtonState extends State<ShareResultIconButton> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isWallet = widget.transactionId != null;
|
||||
// While loading wallet-op share, keep the icon visible so the action is discoverable.
|
||||
if (!_loaded && isWallet) {
|
||||
return IconButton(
|
||||
tooltip: context.strings.t('Share result', 'Partager le résultat'),
|
||||
icon: const Icon(Icons.ios_share_rounded, color: AppColors.primary),
|
||||
visualDensity: VisualDensity.compact,
|
||||
constraints: const BoxConstraints(minWidth: 36, minHeight: 36),
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: () => openShareResultDialog(
|
||||
context,
|
||||
betId: widget.betId,
|
||||
transactionId: widget.transactionId,
|
||||
),
|
||||
);
|
||||
}
|
||||
if (!_loaded || _config == null) return const SizedBox.shrink();
|
||||
final ok = widget.transactionId != null
|
||||
final ok = isWallet
|
||||
? _config!.isWalletOpEligible(widget.operationType ?? '')
|
||||
: _config!.isPredictionEligible(
|
||||
status: widget.status,
|
||||
@ -452,7 +468,10 @@ class _ShareResultIconButtonState extends State<ShareResultIconButton> {
|
||||
if (!ok) return const SizedBox.shrink();
|
||||
return IconButton(
|
||||
tooltip: context.strings.t('Share result', 'Partager le résultat'),
|
||||
icon: const Icon(Icons.ios_share_rounded),
|
||||
icon: const Icon(Icons.ios_share_rounded, color: AppColors.primary),
|
||||
visualDensity: VisualDensity.compact,
|
||||
constraints: const BoxConstraints(minWidth: 36, minHeight: 36),
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: () => openShareResultDialog(
|
||||
context,
|
||||
betId: widget.betId,
|
||||
|
||||
@ -889,10 +889,13 @@ 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';
|
||||
|
||||
return PredCard(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
width: 40,
|
||||
@ -912,9 +915,22 @@ class _StatusTxTile extends StatelessWidget {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
transactionLabel(tx, strings),
|
||||
style: const TextStyle(fontWeight: FontWeight.w700),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
transactionLabel(tx, strings),
|
||||
style: const TextStyle(fontWeight: FontWeight.w700),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
if (canShare)
|
||||
ShareResultIconButton(
|
||||
transactionId: tx.id,
|
||||
operationType: tx.type,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
@ -926,6 +942,7 @@ class _StatusTxTile extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
@ -954,11 +971,6 @@ class _StatusTxTile extends StatelessWidget {
|
||||
),
|
||||
],
|
||||
),
|
||||
if (tx.type == 'deposit' || tx.type == 'withdrawal' || tx.type == 'transfer')
|
||||
ShareResultIconButton(
|
||||
transactionId: tx.id,
|
||||
operationType: tx.type,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@ -43,8 +43,15 @@ export function ShareCardsAdminPage() {
|
||||
queryKey: ['admin-share-cards-settings'],
|
||||
queryFn: async () => {
|
||||
const res = await api.get<ShareCardSettings>('/api/v1/admin/share-cards/settings');
|
||||
setForm(res.data);
|
||||
return res.data;
|
||||
const data = {
|
||||
...res.data,
|
||||
walletOpsEnabled: res.data.walletOpsEnabled !== false,
|
||||
allowDeposit: res.data.allowDeposit !== false,
|
||||
allowWithdrawal: res.data.allowWithdrawal !== false,
|
||||
allowTransfer: res.data.allowTransfer !== false,
|
||||
};
|
||||
setForm(data);
|
||||
return data;
|
||||
},
|
||||
});
|
||||
|
||||
@ -192,7 +199,7 @@ export function ShareCardsAdminPage() {
|
||||
<FormControlLabel
|
||||
control={
|
||||
<Switch
|
||||
checked={form.walletOpsEnabled}
|
||||
checked={Boolean(form.walletOpsEnabled)}
|
||||
disabled={!form.enabled}
|
||||
onChange={(e) => setForm({ ...form, walletOpsEnabled: e.target.checked })}
|
||||
/>
|
||||
@ -202,11 +209,16 @@ export function ShareCardsAdminPage() {
|
||||
<Typography variant="caption" color="text.secondary" sx={{ display: 'block', mb: 1 }}>
|
||||
{t('admin.shareCards.walletOpsHelper')}
|
||||
</Typography>
|
||||
{!form.walletOpsEnabled && form.enabled ? (
|
||||
<Alert severity="info" sx={{ mb: 1.5 }}>
|
||||
{t('admin.shareCards.walletOpsOffHint')}
|
||||
</Alert>
|
||||
) : null}
|
||||
<Stack spacing={0.5} sx={{ mb: 2 }}>
|
||||
<FormControlLabel
|
||||
control={
|
||||
<Switch
|
||||
checked={form.allowDeposit}
|
||||
checked={Boolean(form.allowDeposit) && Boolean(form.walletOpsEnabled)}
|
||||
disabled={walletOpsDisabled}
|
||||
onChange={(e) => setForm({ ...form, allowDeposit: e.target.checked })}
|
||||
/>
|
||||
@ -216,7 +228,7 @@ export function ShareCardsAdminPage() {
|
||||
<FormControlLabel
|
||||
control={
|
||||
<Switch
|
||||
checked={form.allowWithdrawal}
|
||||
checked={Boolean(form.allowWithdrawal) && Boolean(form.walletOpsEnabled)}
|
||||
disabled={walletOpsDisabled}
|
||||
onChange={(e) => setForm({ ...form, allowWithdrawal: e.target.checked })}
|
||||
/>
|
||||
@ -226,7 +238,7 @@ export function ShareCardsAdminPage() {
|
||||
<FormControlLabel
|
||||
control={
|
||||
<Switch
|
||||
checked={form.allowTransfer}
|
||||
checked={Boolean(form.allowTransfer) && Boolean(form.walletOpsEnabled)}
|
||||
disabled={walletOpsDisabled}
|
||||
onChange={(e) => setForm({ ...form, allowTransfer: e.target.checked })}
|
||||
/>
|
||||
|
||||
@ -35,7 +35,9 @@ export function ShareResultButton(props: Props) {
|
||||
|
||||
const eligible =
|
||||
props.kind === 'wallet'
|
||||
? isWalletOpShareEligible(configQ.data, props.operationType)
|
||||
? !configQ.data && configQ.isPending
|
||||
? true
|
||||
: isWalletOpShareEligible(configQ.data, props.operationType)
|
||||
: isPredictionShareEligible(configQ.data, {
|
||||
status: props.status,
|
||||
stakeAccountKind: props.stakeAccountKind,
|
||||
|
||||
@ -1,9 +1,15 @@
|
||||
/**
|
||||
* Preview dialog: load share payload (prediction or wallet op), then share/download PNG.
|
||||
* Preview dialog: load share payload, then share (native / social / copy) or download PNG.
|
||||
* Desktop browsers rarely support Web Share with files — we must not silently download.
|
||||
*/
|
||||
import CloseRoundedIcon from '@mui/icons-material/CloseRounded';
|
||||
import ContentCopyRoundedIcon from '@mui/icons-material/ContentCopyRounded';
|
||||
import DownloadRoundedIcon from '@mui/icons-material/DownloadRounded';
|
||||
import FacebookRoundedIcon from '@mui/icons-material/FacebookRounded';
|
||||
import ShareRoundedIcon from '@mui/icons-material/ShareRounded';
|
||||
import TelegramIcon from '@mui/icons-material/Telegram';
|
||||
import WhatsAppIcon from '@mui/icons-material/WhatsApp';
|
||||
import XIcon from '@mui/icons-material/X';
|
||||
import {
|
||||
Alert,
|
||||
Box,
|
||||
@ -14,11 +20,15 @@ import {
|
||||
DialogContent,
|
||||
DialogTitle,
|
||||
IconButton,
|
||||
ListItemIcon,
|
||||
ListItemText,
|
||||
Menu,
|
||||
MenuItem,
|
||||
Stack,
|
||||
Typography,
|
||||
} from '@mui/material';
|
||||
import { toPng } from 'html-to-image';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { useEffect, useRef, useState, type MouseEvent } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import axios from 'axios';
|
||||
import { copyTextToClipboard } from '../../shared/utils/clipboard';
|
||||
@ -28,13 +38,16 @@ import type { ShareCardPayload } from './types';
|
||||
|
||||
type Props = {
|
||||
open: boolean;
|
||||
/** Prediction bet id */
|
||||
betId?: string | null;
|
||||
/** Wallet transaction id */
|
||||
transactionId?: string | null;
|
||||
onClose: () => void;
|
||||
};
|
||||
|
||||
type NavShare = Navigator & {
|
||||
share?: (data: ShareData) => Promise<void>;
|
||||
canShare?: (data: ShareData) => boolean;
|
||||
};
|
||||
|
||||
function errorMessage(e: unknown, fallback: string): string {
|
||||
if (axios.isAxiosError(e)) {
|
||||
const data = e.response?.data as { error?: string } | undefined;
|
||||
@ -44,32 +57,67 @@ function errorMessage(e: unknown, fallback: string): string {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
async function shareOrDownloadPng(blob: Blob, filename: string, verifyUrl: string): Promise<void> {
|
||||
const file = new File([blob], filename, { type: 'image/png' });
|
||||
const nav = navigator as Navigator & {
|
||||
share?: (data: ShareData) => Promise<void>;
|
||||
canShare?: (data: ShareData) => boolean;
|
||||
};
|
||||
if (nav.share && (!nav.canShare || nav.canShare({ files: [file] }))) {
|
||||
try {
|
||||
function canShareFiles(file: File): boolean {
|
||||
const nav = navigator as NavShare;
|
||||
if (typeof nav.share !== 'function') return false;
|
||||
if (typeof nav.canShare !== 'function') return false;
|
||||
try {
|
||||
return nav.canShare({ files: [file] });
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function canShareUrlOnly(): boolean {
|
||||
const nav = navigator as NavShare;
|
||||
return typeof nav.share === 'function';
|
||||
}
|
||||
|
||||
function shareCaption(verifyUrl: string): string {
|
||||
return `Prediqo — ${verifyUrl}`;
|
||||
}
|
||||
|
||||
async function tryNativeShare(opts: {
|
||||
blob: Blob;
|
||||
filename: string;
|
||||
verifyUrl: string;
|
||||
}): Promise<'shared' | 'cancelled' | 'unsupported'> {
|
||||
const nav = navigator as NavShare;
|
||||
if (typeof nav.share !== 'function') return 'unsupported';
|
||||
|
||||
const file = new File([opts.blob], opts.filename, { type: 'image/png' });
|
||||
const withFiles = canShareFiles(file);
|
||||
|
||||
try {
|
||||
if (withFiles) {
|
||||
await nav.share({
|
||||
files: [file],
|
||||
title: 'Prediqo',
|
||||
text: verifyUrl,
|
||||
url: verifyUrl,
|
||||
text: shareCaption(opts.verifyUrl),
|
||||
});
|
||||
return;
|
||||
} catch {
|
||||
/* fall through to download */
|
||||
return 'shared';
|
||||
}
|
||||
// Desktop / limited browsers: share link only (no silent download).
|
||||
await nav.share({
|
||||
title: 'Prediqo',
|
||||
text: shareCaption(opts.verifyUrl),
|
||||
url: opts.verifyUrl,
|
||||
});
|
||||
return 'shared';
|
||||
} catch (e) {
|
||||
// User dismissed the sheet — not a failure that should download.
|
||||
if (e instanceof DOMException && e.name === 'AbortError') return 'cancelled';
|
||||
return 'unsupported';
|
||||
}
|
||||
}
|
||||
|
||||
function downloadBlob(blob: Blob, filename: string): void {
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = filename;
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
await copyTextToClipboard(verifyUrl);
|
||||
}
|
||||
|
||||
export function ShareResultDialog({ open, betId, transactionId, onClose }: Props) {
|
||||
@ -80,12 +128,19 @@ export function ShareResultDialog({ open, betId, transactionId, onClose }: Props
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [hint, setHint] = useState<string | null>(null);
|
||||
const [menuAnchor, setMenuAnchor] = useState<null | HTMLElement>(null);
|
||||
const [cachedExport, setCachedExport] = useState<{
|
||||
blob: Blob;
|
||||
filename: string;
|
||||
} | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!open || (!betId && !transactionId)) {
|
||||
setPayload(null);
|
||||
setError(null);
|
||||
setHint(null);
|
||||
setCachedExport(null);
|
||||
setMenuAnchor(null);
|
||||
return;
|
||||
}
|
||||
let cancelled = false;
|
||||
@ -112,36 +167,36 @@ export function ShareResultDialog({ open, betId, transactionId, onClose }: Props
|
||||
};
|
||||
}, [open, betId, transactionId, t]);
|
||||
|
||||
const exportPng = async (share: boolean) => {
|
||||
if (!cardRef.current || !payload) return;
|
||||
const buildExport = async () => {
|
||||
if (!cardRef.current || !payload) return null;
|
||||
if (cachedExport) return cachedExport;
|
||||
const dataUrl = await toPng(cardRef.current, {
|
||||
cacheBust: true,
|
||||
pixelRatio: 2,
|
||||
backgroundColor: '#0B1220',
|
||||
});
|
||||
const res = await fetch(dataUrl);
|
||||
const blob = await res.blob();
|
||||
const id =
|
||||
payload.kind === 'wallet'
|
||||
? payload.transactionId.slice(0, 8)
|
||||
: payload.betId.slice(0, 8);
|
||||
const tag = payload.kind === 'wallet' ? payload.operationType : payload.status;
|
||||
const filename = `prediqo-${tag}-${id}.png`;
|
||||
const next = { blob, filename };
|
||||
setCachedExport(next);
|
||||
return next;
|
||||
};
|
||||
|
||||
const onDownload = async () => {
|
||||
if (!payload) return;
|
||||
setBusy(true);
|
||||
setHint(null);
|
||||
try {
|
||||
const dataUrl = await toPng(cardRef.current, {
|
||||
cacheBust: true,
|
||||
pixelRatio: 2,
|
||||
backgroundColor: '#0B1220',
|
||||
});
|
||||
const res = await fetch(dataUrl);
|
||||
const blob = await res.blob();
|
||||
const id =
|
||||
payload.kind === 'wallet'
|
||||
? payload.transactionId.slice(0, 8)
|
||||
: payload.betId.slice(0, 8);
|
||||
const tag = payload.kind === 'wallet' ? payload.operationType : payload.status;
|
||||
const filename = `prediqo-${tag}-${id}.png`;
|
||||
if (share) {
|
||||
await shareOrDownloadPng(blob, filename, payload.verifyUrl);
|
||||
setHint(t('shareCard.sharedOrDownloaded'));
|
||||
} else {
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = filename;
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
setHint(t('shareCard.downloaded'));
|
||||
}
|
||||
const exported = await buildExport();
|
||||
if (!exported) throw new Error('export');
|
||||
downloadBlob(exported.blob, exported.filename);
|
||||
setHint(t('shareCard.downloaded'));
|
||||
} catch {
|
||||
setHint(t('shareCard.exportFailed'));
|
||||
} finally {
|
||||
@ -149,6 +204,56 @@ export function ShareResultDialog({ open, betId, transactionId, onClose }: Props
|
||||
}
|
||||
};
|
||||
|
||||
const onShareClick = async (event: MouseEvent<HTMLElement>) => {
|
||||
if (!payload) return;
|
||||
setBusy(true);
|
||||
setHint(null);
|
||||
try {
|
||||
const exported = await buildExport();
|
||||
if (!exported) throw new Error('export');
|
||||
|
||||
// Prefer native sheet when available (mobile / some desktops).
|
||||
if (canShareUrlOnly()) {
|
||||
const result = await tryNativeShare({
|
||||
blob: exported.blob,
|
||||
filename: exported.filename,
|
||||
verifyUrl: payload.verifyUrl,
|
||||
});
|
||||
if (result === 'shared') {
|
||||
setHint(t('shareCard.sharedOrDownloaded'));
|
||||
return;
|
||||
}
|
||||
if (result === 'cancelled') return;
|
||||
}
|
||||
|
||||
// Fallback: explicit share menu (never silent download).
|
||||
setMenuAnchor(event.currentTarget);
|
||||
setHint(t('shareCard.nativeShareUnavailable'));
|
||||
} catch {
|
||||
setHint(t('shareCard.exportFailed'));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
const closeMenu = () => setMenuAnchor(null);
|
||||
|
||||
const copyLink = async () => {
|
||||
if (!payload) return;
|
||||
closeMenu();
|
||||
const ok = await copyTextToClipboard(payload.verifyUrl);
|
||||
setHint(ok ? t('shareCard.linkCopied') : t('shareCard.exportFailed'));
|
||||
};
|
||||
|
||||
const openSocial = (url: string) => {
|
||||
closeMenu();
|
||||
window.open(url, '_blank', 'noopener,noreferrer');
|
||||
};
|
||||
|
||||
const verifyUrl = payload?.verifyUrl ?? '';
|
||||
const encodedUrl = encodeURIComponent(verifyUrl);
|
||||
const encodedText = encodeURIComponent(shareCaption(verifyUrl));
|
||||
|
||||
return (
|
||||
<Dialog open={open} onClose={onClose} maxWidth="sm" fullWidth>
|
||||
<DialogTitle sx={{ pr: 6 }}>
|
||||
@ -182,12 +287,12 @@ export function ShareResultDialog({ open, betId, transactionId, onClose }: Props
|
||||
</Alert>
|
||||
)}
|
||||
</DialogContent>
|
||||
<DialogActions sx={{ px: 3, pb: 2 }}>
|
||||
<DialogActions sx={{ px: 3, pb: 2, flexWrap: 'wrap', gap: 1 }}>
|
||||
<Button onClick={onClose}>{t('shareCard.cancel')}</Button>
|
||||
<Button
|
||||
startIcon={<DownloadRoundedIcon />}
|
||||
disabled={!payload || busy}
|
||||
onClick={() => void exportPng(false)}
|
||||
onClick={() => void onDownload()}
|
||||
>
|
||||
{t('shareCard.download')}
|
||||
</Button>
|
||||
@ -195,10 +300,78 @@ export function ShareResultDialog({ open, betId, transactionId, onClose }: Props
|
||||
variant="contained"
|
||||
startIcon={<ShareRoundedIcon />}
|
||||
disabled={!payload || busy}
|
||||
onClick={() => void exportPng(true)}
|
||||
onClick={(e) => void onShareClick(e)}
|
||||
>
|
||||
{t('shareCard.share')}
|
||||
</Button>
|
||||
<Menu
|
||||
anchorEl={menuAnchor}
|
||||
open={Boolean(menuAnchor)}
|
||||
onClose={closeMenu}
|
||||
anchorOrigin={{ vertical: 'top', horizontal: 'right' }}
|
||||
transformOrigin={{ vertical: 'bottom', horizontal: 'right' }}
|
||||
>
|
||||
<MenuItem disabled>
|
||||
<ListItemText primary={t('shareCard.shareVia')} />
|
||||
</MenuItem>
|
||||
<MenuItem onClick={() => void copyLink()}>
|
||||
<ListItemIcon>
|
||||
<ContentCopyRoundedIcon fontSize="small" />
|
||||
</ListItemIcon>
|
||||
<ListItemText>{t('shareCard.copyLink')}</ListItemText>
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
onClick={() =>
|
||||
openSocial(`https://wa.me/?text=${encodedText}`)
|
||||
}
|
||||
>
|
||||
<ListItemIcon>
|
||||
<WhatsAppIcon fontSize="small" />
|
||||
</ListItemIcon>
|
||||
<ListItemText>{t('shareCard.shareWhatsApp')}</ListItemText>
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
onClick={() =>
|
||||
openSocial(`https://t.me/share/url?url=${encodedUrl}&text=${encodedText}`)
|
||||
}
|
||||
>
|
||||
<ListItemIcon>
|
||||
<TelegramIcon fontSize="small" />
|
||||
</ListItemIcon>
|
||||
<ListItemText>{t('shareCard.shareTelegram')}</ListItemText>
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
onClick={() =>
|
||||
openSocial(`https://twitter.com/intent/tweet?url=${encodedUrl}&text=${encodedText}`)
|
||||
}
|
||||
>
|
||||
<ListItemIcon>
|
||||
<XIcon fontSize="small" />
|
||||
</ListItemIcon>
|
||||
<ListItemText>{t('shareCard.shareX')}</ListItemText>
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
onClick={() =>
|
||||
openSocial(`https://www.facebook.com/sharer/sharer.php?u=${encodedUrl}`)
|
||||
}
|
||||
>
|
||||
<ListItemIcon>
|
||||
<FacebookRoundedIcon fontSize="small" />
|
||||
</ListItemIcon>
|
||||
<ListItemText>{t('shareCard.shareFacebook')}</ListItemText>
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
onClick={() => {
|
||||
closeMenu();
|
||||
void onDownload();
|
||||
}}
|
||||
>
|
||||
<ListItemIcon>
|
||||
<DownloadRoundedIcon fontSize="small" />
|
||||
</ListItemIcon>
|
||||
<ListItemText>{t('shareCard.download')}</ListItemText>
|
||||
</MenuItem>
|
||||
</Menu>
|
||||
</DialogActions>
|
||||
</Dialog>
|
||||
);
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { api } from '../../shared/services/api';
|
||||
import type { ShareCardConfig, ShareCardPayload } from './types';
|
||||
import { normalizeShareCardConfig, type ShareCardConfig, type ShareCardPayload } from './types';
|
||||
|
||||
export function useShareCardConfig(enabled = true) {
|
||||
return useQuery({
|
||||
@ -9,7 +9,7 @@ export function useShareCardConfig(enabled = true) {
|
||||
staleTime: 60_000,
|
||||
queryFn: async () => {
|
||||
const res = await api.get<ShareCardConfig>('/api/v1/share-cards/config');
|
||||
return res.data;
|
||||
return normalizeShareCardConfig(res.data) ?? res.data;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@ -97,31 +97,54 @@ export function isPredictionShareEligible(
|
||||
config: ShareCardConfig | null | undefined,
|
||||
input: { stakeAccountKind?: string | null; status?: string | null; requireStatus?: boolean }
|
||||
): boolean {
|
||||
if (!config?.enabled) return false;
|
||||
const c = normalizeShareCardConfig(config ?? undefined);
|
||||
if (!c?.enabled) return false;
|
||||
const kind = input.stakeAccountKind ?? 'main';
|
||||
if (kind === 'main' && !config.allowMainWallet) return false;
|
||||
if (kind === 'bonus' && !config.allowBonusWallet) return false;
|
||||
if (kind === 'test' && !config.allowTestWallet) return false;
|
||||
if (kind === 'main' && !c.allowMainWallet) return false;
|
||||
if (kind === 'bonus' && !c.allowBonusWallet) return false;
|
||||
if (kind === 'test' && !c.allowTestWallet) return false;
|
||||
|
||||
const status = input.status;
|
||||
if (!status) {
|
||||
return input.requireStatus === false;
|
||||
}
|
||||
if (status !== 'won' && status !== 'lost' && status !== 'refunded') return false;
|
||||
if (status === 'won' && !config.allowWon) return false;
|
||||
if (status === 'lost' && !config.allowLost) return false;
|
||||
if (status === 'refunded' && !config.allowRefunded) return false;
|
||||
if (status === 'won' && !c.allowWon) return false;
|
||||
if (status === 'lost' && !c.allowLost) return false;
|
||||
if (status === 'refunded' && !c.allowRefunded) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Normalize partial / legacy API payloads so wallet-op flags default to ON. */
|
||||
export function normalizeShareCardConfig(
|
||||
raw: Partial<ShareCardConfig> | null | undefined
|
||||
): ShareCardConfig | null {
|
||||
if (!raw) return null;
|
||||
return {
|
||||
enabled: raw.enabled === true,
|
||||
allowMainWallet: raw.allowMainWallet !== false,
|
||||
allowBonusWallet: raw.allowBonusWallet !== false,
|
||||
allowTestWallet: raw.allowTestWallet === true,
|
||||
allowWon: raw.allowWon !== false,
|
||||
allowLost: raw.allowLost !== false,
|
||||
allowRefunded: raw.allowRefunded !== false,
|
||||
walletOpsEnabled: raw.walletOpsEnabled !== false,
|
||||
allowDeposit: raw.allowDeposit !== false,
|
||||
allowWithdrawal: raw.allowWithdrawal !== false,
|
||||
allowTransfer: raw.allowTransfer !== false,
|
||||
updatedAt: raw.updatedAt,
|
||||
};
|
||||
}
|
||||
|
||||
export function isWalletOpShareEligible(
|
||||
config: ShareCardConfig | null | undefined,
|
||||
operationType: string
|
||||
): boolean {
|
||||
if (!config?.enabled || !config.walletOpsEnabled) return false;
|
||||
if (operationType === 'deposit') return config.allowDeposit;
|
||||
if (operationType === 'withdrawal') return config.allowWithdrawal;
|
||||
if (operationType === 'transfer') return config.allowTransfer;
|
||||
const c = normalizeShareCardConfig(config ?? undefined);
|
||||
if (!c?.enabled || !c.walletOpsEnabled) return false;
|
||||
if (operationType === 'deposit') return c.allowDeposit;
|
||||
if (operationType === 'withdrawal') return c.allowWithdrawal;
|
||||
if (operationType === 'transfer') return c.allowTransfer;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -131,7 +131,7 @@ export function TransactionList({
|
||||
}}
|
||||
>
|
||||
<ScrollableTable>
|
||||
<Table size="small" sx={{ minWidth: 560 }}>
|
||||
<Table size="small" sx={{ minWidth: 520 }}>
|
||||
<TableHead>
|
||||
<TableRow>
|
||||
<TableCell>{t('common.asset')}</TableCell>
|
||||
@ -139,7 +139,6 @@ export function TransactionList({
|
||||
<TableCell align="right">{t('common.amount')}</TableCell>
|
||||
<TableCell>{t('common.status')}</TableCell>
|
||||
<TableCell>{t('common.date')}</TableCell>
|
||||
<TableCell sx={{ width: 48 }} />
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
@ -152,6 +151,20 @@ export function TransactionList({
|
||||
const human = rawToHuman(tx.amount, decimals);
|
||||
const predictionShare = predictionShareMeta(tx);
|
||||
const walletShare = walletOpShareMeta(tx);
|
||||
const shareButton = predictionShare ? (
|
||||
<ShareResultButton
|
||||
betId={predictionShare.betId}
|
||||
status={predictionShare.status}
|
||||
stakeAccountKind={predictionShare.stakeAccountKind}
|
||||
requireStatus={Boolean(predictionShare.status)}
|
||||
/>
|
||||
) : walletShare ? (
|
||||
<ShareResultButton
|
||||
kind="wallet"
|
||||
transactionId={walletShare.transactionId}
|
||||
operationType={walletShare.operationType}
|
||||
/>
|
||||
) : null;
|
||||
|
||||
return (
|
||||
<TableRow key={tx.id} hover>
|
||||
@ -175,7 +188,11 @@ export function TransactionList({
|
||||
</Stack>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Typography variant="body2">{txLabel(tx)}</Typography>
|
||||
<Stack direction="row" spacing={0.5} sx={{ alignItems: 'center' }}>
|
||||
<Typography variant="body2">{txLabel(tx)}</Typography>
|
||||
{/* Beside the label so share stays visible without horizontal scroll */}
|
||||
{shareButton}
|
||||
</Stack>
|
||||
</TableCell>
|
||||
<TableCell align="right">
|
||||
<Typography
|
||||
@ -208,22 +225,6 @@ export function TransactionList({
|
||||
{dayjs(tx.created_at).format('YYYY-MM-DD HH:mm')}
|
||||
</Typography>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{predictionShare ? (
|
||||
<ShareResultButton
|
||||
betId={predictionShare.betId}
|
||||
status={predictionShare.status}
|
||||
stakeAccountKind={predictionShare.stakeAccountKind}
|
||||
requireStatus={Boolean(predictionShare.status)}
|
||||
/>
|
||||
) : walletShare ? (
|
||||
<ShareResultButton
|
||||
kind="wallet"
|
||||
transactionId={walletShare.transactionId}
|
||||
operationType={walletShare.operationType}
|
||||
/>
|
||||
) : null}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
})}
|
||||
|
||||
@ -215,14 +215,24 @@ export const en = {
|
||||
},
|
||||
},
|
||||
shareCard: {
|
||||
share: 'Share result',
|
||||
share: 'Share',
|
||||
shareVia: 'Share via…',
|
||||
copyLink: 'Copy verify link',
|
||||
linkCopied: 'Verify link copied to clipboard.',
|
||||
openNativeShare: 'Device share sheet',
|
||||
shareWhatsApp: 'WhatsApp',
|
||||
shareTelegram: 'Telegram',
|
||||
shareX: 'X (Twitter)',
|
||||
shareFacebook: 'Facebook',
|
||||
nativeShareUnavailable:
|
||||
'Your browser cannot share images directly. Copy the verify link or download the card, then post it on social media.',
|
||||
cancel: 'Cancel',
|
||||
download: 'Download',
|
||||
previewTitle: 'Share card preview',
|
||||
previewHint: 'Review your card before sharing. Sharing is only available after this preview.',
|
||||
loadError: 'Unable to load this result for sharing.',
|
||||
downloaded: 'Card downloaded.',
|
||||
sharedOrDownloaded: 'Shared (or downloaded). Verify link copied when possible.',
|
||||
sharedOrDownloaded: 'Shared successfully.',
|
||||
exportFailed: 'Could not export the card image.',
|
||||
prediction: 'Prediction',
|
||||
interval: 'Interval',
|
||||
@ -1746,6 +1756,8 @@ export const en = {
|
||||
walletOpsTitle: 'Wallet operations',
|
||||
walletOpsEnabled: 'Enable wallet operation sharing',
|
||||
walletOpsHelper: 'Allow users to share deposits, 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',
|
||||
allowWithdrawal: 'Withdrawals',
|
||||
allowTransfer: 'Transfers',
|
||||
|
||||
@ -221,7 +221,17 @@ export const fr = {
|
||||
},
|
||||
},
|
||||
shareCard: {
|
||||
share: 'Partager le résultat',
|
||||
share: 'Partager',
|
||||
shareVia: 'Partager via…',
|
||||
copyLink: 'Copier le lien de vérification',
|
||||
linkCopied: 'Lien de vérification copié.',
|
||||
openNativeShare: 'Partage de l’appareil',
|
||||
shareWhatsApp: 'WhatsApp',
|
||||
shareTelegram: 'Telegram',
|
||||
shareX: 'X (Twitter)',
|
||||
shareFacebook: 'Facebook',
|
||||
nativeShareUnavailable:
|
||||
'Votre navigateur ne peut pas partager d’image directement. Copiez le lien de vérification ou téléchargez la carte, puis publiez-la sur les réseaux.',
|
||||
cancel: 'Annuler',
|
||||
download: 'Télécharger',
|
||||
previewTitle: 'Aperçu de la carte',
|
||||
@ -229,7 +239,7 @@ export const fr = {
|
||||
'Vérifiez votre carte avant de partager. Le partage n’est possible qu’après cet aperçu.',
|
||||
loadError: 'Impossible de charger ce résultat pour le partage.',
|
||||
downloaded: 'Carte téléchargée.',
|
||||
sharedOrDownloaded: 'Partagé (ou téléchargé). Lien de vérification copié si possible.',
|
||||
sharedOrDownloaded: 'Partage réussi.',
|
||||
exportFailed: 'Impossible d’exporter l’image de la carte.',
|
||||
prediction: 'Prédiction',
|
||||
interval: 'Intervalle',
|
||||
@ -1763,6 +1773,8 @@ export const fr = {
|
||||
walletOpsEnabled: 'Activer le partage des opérations Wallet',
|
||||
walletOpsHelper:
|
||||
'Autoriser les utilisateurs à partager dépôts, 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',
|
||||
allowWithdrawal: 'Retraits',
|
||||
allowTransfer: 'Transferts',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user