From cf3353a216863ad9b4c7683a0f835cca0931f3d7 Mon Sep 17 00:00:00 2001 From: Kurdistan Tech Ministry Date: Sat, 7 Feb 2026 17:48:55 +0300 Subject: [PATCH] fix: wait for transaction finalization in LP staking --- package.json | 2 +- src/components/wallet/LPStakingModal.tsx | 94 +++++++++++++++++++++--- src/version.json | 6 +- 3 files changed, 88 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 146c520..73aa142 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pezkuwi-telegram-miniapp", - "version": "1.0.156", + "version": "1.0.157", "type": "module", "description": "Pezkuwichain Telegram Mini App - Forum, Announcements, Rewards", "author": "Pezkuwichain Team", diff --git a/src/components/wallet/LPStakingModal.tsx b/src/components/wallet/LPStakingModal.tsx index 94f3e8a..20c1fff 100644 --- a/src/components/wallet/LPStakingModal.tsx +++ b/src/components/wallet/LPStakingModal.tsx @@ -159,17 +159,41 @@ export function LPStakingModal({ isOpen, onClose }: LPStakingModalProps) { // eslint-disable-next-line @typescript-eslint/no-explicit-any const tx = (assetHubApi.tx.assetRewards as any).stake(selectedPool, amountBN.toString()); - const hash = await tx.signAndSend(keypair); + await new Promise((resolve, reject) => { + tx.signAndSend( + keypair, + ({ + status, + dispatchError, + }: { + status: { isFinalized: boolean }; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + dispatchError?: { isModule: boolean; asModule: any; toString: () => string }; + }) => { + if (status.isFinalized) { + if (dispatchError) { + let errorMsg = 'Stake neserketî'; + if (dispatchError.isModule) { + const decoded = assetHubApi.registry.findMetaError(dispatchError.asModule); + errorMsg = `${decoded.section}.${decoded.name}`; + } + reject(new Error(errorMsg)); + } else { + resolve(); + } + } + } + ).catch(reject); + }); + hapticNotification('success'); - showAlert(`Stake serket! Hash: ${hash.toString().slice(0, 16)}...`); + showAlert('Stake serket!'); setStakeAmount(''); - // Close modal after success setTimeout(() => { onClose(); }, 1500); } catch (err) { - console.error('Stake error:', err); setError(err instanceof Error ? err.message : 'Stake neserketî'); hapticNotification('error'); } finally { @@ -189,16 +213,41 @@ export function LPStakingModal({ isOpen, onClose }: LPStakingModalProps) { // eslint-disable-next-line @typescript-eslint/no-explicit-any const tx = (assetHubApi.tx.assetRewards as any).unstake(selectedPool, amountBN.toString()); - const hash = await tx.signAndSend(keypair); + await new Promise((resolve, reject) => { + tx.signAndSend( + keypair, + ({ + status, + dispatchError, + }: { + status: { isFinalized: boolean }; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + dispatchError?: { isModule: boolean; asModule: any; toString: () => string }; + }) => { + if (status.isFinalized) { + if (dispatchError) { + let errorMsg = 'Unstake neserketî'; + if (dispatchError.isModule) { + const decoded = assetHubApi.registry.findMetaError(dispatchError.asModule); + errorMsg = `${decoded.section}.${decoded.name}`; + } + reject(new Error(errorMsg)); + } else { + resolve(); + } + } + } + ).catch(reject); + }); + hapticNotification('success'); - showAlert(`Unstake serket! Hash: ${hash.toString().slice(0, 16)}...`); + showAlert('Unstake serket!'); setUnstakeAmount(''); setTimeout(() => { onClose(); }, 1500); } catch (err) { - console.error('Unstake error:', err); setError(err instanceof Error ? err.message : 'Unstake neserketî'); hapticNotification('error'); } finally { @@ -216,15 +265,40 @@ export function LPStakingModal({ isOpen, onClose }: LPStakingModalProps) { // eslint-disable-next-line @typescript-eslint/no-explicit-any const tx = (assetHubApi.tx.assetRewards as any).harvestRewards(selectedPool); - const hash = await tx.signAndSend(keypair); + await new Promise((resolve, reject) => { + tx.signAndSend( + keypair, + ({ + status, + dispatchError, + }: { + status: { isFinalized: boolean }; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + dispatchError?: { isModule: boolean; asModule: any; toString: () => string }; + }) => { + if (status.isFinalized) { + if (dispatchError) { + let errorMsg = 'Xelat stendin neserketî'; + if (dispatchError.isModule) { + const decoded = assetHubApi.registry.findMetaError(dispatchError.asModule); + errorMsg = `${decoded.section}.${decoded.name}`; + } + reject(new Error(errorMsg)); + } else { + resolve(); + } + } + } + ).catch(reject); + }); + hapticNotification('success'); - showAlert(`Xelat hat stendin! Hash: ${hash.toString().slice(0, 16)}...`); + showAlert('Xelat hat stendin!'); setTimeout(() => { onClose(); }, 1500); } catch (err) { - console.error('Claim error:', err); setError(err instanceof Error ? err.message : 'Xelat stendin neserketî'); hapticNotification('error'); } finally { diff --git a/src/version.json b/src/version.json index ccde3e3..689d199 100644 --- a/src/version.json +++ b/src/version.json @@ -1,5 +1,5 @@ { - "version": "1.0.156", - "buildTime": "2026-02-07T03:44:51.028Z", - "buildNumber": 1770435891028 + "version": "1.0.157", + "buildTime": "2026-02-07T14:48:55.082Z", + "buildNumber": 1770475735083 }