diff --git a/prediqo_web/src/features/treasury/TreasuryAdminPage.tsx b/prediqo_web/src/features/treasury/TreasuryAdminPage.tsx index 8d58e2d2..5cffc18f 100644 --- a/prediqo_web/src/features/treasury/TreasuryAdminPage.tsx +++ b/prediqo_web/src/features/treasury/TreasuryAdminPage.tsx @@ -18,11 +18,13 @@ import { DialogTitle, Divider, FormControl, + IconButton, InputAdornment, InputLabel, Link, MenuItem, Select, + Snackbar, Stack, Table, TableBody, @@ -30,6 +32,7 @@ import { TableHead, TableRow, TextField, + Tooltip, Typography, } from '@mui/material'; import AccountBalanceWalletRoundedIcon from '@mui/icons-material/AccountBalanceWalletRounded'; @@ -43,6 +46,7 @@ import { api } from '../../shared/services/api'; import { PageHeader, RefreshIconButton } from '../../shared/components/PageHeader'; import { PermissionGate } from '../../shared/auth/PermissionGate'; import { ScrollableTable } from '../../shared/components/ScrollableTable'; +import { copyTextToClipboard } from '../../shared/utils/clipboard'; import { rawToHuman } from '../wallet/utils/walletFormat'; type WalletType = { @@ -137,53 +141,87 @@ function networkLabel(network: string): string { return network; } -async function copyText(text: string): Promise { - try { - await navigator.clipboard.writeText(text); - } catch { - /* ignore */ - } -} - -function AddressLine({ +function AddressField({ label, address, network, + onCopied, }: { label: string; address: string | null | undefined; network: string; + onCopied: (ok: boolean) => void; }) { const { t } = useTranslation(); if (!address) { return ( - + {label}: — ); } const href = explorerUrl(network, address); + + const handleCopy = async () => { + const ok = await copyTextToClipboard(address); + onCopied(ok); + }; + return ( - - + + {label} - - {shortAddress(address)} - - - {href && ( - - {t('admin.treasury.viewOnExplorer')} - - )} + fullWidth + value={address} + InputProps={{ + readOnly: true, + sx: { + fontFamily: 'ui-monospace, monospace', + fontSize: 12, + '& input': { cursor: 'text' }, + }, + endAdornment: ( + + + void handleCopy()} + > + + + + + ), + }} + onFocus={(e) => e.target.select()} + onClick={(e) => (e.target as HTMLInputElement).select()} + /> + + + {href && ( + + )} + ); } @@ -200,6 +238,11 @@ export function TreasuryAdminPage() { const [confirmFunding, setConfirmFunding] = useState<{ id: string; txId: string } | null>(null); const [pendingMsg, setPendingMsg] = useState(null); const [fundingError, setFundingError] = useState(null); + const [copyToast, setCopyToast] = useState(null); + + const notifyCopy = (ok: boolean) => { + setCopyToast(ok ? t('admin.treasury.addressCopied') : t('admin.treasury.copyFailed')); + }; const overviewQ = useQuery({ queryKey: ['admin-treasury-overview'], @@ -434,10 +477,11 @@ export function TreasuryAdminPage() { {coldBal} - {asset.nativeSymbol && asset.coldWallet?.address && ( @@ -464,10 +508,11 @@ export function TreasuryAdminPage() { {hotBal} - {asset.nativeSymbol && asset.hotWallet?.address && ( )} {selectedFundingAsset?.coldWallet && selectedFundingAsset.hotWallet && ( - - {t('admin.treasury.fundingRoute', { - from: shortAddress(selectedFundingAsset.coldWallet.address), - to: shortAddress(selectedFundingAsset.hotWallet.address), - })} - + + + {t('admin.treasury.fundingAddresses')} + + + + )} @@ -867,6 +923,14 @@ export function TreasuryAdminPage() { + + setCopyToast(null)} + message={copyToast} + anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }} + /> ); } diff --git a/prediqo_web/src/shared/i18n/locales/en.ts b/prediqo_web/src/shared/i18n/locales/en.ts index adfaf132..acc19779 100644 --- a/prediqo_web/src/shared/i18n/locales/en.ts +++ b/prediqo_web/src/shared/i18n/locales/en.ts @@ -1541,6 +1541,8 @@ export const en = { hotWallet: 'Hot wallet', address: 'Address', copyAddress: 'Copy address', + addressCopied: 'Address copied', + copyFailed: 'Could not copy — select the address and copy manually (Ctrl+C)', gasBalance: 'Gas ({{symbol}}): {{balance}}', gasOk: 'enough for withdrawals', gasLow: 'below min {{min}} {{symbol}} — top up before withdrawals', @@ -1562,6 +1564,9 @@ export const en = { fundingSelectNetwork: 'Select a network', invalidAmount: 'Enter a valid USDT amount greater than zero', fundingRoute: 'Route: {{from}} → {{to}}', + fundingAddresses: 'Addresses for the on-chain transfer', + copyColdForTransfer: 'From (cold) — source of funds', + copyHotDestination: 'To (hot) — paste this on your exchange / wallet', notes: 'Notes', requestFunding: 'Request funding', amount: 'Amount', diff --git a/prediqo_web/src/shared/i18n/locales/fr.ts b/prediqo_web/src/shared/i18n/locales/fr.ts index 76a94f0f..a3cbfd95 100644 --- a/prediqo_web/src/shared/i18n/locales/fr.ts +++ b/prediqo_web/src/shared/i18n/locales/fr.ts @@ -1557,6 +1557,8 @@ export const fr = { hotWallet: 'Hot wallet', address: 'Adresse', copyAddress: 'Copier l’adresse', + addressCopied: 'Adresse copiée', + copyFailed: 'Copie impossible — sélectionnez l’adresse et copiez manuellement (Ctrl+C)', gasBalance: 'Gas ({{symbol}}) : {{balance}}', gasOk: 'suffisant pour les retraits', gasLow: 'sous le minimum {{min}} {{symbol}} — rechargez avant les retraits', @@ -1578,6 +1580,9 @@ export const fr = { fundingSelectNetwork: 'Sélectionnez un réseau', invalidAmount: 'Saisissez un montant USDT valide supérieur à zéro', fundingRoute: 'Parcours : {{from}} → {{to}}', + fundingAddresses: 'Adresses pour le transfert on-chain', + copyColdForTransfer: 'De (cold) — source des fonds', + copyHotDestination: 'Vers (hot) — à coller dans l’échangeur / wallet', notes: 'Notes', requestFunding: 'Demander le financement', amount: 'Montant', diff --git a/prediqo_web/src/shared/utils/clipboard.ts b/prediqo_web/src/shared/utils/clipboard.ts index abc4dde5..502af6cc 100644 --- a/prediqo_web/src/shared/utils/clipboard.ts +++ b/prediqo_web/src/shared/utils/clipboard.ts @@ -5,13 +5,14 @@ export async function copyTextToClipboard(text: string): Promise { const value = text ?? ''; if (!value) return false; - try { - if (navigator.clipboard?.writeText) { + // Clipboard API is unreliable / blocked outside secure contexts (plain HTTP). + if (typeof window !== 'undefined' && window.isSecureContext && navigator.clipboard?.writeText) { + try { await navigator.clipboard.writeText(value); return true; + } catch { + // Fall through to legacy path. } - } catch { - // Fall through to legacy path (common on HTTP origins). } try { @@ -24,6 +25,7 @@ export async function copyTextToClipboard(text: string): Promise { document.body.appendChild(ta); ta.focus(); ta.select(); + ta.setSelectionRange(0, value.length); const ok = document.execCommand('copy'); document.body.removeChild(ta); return ok;