fix: use direct fetch for verify-deposit to read error responses

This commit is contained in:
2026-02-23 12:29:28 +03:00
parent d7935e2c4f
commit b9024cb034
+14 -8
View File
@@ -32,7 +32,7 @@ import {
import { usePezkuwi } from '@/contexts/PezkuwiContext'; import { usePezkuwi } from '@/contexts/PezkuwiContext';
import { useWallet } from '@/contexts/WalletContext'; import { useWallet } from '@/contexts/WalletContext';
import { toast } from 'sonner'; import { toast } from 'sonner';
import { supabase } from '@/lib/supabase';
import { import {
getPlatformWalletAddress, getPlatformWalletAddress,
type CryptoToken type CryptoToken
@@ -177,20 +177,26 @@ export function DepositModal({ isOpen, onClose, onSuccess }: DepositModalProps)
try { try {
// Call the Edge Function for secure deposit verification // Call the Edge Function for secure deposit verification
// This verifies the transaction on-chain before crediting balance // Use fetch directly to read response body on all status codes
const { data, error } = await supabase.functions.invoke('verify-deposit', { const supabaseUrl = import.meta.env.VITE_SUPABASE_URL;
body: { const supabaseKey = import.meta.env.VITE_SUPABASE_ANON_KEY;
const res = await fetch(`${supabaseUrl}/functions/v1/verify-deposit`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${supabaseKey}`,
'apikey': supabaseKey,
},
body: JSON.stringify({
txHash, txHash,
token, token,
expectedAmount: depositAmount, expectedAmount: depositAmount,
walletAddress: selectedAccount?.address, walletAddress: selectedAccount?.address,
...(blockNumber ? { blockNumber } : {}) ...(blockNumber ? { blockNumber } : {})
} })
}); });
if (error) { const data = await res.json();
throw new Error(error.message || t('p2pDeposit.verificationFailed'));
}
if (data?.success) { if (data?.success) {
toast.success(t('p2pDeposit.depositVerified', { amount: data.amount, token })); toast.success(t('p2pDeposit.depositVerified', { amount: data.amount, token }));