diff --git a/src/components/p2p/DepositWithdrawModal.tsx b/src/components/p2p/DepositWithdrawModal.tsx index ddb0470..7070b89 100644 --- a/src/components/p2p/DepositWithdrawModal.tsx +++ b/src/components/p2p/DepositWithdrawModal.tsx @@ -102,12 +102,15 @@ export function DepositWithdrawModal({ tx = (assetHubApi.tx.assets as any).transfer(1, PLATFORM_WALLET, amountPlanck.toString()); } - // Send TX and wait for finalization - const txHash = await new Promise((resolve, reject) => { + // Send TX and wait for finalization, capture block number for fast verification + const { txHash, blockNumber } = await new Promise<{ + txHash: string; + blockNumber: number; + }>((resolve, reject) => { tx.signAndSend( keypair, // eslint-disable-next-line @typescript-eslint/no-explicit-any - (result: any) => { + async (result: any) => { if (result.dispatchError) { if (result.dispatchError.isModule) { const decoded = assetHubApi!.registry.findMetaError(result.dispatchError.asModule); @@ -118,7 +121,17 @@ export function DepositWithdrawModal({ return; } if (result.status.isFinalized) { - resolve(result.txHash.toHex()); + try { + // Get block number from finalized block hash for fast verification + const header = await assetHubApi!.rpc.chain.getHeader(result.status.asFinalized); + resolve({ + txHash: result.txHash.toHex(), + blockNumber: header.number.toNumber(), + }); + } catch { + // Fallback: resolve without block number + resolve({ txHash: result.txHash.toHex(), blockNumber: 0 }); + } } } ).catch(reject); @@ -127,7 +140,13 @@ export function DepositWithdrawModal({ // TX finalized, now verify deposit on backend setDepositStep('verifying'); - const result = await verifyDeposit(sessionToken, txHash, depositToken, amount); + const result = await verifyDeposit( + sessionToken, + txHash, + depositToken, + amount, + blockNumber || undefined + ); setDepositResult({ amount: result.amount, token: result.token }); setDepositStep('success'); diff --git a/src/lib/p2p-api.ts b/src/lib/p2p-api.ts index b102321..f937bda 100644 --- a/src/lib/p2p-api.ts +++ b/src/lib/p2p-api.ts @@ -106,12 +106,19 @@ async function callEdgeFunction( if (error) { let msg = error.message || 'Unknown error'; - if (error.context?.body) { + // Try to extract the actual error from response body + const body = + error.context?.body ?? + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (error as any)?.body ?? + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (error as any)?.responseBody; + if (body) { try { - const parsed = JSON.parse(error.context.body); + const parsed = typeof body === 'string' ? JSON.parse(body) : body; if (parsed.error) msg = parsed.error; } catch { - if (typeof error.context.body === 'string') msg = error.context.body; + if (typeof body === 'string' && body.length < 500) msg = body; } } throw new Error(msg);