mirror of
https://github.com/pezkuwichain/pezkuwi-telegram-miniapp.git
synced 2026-04-22 03:07:55 +00:00
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:
@@ -102,12 +102,15 @@ export function DepositWithdrawModal({
|
|||||||
tx = (assetHubApi.tx.assets as any).transfer(1, PLATFORM_WALLET, amountPlanck.toString());
|
tx = (assetHubApi.tx.assets as any).transfer(1, PLATFORM_WALLET, amountPlanck.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send TX and wait for finalization
|
// Send TX and wait for finalization, capture block number for fast verification
|
||||||
const txHash = await new Promise<string>((resolve, reject) => {
|
const { txHash, blockNumber } = await new Promise<{
|
||||||
|
txHash: string;
|
||||||
|
blockNumber: number;
|
||||||
|
}>((resolve, reject) => {
|
||||||
tx.signAndSend(
|
tx.signAndSend(
|
||||||
keypair,
|
keypair,
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
(result: any) => {
|
async (result: any) => {
|
||||||
if (result.dispatchError) {
|
if (result.dispatchError) {
|
||||||
if (result.dispatchError.isModule) {
|
if (result.dispatchError.isModule) {
|
||||||
const decoded = assetHubApi!.registry.findMetaError(result.dispatchError.asModule);
|
const decoded = assetHubApi!.registry.findMetaError(result.dispatchError.asModule);
|
||||||
@@ -118,7 +121,17 @@ export function DepositWithdrawModal({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (result.status.isFinalized) {
|
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);
|
).catch(reject);
|
||||||
@@ -127,7 +140,13 @@ export function DepositWithdrawModal({
|
|||||||
// TX finalized, now verify deposit on backend
|
// TX finalized, now verify deposit on backend
|
||||||
setDepositStep('verifying');
|
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 });
|
setDepositResult({ amount: result.amount, token: result.token });
|
||||||
setDepositStep('success');
|
setDepositStep('success');
|
||||||
|
|||||||
+10
-3
@@ -106,12 +106,19 @@ async function callEdgeFunction<T>(
|
|||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
let msg = error.message || 'Unknown 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 {
|
try {
|
||||||
const parsed = JSON.parse(error.context.body);
|
const parsed = typeof body === 'string' ? JSON.parse(body) : body;
|
||||||
if (parsed.error) msg = parsed.error;
|
if (parsed.error) msg = parsed.error;
|
||||||
} catch {
|
} catch {
|
||||||
if (typeof error.context.body === 'string') msg = error.context.body;
|
if (typeof body === 'string' && body.length < 500) msg = body;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new Error(msg);
|
throw new Error(msg);
|
||||||
|
|||||||
Reference in New Issue
Block a user