After starting the cold wallet to hot wallet1
This commit is contained in:
parent
71c852a748
commit
cb90074de1
@ -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<void> {
|
||||
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 (
|
||||
<Typography variant="body2" sx={{ opacity: 0.55 }}>
|
||||
<Typography variant="body2" sx={{ opacity: 0.55, mt: 0.5 }}>
|
||||
{label}: —
|
||||
</Typography>
|
||||
);
|
||||
}
|
||||
const href = explorerUrl(network, address);
|
||||
|
||||
const handleCopy = async () => {
|
||||
const ok = await copyTextToClipboard(address);
|
||||
onCopied(ok);
|
||||
};
|
||||
|
||||
return (
|
||||
<Stack direction="row" spacing={0.75} alignItems="center" useFlexGap sx={{ flexWrap: 'wrap' }}>
|
||||
<Typography variant="body2" sx={{ opacity: 0.7 }}>
|
||||
<Stack spacing={0.75} sx={{ mt: 0.5, minWidth: 0 }}>
|
||||
<Typography variant="caption" sx={{ opacity: 0.7 }}>
|
||||
{label}
|
||||
</Typography>
|
||||
<Typography variant="body2" sx={{ fontFamily: 'ui-monospace, monospace', fontWeight: 600 }}>
|
||||
{shortAddress(address)}
|
||||
</Typography>
|
||||
<Button
|
||||
<TextField
|
||||
size="small"
|
||||
aria-label={t('admin.treasury.copyAddress')}
|
||||
onClick={() => void copyText(address)}
|
||||
sx={{ minWidth: 0, px: 0.5 }}
|
||||
>
|
||||
<ContentCopyRoundedIcon sx={{ fontSize: 16 }} />
|
||||
</Button>
|
||||
{href && (
|
||||
<Link href={href} target="_blank" rel="noopener noreferrer" variant="body2" underline="hover">
|
||||
{t('admin.treasury.viewOnExplorer')}
|
||||
</Link>
|
||||
)}
|
||||
fullWidth
|
||||
value={address}
|
||||
InputProps={{
|
||||
readOnly: true,
|
||||
sx: {
|
||||
fontFamily: 'ui-monospace, monospace',
|
||||
fontSize: 12,
|
||||
'& input': { cursor: 'text' },
|
||||
},
|
||||
endAdornment: (
|
||||
<InputAdornment position="end">
|
||||
<Tooltip title={t('admin.treasury.copyAddress')}>
|
||||
<IconButton
|
||||
edge="end"
|
||||
size="small"
|
||||
aria-label={t('admin.treasury.copyAddress')}
|
||||
onClick={() => void handleCopy()}
|
||||
>
|
||||
<ContentCopyRoundedIcon fontSize="small" />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
</InputAdornment>
|
||||
),
|
||||
}}
|
||||
onFocus={(e) => e.target.select()}
|
||||
onClick={(e) => (e.target as HTMLInputElement).select()}
|
||||
/>
|
||||
<Stack direction="row" spacing={1} useFlexGap sx={{ flexWrap: 'wrap' }}>
|
||||
<Button
|
||||
size="small"
|
||||
variant="outlined"
|
||||
onClick={() => void handleCopy()}
|
||||
startIcon={<ContentCopyRoundedIcon />}
|
||||
>
|
||||
{t('admin.treasury.copyAddress')}
|
||||
</Button>
|
||||
{href && (
|
||||
<Button
|
||||
size="small"
|
||||
href={href}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
sx={{ textTransform: 'none' }}
|
||||
>
|
||||
{t('admin.treasury.viewOnExplorer')}
|
||||
</Button>
|
||||
)}
|
||||
</Stack>
|
||||
</Stack>
|
||||
);
|
||||
}
|
||||
@ -200,6 +238,11 @@ export function TreasuryAdminPage() {
|
||||
const [confirmFunding, setConfirmFunding] = useState<{ id: string; txId: string } | null>(null);
|
||||
const [pendingMsg, setPendingMsg] = useState<string | null>(null);
|
||||
const [fundingError, setFundingError] = useState<string | null>(null);
|
||||
const [copyToast, setCopyToast] = useState<string | null>(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() {
|
||||
<Typography variant="h5" sx={{ fontWeight: 800, my: 0.5 }}>
|
||||
{coldBal}
|
||||
</Typography>
|
||||
<AddressLine
|
||||
<AddressField
|
||||
label={t('admin.treasury.address')}
|
||||
address={asset.coldWallet?.address}
|
||||
network={wt.network}
|
||||
onCopied={notifyCopy}
|
||||
/>
|
||||
{asset.nativeSymbol && asset.coldWallet?.address && (
|
||||
<Typography variant="caption" sx={{ display: 'block', mt: 0.75, opacity: 0.65 }}>
|
||||
@ -464,10 +508,11 @@ export function TreasuryAdminPage() {
|
||||
<Typography variant="h5" sx={{ fontWeight: 800, my: 0.5 }}>
|
||||
{hotBal}
|
||||
</Typography>
|
||||
<AddressLine
|
||||
<AddressField
|
||||
label={t('admin.treasury.address')}
|
||||
address={asset.hotWallet?.address}
|
||||
network={wt.network}
|
||||
onCopied={notifyCopy}
|
||||
/>
|
||||
{asset.nativeSymbol && asset.hotWallet?.address && (
|
||||
<Stack
|
||||
@ -637,12 +682,23 @@ export function TreasuryAdminPage() {
|
||||
</Alert>
|
||||
)}
|
||||
{selectedFundingAsset?.coldWallet && selectedFundingAsset.hotWallet && (
|
||||
<Typography variant="caption" sx={{ fontFamily: 'ui-monospace, monospace', opacity: 0.7 }}>
|
||||
{t('admin.treasury.fundingRoute', {
|
||||
from: shortAddress(selectedFundingAsset.coldWallet.address),
|
||||
to: shortAddress(selectedFundingAsset.hotWallet.address),
|
||||
})}
|
||||
</Typography>
|
||||
<Stack spacing={1.25} sx={{ mt: 0.5 }}>
|
||||
<Typography variant="subtitle2" sx={{ fontWeight: 700 }}>
|
||||
{t('admin.treasury.fundingAddresses')}
|
||||
</Typography>
|
||||
<AddressField
|
||||
label={t('admin.treasury.copyColdForTransfer')}
|
||||
address={selectedFundingAsset.coldWallet.address}
|
||||
network={selectedFundingAsset.walletType.network}
|
||||
onCopied={notifyCopy}
|
||||
/>
|
||||
<AddressField
|
||||
label={t('admin.treasury.copyHotDestination')}
|
||||
address={selectedFundingAsset.hotWallet.address}
|
||||
network={selectedFundingAsset.walletType.network}
|
||||
onCopied={notifyCopy}
|
||||
/>
|
||||
</Stack>
|
||||
)}
|
||||
</Stack>
|
||||
|
||||
@ -867,6 +923,14 @@ export function TreasuryAdminPage() {
|
||||
</DialogActions>
|
||||
</Dialog>
|
||||
</PermissionGate>
|
||||
|
||||
<Snackbar
|
||||
open={!!copyToast}
|
||||
autoHideDuration={2500}
|
||||
onClose={() => setCopyToast(null)}
|
||||
message={copyToast}
|
||||
anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
@ -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',
|
||||
|
||||
@ -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',
|
||||
|
||||
@ -5,13 +5,14 @@ export async function copyTextToClipboard(text: string): Promise<boolean> {
|
||||
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<boolean> {
|
||||
document.body.appendChild(ta);
|
||||
ta.focus();
|
||||
ta.select();
|
||||
ta.setSelectionRange(0, value.length);
|
||||
const ok = document.execCommand('copy');
|
||||
document.body.removeChild(ta);
|
||||
return ok;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user