diff --git a/backend/src/controllers/walletController.ts b/backend/src/controllers/walletController.ts index d03a13e8..76943314 100644 --- a/backend/src/controllers/walletController.ts +++ b/backend/src/controllers/walletController.ts @@ -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 }); } } diff --git a/prediqo_mobile/lib/features/wallet/presentation/deposit_asset_select_screen.dart b/prediqo_mobile/lib/features/wallet/presentation/deposit_asset_select_screen.dart index c6c0a7eb..5f455ab5 100644 --- a/prediqo_mobile/lib/features/wallet/presentation/deposit_asset_select_screen.dart +++ b/prediqo_mobile/lib/features/wallet/presentation/deposit_asset_select_screen.dart @@ -39,7 +39,7 @@ class _DepositAssetSelectScreenState extends State { 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( diff --git a/prediqo_mobile/lib/features/wallet/presentation/withdraw_screen.dart b/prediqo_mobile/lib/features/wallet/presentation/withdraw_screen.dart index 7cc30843..820cc302 100644 --- a/prediqo_mobile/lib/features/wallet/presentation/withdraw_screen.dart +++ b/prediqo_mobile/lib/features/wallet/presentation/withdraw_screen.dart @@ -180,7 +180,7 @@ class _WithdrawScreenState extends State { 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')); diff --git a/prediqo_web/src/features/settings/SettingsPage.tsx b/prediqo_web/src/features/settings/SettingsPage.tsx index a38a1a97..31e332c7 100644 --- a/prediqo_web/src/features/settings/SettingsPage.tsx +++ b/prediqo_web/src/features/settings/SettingsPage.tsx @@ -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() { {t('admin.settings.sections.networks.subtitle')} + + {t('admin.settings.sections.networks.applyHint')} + diff --git a/prediqo_web/src/features/wallet/WalletPage.tsx b/prediqo_web/src/features/wallet/WalletPage.tsx index 5ce0a4f0..41150e71 100644 --- a/prediqo_web/src/features/wallet/WalletPage.tsx +++ b/prediqo_web/src/features/wallet/WalletPage.tsx @@ -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={} onClick={() => openDialog('receive')} + disabled={depositableBalances.length === 0} sx={{ flex: 1 }} > {t('wallet.receiveUsdt')} @@ -174,6 +206,7 @@ export function WalletPage() { color="warning" startIcon={} onClick={() => openDialog('withdraw')} + disabled={withdrawableBalances.length === 0 || !(healthQ.data?.withdrawalsEnabled ?? false)} sx={{ flex: 1 }} > {t('wallet.withdraw')} diff --git a/prediqo_web/src/features/wallet/components/MainAssetCard.tsx b/prediqo_web/src/features/wallet/components/MainAssetCard.tsx index 8397b183..5d171057 100644 --- a/prediqo_web/src/features/wallet/components/MainAssetCard.tsx +++ b/prediqo_web/src/features/wallet/components/MainAssetCard.tsx @@ -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 ( - + {networkLabel(code)} - {balance.walletType.predictionEnabled ? ( + - ) : null} + + {balance.walletType.predictionEnabled ? ( + + ) : null} + - - - + {depositEnabled ? ( + + + + ) : null} @@ -81,8 +109,14 @@ export function MainAssetCard({ balance, onReceive, onSend }: MainAssetCardProps )} + {!depositEnabled && ( + + {t('wallet.mainCard.depositsDisabledHint')} + + )} + -