fix: pass block number hint to verify-deposit for faster verification

- Get block number from finalized block hash in frontend
- Pass as hint to verify-deposit-telegram to avoid 100-block scan
- Improve error message extraction in callEdgeFunction
This commit is contained in:
2026-02-26 22:44:50 +03:00
parent 4686453df7
commit b67809481e
2 changed files with 34 additions and 8 deletions
+24 -5
View File
@@ -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<string>((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');
+10 -3
View File
@@ -106,12 +106,19 @@ async function callEdgeFunction<T>(
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);