mirror of
https://github.com/pezkuwichain/pwap.git
synced 2026-06-12 15:31:09 +00:00
fix: use direct fetch for verify-deposit to read error responses
This commit is contained in:
@@ -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 }));
|
||||||
|
|||||||
Reference in New Issue
Block a user