After trying to recuparate money from cold wallet5
This commit is contained in:
parent
0b4fb7f384
commit
bb30e14dfe
@ -68,11 +68,22 @@ export async function createFundRequest(input: {
|
||||
);
|
||||
if (!canRequest) throw new FundApprovalError('Permission denied: fund_operation.request');
|
||||
|
||||
const row = await fundOperationRequestRepository.createRequest({
|
||||
operationType: input.operationType,
|
||||
payload: input.payload,
|
||||
requestedBy: input.requestedBy,
|
||||
});
|
||||
let row;
|
||||
try {
|
||||
row = await fundOperationRequestRepository.createRequest({
|
||||
operationType: input.operationType,
|
||||
payload: input.payload,
|
||||
requestedBy: input.requestedBy,
|
||||
});
|
||||
} catch (e) {
|
||||
const msg = e instanceof Error ? e.message : '';
|
||||
if (/operation_type_check|violates check constraint/i.test(msg)) {
|
||||
throw new FundApprovalError(
|
||||
'Database schema is missing this operation type. Run db migrations and restart the backend.'
|
||||
);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
||||
await auditLogRepository.create({
|
||||
userId: input.requestedBy,
|
||||
|
||||
@ -232,12 +232,22 @@ export const treasuryFundingConfirmBodySchema = z.object({
|
||||
blockchainTxId: z.string().trim().min(1).max(255),
|
||||
});
|
||||
|
||||
export const treasuryGasTransferBodySchema = z.object({
|
||||
walletTypeId: z.number().int().positive(),
|
||||
direction: z.enum(['hot_to_cold', 'cold_to_hot']),
|
||||
amount: z.string().regex(/^\d+$/),
|
||||
notes: z.string().trim().max(2000).optional(),
|
||||
});
|
||||
export const treasuryGasTransferBodySchema = z
|
||||
.object({
|
||||
walletTypeId: z.coerce.number().int().positive(),
|
||||
direction: z.enum(['hot_to_cold', 'cold_to_hot']),
|
||||
amount: z.union([z.string(), z.number()]).transform((v) => String(v).trim()),
|
||||
notes: z.string().trim().max(2000).optional(),
|
||||
})
|
||||
.superRefine((val, ctx) => {
|
||||
if (!/^\d+$/.test(val.amount) || val.amount === '0') {
|
||||
ctx.addIssue({
|
||||
code: 'custom',
|
||||
message: 'amount must be a positive integer string',
|
||||
path: ['amount'],
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
export const countryRegistrationBodySchema = z.object({
|
||||
registrationAllowed: z.boolean(),
|
||||
|
||||
@ -48,6 +48,7 @@ import { PageHeader, RefreshIconButton } from '../../shared/components/PageHeade
|
||||
import { PermissionGate } from '../../shared/auth/PermissionGate';
|
||||
import { ScrollableTable } from '../../shared/components/ScrollableTable';
|
||||
import { copyTextToClipboard } from '../../shared/utils/clipboard';
|
||||
import { apiErrorMessage } from '../../shared/utils/apiError';
|
||||
import { rawToHuman } from '../wallet/utils/walletFormat';
|
||||
|
||||
type WalletType = {
|
||||
@ -279,6 +280,7 @@ export function TreasuryAdminPage() {
|
||||
} | null>(null);
|
||||
const [pendingMsg, setPendingMsg] = useState<string | null>(null);
|
||||
const [fundingError, setFundingError] = useState<string | null>(null);
|
||||
const [gasError, setGasError] = useState<string | null>(null);
|
||||
const [copyToast, setCopyToast] = useState<string | null>(null);
|
||||
|
||||
const notifyCopy = (ok: boolean) => {
|
||||
@ -405,7 +407,10 @@ export function TreasuryAdminPage() {
|
||||
void qc.invalidateQueries({ queryKey: ['admin-treasury-overview'] });
|
||||
void qc.invalidateQueries({ queryKey: ['admin-treasury-gas-preview'] });
|
||||
setGasForm((f) => ({ ...f, amount: '', notes: '' }));
|
||||
setFundingError(null);
|
||||
setGasError(null);
|
||||
},
|
||||
onError: (err) => {
|
||||
setGasError(apiErrorMessage(err, t('admin.treasury.gasRequestFailed')));
|
||||
},
|
||||
});
|
||||
|
||||
@ -445,29 +450,33 @@ export function TreasuryAdminPage() {
|
||||
};
|
||||
|
||||
const submitGasTransfer = () => {
|
||||
setFundingError(null);
|
||||
setGasError(null);
|
||||
if (!gasForm.walletTypeId) {
|
||||
setFundingError(t('admin.treasury.fundingSelectNetwork'));
|
||||
setGasError(t('admin.treasury.fundingSelectNetwork'));
|
||||
return;
|
||||
}
|
||||
if (!gasPreview) {
|
||||
setFundingError(t('admin.treasury.gasPreviewError'));
|
||||
setGasError(t('admin.treasury.gasPreviewError'));
|
||||
return;
|
||||
}
|
||||
const raw = humanAmountToRaw(gasForm.amount, gasPreview.decimals);
|
||||
let raw = humanAmountToRaw(gasForm.amount, gasPreview.decimals);
|
||||
if (raw === '0') {
|
||||
setFundingError(t('admin.treasury.invalidGasAmount'));
|
||||
setGasError(t('admin.treasury.invalidGasAmount'));
|
||||
return;
|
||||
}
|
||||
if (gasForm.direction === 'hot_to_cold' && BigInt(raw) > BigInt(gasPreview.maxSendable)) {
|
||||
setFundingError(t('admin.treasury.gasExceedsReserve'));
|
||||
return;
|
||||
if (gasForm.direction === 'hot_to_cold') {
|
||||
const max = BigInt(gasPreview.maxSendable);
|
||||
if (max <= 0n) {
|
||||
setGasError(t('admin.treasury.gasExceedsReserve'));
|
||||
return;
|
||||
}
|
||||
if (BigInt(raw) > max) raw = max.toString();
|
||||
}
|
||||
void requestGasMut.mutateAsync({
|
||||
requestGasMut.mutate({
|
||||
walletTypeId: gasForm.walletTypeId,
|
||||
direction: gasForm.direction,
|
||||
amount: raw,
|
||||
notes: gasForm.notes || undefined,
|
||||
notes: gasForm.notes.trim() || undefined,
|
||||
});
|
||||
};
|
||||
|
||||
@ -833,6 +842,7 @@ export function TreasuryAdminPage() {
|
||||
)}
|
||||
<PermissionGate permission="admin.treasury.manage">
|
||||
<Button
|
||||
type="button"
|
||||
variant="contained"
|
||||
disabled={requestGasMut.isPending || !gasForm.amount.trim()}
|
||||
onClick={submitGasTransfer}
|
||||
@ -843,10 +853,17 @@ export function TreasuryAdminPage() {
|
||||
minHeight: 40,
|
||||
}}
|
||||
>
|
||||
{t('admin.treasury.requestGasTransfer')}
|
||||
{requestGasMut.isPending
|
||||
? t('common.sending')
|
||||
: t('admin.treasury.requestGasTransfer')}
|
||||
</Button>
|
||||
</PermissionGate>
|
||||
</Stack>
|
||||
{gasError && (
|
||||
<Alert severity="error" onClose={() => setGasError(null)}>
|
||||
{gasError}
|
||||
</Alert>
|
||||
)}
|
||||
<TextField
|
||||
size="small"
|
||||
label={t('admin.treasury.notes')}
|
||||
|
||||
@ -1571,6 +1571,7 @@ export const en = {
|
||||
invalidGasAmount: 'Enter a valid native amount greater than zero',
|
||||
gasExceedsReserve: 'This amount would leave the hot wallet below the withdrawal gas reserve',
|
||||
gasPreviewError: 'Could not load gas balances for this network',
|
||||
gasRequestFailed: 'Gas transfer request failed',
|
||||
fundingKindUsdt: 'USDT',
|
||||
fundingKindGas: 'Gas',
|
||||
confirmDialogHintGas:
|
||||
|
||||
@ -1587,6 +1587,7 @@ export const fr = {
|
||||
invalidGasAmount: 'Saisissez un montant natif valide supérieur à zéro',
|
||||
gasExceedsReserve: 'Ce montant laisserait le hot wallet sous la réserve de gas des retraits',
|
||||
gasPreviewError: 'Impossible de charger les soldes de gas pour ce réseau',
|
||||
gasRequestFailed: 'La demande de transfert de gas a échoué',
|
||||
fundingKindUsdt: 'USDT',
|
||||
fundingKindGas: 'Gas',
|
||||
confirmDialogHintGas:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user