After adding the BSC option3
This commit is contained in:
parent
342e84b6ef
commit
90842c0b74
@ -56,6 +56,10 @@ export async function getDepositAddress(req: AuthRequest, res: Response): Promis
|
||||
res.status(503).json({ error: 'Deposit addresses are not available. Server configuration required: set a valid BIP39 mnemonic in PLATFORM_MNEMONIC.' });
|
||||
return;
|
||||
}
|
||||
if (/Deposits are disabled/i.test(msg)) {
|
||||
res.status(403).json({ error: msg, code: 'DEPOSIT_NETWORK_DISABLED' });
|
||||
return;
|
||||
}
|
||||
res.status(400).json({ error: msg });
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ class _DepositAssetSelectScreenState extends State<DepositAssetSelectScreen> {
|
||||
if (state.isLoading && state.walletTypes.isEmpty) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
final types = state.walletTypes.where((t) => t.depositEnabled).toList();
|
||||
final types = state.walletTypes.where((t) => t.depositEnabled == true).toList();
|
||||
if (types.isEmpty) {
|
||||
return Center(
|
||||
child: Padding(
|
||||
|
||||
@ -180,7 +180,7 @@ class _WithdrawScreenState extends State<WithdrawScreen> {
|
||||
if (!state.isLoaded && state.balances.isEmpty) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
final types = state.walletTypes.where((t) => t.withdrawEnabled).toList();
|
||||
final types = state.walletTypes.where((t) => t.withdrawEnabled == true).toList();
|
||||
final balances = state.balances;
|
||||
if (types.isEmpty) {
|
||||
return const Center(child: Text('No withdrawal networks enabled'));
|
||||
|
||||
@ -20,7 +20,7 @@ import {
|
||||
import ExpandMoreRoundedIcon from '@mui/icons-material/ExpandMoreRounded';
|
||||
import SaveRoundedIcon from '@mui/icons-material/SaveRounded';
|
||||
import RestartAltRoundedIcon from '@mui/icons-material/RestartAltRounded';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import { useMemo, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { api } from '../../shared/services/api';
|
||||
@ -32,6 +32,7 @@ import { PermissionGate } from '../../shared/auth/PermissionGate';
|
||||
export function SettingsPage() {
|
||||
const { t } = useTranslation();
|
||||
const { can } = useAuth();
|
||||
const qc = useQueryClient();
|
||||
const canEditSettings = can('admin.settings.edit');
|
||||
type Settings = {
|
||||
password_min_length: number;
|
||||
@ -100,6 +101,12 @@ export function SettingsPage() {
|
||||
try {
|
||||
await api.patch('/api/v1/admin/settings', effective);
|
||||
await q.refetch();
|
||||
await Promise.all([
|
||||
qc.invalidateQueries({ queryKey: ['wallet-balances'] }),
|
||||
qc.invalidateQueries({ queryKey: ['wallet-deposit-address'] }),
|
||||
qc.invalidateQueries({ queryKey: ['health'] }),
|
||||
qc.invalidateQueries({ queryKey: ['health-withdrawal-policy'] }),
|
||||
]);
|
||||
setForm(null);
|
||||
setSaved(true);
|
||||
} catch (e: any) {
|
||||
@ -298,6 +305,9 @@ export function SettingsPage() {
|
||||
<Typography variant="body2" sx={{ opacity: 0.7 }}>
|
||||
{t('admin.settings.sections.networks.subtitle')}
|
||||
</Typography>
|
||||
<Typography variant="caption" sx={{ opacity: 0.65, display: 'block', mt: 0.5 }}>
|
||||
{t('admin.settings.sections.networks.applyHint')}
|
||||
</Typography>
|
||||
</Box>
|
||||
</AccordionSummary>
|
||||
<AccordionDetails>
|
||||
|
||||
@ -65,6 +65,14 @@ export function WalletPage() {
|
||||
() => balances.filter((b) => isSupportedUsdtCode(b.walletType.code)),
|
||||
[balances]
|
||||
);
|
||||
const depositableBalances = useMemo(
|
||||
() => usdtBalances.filter((b) => b.walletType.depositEnabled === true),
|
||||
[usdtBalances]
|
||||
);
|
||||
const withdrawableBalances = useMemo(
|
||||
() => usdtBalances.filter((b) => b.walletType.withdrawEnabled === true),
|
||||
[usdtBalances]
|
||||
);
|
||||
const transactions = txQ.data?.items ?? [];
|
||||
const txTotal = txQ.data?.total ?? 0;
|
||||
const primaryBalance =
|
||||
@ -78,6 +86,7 @@ export function WalletPage() {
|
||||
locked: rawToHuman(b.locked, b.walletType.decimals),
|
||||
hasLocked: BigInt(b.locked || '0') > 0n,
|
||||
network: networkLabel(b.walletType.code),
|
||||
depositEnabled: b.walletType.depositEnabled === true,
|
||||
}));
|
||||
return { lines };
|
||||
}, [usdtBalances]);
|
||||
@ -88,6 +97,28 @@ export function WalletPage() {
|
||||
};
|
||||
|
||||
const openDialog = (kind: DialogKind, asset?: string) => {
|
||||
if (kind === 'receive') {
|
||||
if (depositableBalances.length === 0) {
|
||||
setToast(t('wallet.receiveDialog.noNetworks'));
|
||||
return;
|
||||
}
|
||||
const ok =
|
||||
!asset || depositableBalances.some((b) => b.walletType.code === asset);
|
||||
setDialogAsset(ok ? asset ?? null : depositableBalances[0]?.walletType.code ?? null);
|
||||
setDialog('receive');
|
||||
return;
|
||||
}
|
||||
if (kind === 'withdraw') {
|
||||
if (withdrawableBalances.length === 0) {
|
||||
setToast(t('wallet.withdrawDialog.noNetworks'));
|
||||
return;
|
||||
}
|
||||
const ok =
|
||||
!asset || withdrawableBalances.some((b) => b.walletType.code === asset);
|
||||
setDialogAsset(ok ? asset ?? null : withdrawableBalances[0]?.walletType.code ?? null);
|
||||
setDialog('withdraw');
|
||||
return;
|
||||
}
|
||||
setDialogAsset(asset ?? null);
|
||||
setDialog(kind);
|
||||
};
|
||||
@ -157,6 +188,7 @@ export function WalletPage() {
|
||||
variant="contained"
|
||||
startIcon={<CallReceivedRoundedIcon />}
|
||||
onClick={() => openDialog('receive')}
|
||||
disabled={depositableBalances.length === 0}
|
||||
sx={{ flex: 1 }}
|
||||
>
|
||||
{t('wallet.receiveUsdt')}
|
||||
@ -174,6 +206,7 @@ export function WalletPage() {
|
||||
color="warning"
|
||||
startIcon={<SouthWestRoundedIcon />}
|
||||
onClick={() => openDialog('withdraw')}
|
||||
disabled={withdrawableBalances.length === 0 || !(healthQ.data?.withdrawalsEnabled ?? false)}
|
||||
sx={{ flex: 1 }}
|
||||
>
|
||||
{t('wallet.withdraw')}
|
||||
|
||||
@ -28,9 +28,11 @@ export function MainAssetCard({ balance, onReceive, onSend }: MainAssetCardProps
|
||||
const code = balance.walletType.code;
|
||||
const [c1, c2] = coinColors(code);
|
||||
const hasLocked = BigInt(balance.locked || '0') > 0n;
|
||||
const depositEnabled = balance.walletType.depositEnabled === true;
|
||||
const withdrawEnabled = balance.walletType.withdrawEnabled === true;
|
||||
|
||||
return (
|
||||
<Card sx={{ borderRadius: 2, height: '100%' }}>
|
||||
<Card sx={{ borderRadius: 2, height: '100%', opacity: depositEnabled || withdrawEnabled ? 1 : 0.92 }}>
|
||||
<CardContent sx={{ p: 2.5 }}>
|
||||
<Stack direction="row" spacing={1.5} sx={{ alignItems: 'center' }}>
|
||||
<Box
|
||||
@ -53,18 +55,44 @@ export function MainAssetCard({ balance, onReceive, onSend }: MainAssetCardProps
|
||||
<Typography variant="body2" sx={{ opacity: 0.65 }}>
|
||||
{networkLabel(code)}
|
||||
</Typography>
|
||||
{balance.walletType.predictionEnabled ? (
|
||||
<Stack direction="row" spacing={0.75} sx={{ mt: 0.75, flexWrap: 'wrap', gap: 0.75 }}>
|
||||
<Chip
|
||||
size="small"
|
||||
color="primary"
|
||||
label={t('wallet.mainCard.badge')}
|
||||
sx={{ mt: 0.75, fontWeight: 700 }}
|
||||
color={depositEnabled ? 'success' : 'default'}
|
||||
variant={depositEnabled ? 'filled' : 'outlined'}
|
||||
label={
|
||||
depositEnabled
|
||||
? t('wallet.mainCard.depositsOn')
|
||||
: t('wallet.mainCard.depositsOff')
|
||||
}
|
||||
sx={{ fontWeight: 700 }}
|
||||
/>
|
||||
) : null}
|
||||
<Chip
|
||||
size="small"
|
||||
color={withdrawEnabled ? 'success' : 'default'}
|
||||
variant={withdrawEnabled ? 'filled' : 'outlined'}
|
||||
label={
|
||||
withdrawEnabled
|
||||
? t('wallet.mainCard.withdrawalsOn')
|
||||
: t('wallet.mainCard.withdrawalsOff')
|
||||
}
|
||||
sx={{ fontWeight: 700 }}
|
||||
/>
|
||||
{balance.walletType.predictionEnabled ? (
|
||||
<Chip
|
||||
size="small"
|
||||
color="primary"
|
||||
label={t('wallet.mainCard.predictionBadge')}
|
||||
sx={{ fontWeight: 700 }}
|
||||
/>
|
||||
) : null}
|
||||
</Stack>
|
||||
</Box>
|
||||
<IconButton size="small" aria-label={t('wallet.mainCard.receiveAria')} onClick={onReceive}>
|
||||
<QrCode2RoundedIcon fontSize="small" />
|
||||
</IconButton>
|
||||
{depositEnabled ? (
|
||||
<IconButton size="small" aria-label={t('wallet.mainCard.receiveAria')} onClick={onReceive}>
|
||||
<QrCode2RoundedIcon fontSize="small" />
|
||||
</IconButton>
|
||||
) : null}
|
||||
</Stack>
|
||||
|
||||
<Typography variant="caption" sx={{ opacity: 0.6, textTransform: 'uppercase', mt: 2, display: 'block' }}>
|
||||
@ -81,8 +109,14 @@ export function MainAssetCard({ balance, onReceive, onSend }: MainAssetCardProps
|
||||
</Typography>
|
||||
)}
|
||||
|
||||
{!depositEnabled && (
|
||||
<Typography variant="body2" color="warning.main" sx={{ mt: 1 }}>
|
||||
{t('wallet.mainCard.depositsDisabledHint')}
|
||||
</Typography>
|
||||
)}
|
||||
|
||||
<Stack direction="row" spacing={1} sx={{ mt: 2 }}>
|
||||
<Button size="small" variant="contained" onClick={onReceive}>
|
||||
<Button size="small" variant="contained" onClick={onReceive} disabled={!depositEnabled}>
|
||||
{t('wallet.mainCard.receive')}
|
||||
</Button>
|
||||
<Button size="small" variant="outlined" onClick={onSend}>
|
||||
|
||||
@ -41,12 +41,17 @@ export function ReceiveDialog({ open, onClose, onCopied, initialAsset }: Receive
|
||||
return rows.filter(
|
||||
(b) =>
|
||||
(b.walletType.code === USDT_TRC20_CODE || b.walletType.code === USDT_BEP20_CODE) &&
|
||||
b.walletType.depositEnabled !== false
|
||||
b.walletType.depositEnabled === true
|
||||
);
|
||||
}, [balancesQ.data]);
|
||||
|
||||
const [asset, setAsset] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
void balancesQ.refetch();
|
||||
}, [open]); // eslint-disable-line react-hooks/exhaustive-deps -- refetch when dialog opens
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
const preferred =
|
||||
|
||||
@ -59,7 +59,7 @@ export function WithdrawDialog({
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
|
||||
const withdrawBalances = useMemo(
|
||||
() => balances.filter((b) => b.walletType.withdrawEnabled !== false),
|
||||
() => balances.filter((b) => b.walletType.withdrawEnabled === true),
|
||||
[balances]
|
||||
);
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@ export type PaginatedTransactions = {
|
||||
offset: number;
|
||||
};
|
||||
|
||||
/** Fetches the authenticated user's ledger balances. */
|
||||
/** Fetches the authenticated user's ledger balances (includes deposit/withdraw flags). */
|
||||
export function useBalances() {
|
||||
return useQuery({
|
||||
queryKey: ['wallet-balances'],
|
||||
@ -21,6 +21,9 @@ export function useBalances() {
|
||||
const res = await api.get<BalanceEntry[]>('/api/v1/balances');
|
||||
return res.data;
|
||||
},
|
||||
staleTime: 0,
|
||||
refetchOnMount: 'always',
|
||||
refetchOnWindowFocus: true,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -373,6 +373,13 @@ export const en = {
|
||||
mainCard: {
|
||||
title: 'Main wallet',
|
||||
badge: 'Deposits & withdrawals',
|
||||
depositsOn: 'Deposits on',
|
||||
depositsOff: 'Deposits off',
|
||||
withdrawalsOn: 'Withdrawals on',
|
||||
withdrawalsOff: 'Withdrawals off',
|
||||
predictionBadge: 'Candle Predict',
|
||||
depositsDisabledHint:
|
||||
'Deposits are disabled for this network by the platform. Do not send funds to an old address for this network.',
|
||||
availableBalance: 'Available balance',
|
||||
locked: 'Locked:',
|
||||
receive: 'Receive',
|
||||
@ -1713,6 +1720,8 @@ export const en = {
|
||||
networks: {
|
||||
title: 'USDT networks',
|
||||
subtitle: 'Enable or disable deposits and withdrawals per chain (TRC20 / BEP20).',
|
||||
applyHint:
|
||||
'After save, Wallet only offers deposit/withdraw for networks that are enabled. Disabled networks stop accepting new deposits immediately (scanner + address API).',
|
||||
trc20: 'TRON — USDT (TRC20)',
|
||||
bep20: 'BSC — USDT (BEP20)',
|
||||
depositEnabled: 'Deposits enabled',
|
||||
|
||||
@ -382,6 +382,13 @@ export const fr = {
|
||||
mainCard: {
|
||||
title: 'Portefeuille principal',
|
||||
badge: 'Dépôts et retraits',
|
||||
depositsOn: 'Dépôts activés',
|
||||
depositsOff: 'Dépôts désactivés',
|
||||
withdrawalsOn: 'Retraits activés',
|
||||
withdrawalsOff: 'Retraits désactivés',
|
||||
predictionBadge: 'Candle Predict',
|
||||
depositsDisabledHint:
|
||||
'Les dépôts sont désactivés pour ce réseau. N’envoyez pas de fonds vers une ancienne adresse de ce réseau.',
|
||||
availableBalance: 'Solde disponible',
|
||||
locked: 'Bloqué :',
|
||||
receive: 'Recevoir',
|
||||
@ -1731,6 +1738,8 @@ export const fr = {
|
||||
networks: {
|
||||
title: 'Réseaux USDT',
|
||||
subtitle: 'Activer ou désactiver dépôts et retraits par chaîne (TRC20 / BEP20).',
|
||||
applyHint:
|
||||
'Après enregistrement, le Wallet ne propose dépôt/retrait que pour les réseaux activés. Un réseau désactivé refuse immédiatement les nouveaux dépôts (scanner + API adresse).',
|
||||
trc20: 'TRON — USDT (TRC20)',
|
||||
bep20: 'BSC — USDT (BEP20)',
|
||||
depositEnabled: 'Dépôts activés',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user