diff --git a/web/src/components/staking/StakingDashboard.tsx b/web/src/components/staking/StakingDashboard.tsx index a7d01203..71a13e9f 100644 --- a/web/src/components/staking/StakingDashboard.tsx +++ b/web/src/components/staking/StakingDashboard.tsx @@ -22,6 +22,7 @@ import { type StakingInfo } from '@pezkuwi/lib/staking'; import { LoadingState } from '@pezkuwi/components/AsyncComponent'; +import { handleBlockchainError, handleBlockchainSuccess } from '@pezkuwi/lib/error-handler'; export const StakingDashboard: React.FC = () => { const { t } = useTranslation(); @@ -120,22 +121,10 @@ export const StakingDashboard: React.FC = () => { console.log('Transaction in block:', status.asInBlock.toHex()); if (dispatchError) { - let errorMessage = 'Transaction failed'; - if (dispatchError.isModule) { - const decoded = api.registry.findMetaError(dispatchError.asModule); - errorMessage = `${decoded.section}.${decoded.name}: ${decoded.docs.join(' ')}`; - } - toast({ - title: 'Error', - description: errorMessage, - variant: 'destructive', - }); + handleBlockchainError(dispatchError, api, toast); setIsLoading(false); } else { - toast({ - title: 'Success', - description: `Bonded ${bondAmount} HEZ successfully`, - }); + handleBlockchainSuccess('staking.bonded', toast, { amount: bondAmount }); setBondAmount(''); refreshBalances(); // Refresh staking data after a delay @@ -184,22 +173,10 @@ export const StakingDashboard: React.FC = () => { ({ status, dispatchError }) => { if (status.isInBlock) { if (dispatchError) { - let errorMessage = 'Nomination failed'; - if (dispatchError.isModule) { - const decoded = api.registry.findMetaError(dispatchError.asModule); - errorMessage = `${decoded.section}.${decoded.name}: ${decoded.docs.join(' ')}`; - } - toast({ - title: 'Error', - description: errorMessage, - variant: 'destructive', - }); + handleBlockchainError(dispatchError, api, toast); setIsLoading(false); } else { - toast({ - title: 'Success', - description: `Nominated ${selectedValidators.length} validator(s)`, - }); + handleBlockchainSuccess('staking.nominated', toast, { count: selectedValidators.length.toString() }); // Refresh staking data setTimeout(() => { if (api && selectedAccount) { @@ -242,21 +219,12 @@ export const StakingDashboard: React.FC = () => { ({ status, dispatchError }) => { if (status.isInBlock) { if (dispatchError) { - let errorMessage = 'Unbond failed'; - if (dispatchError.isModule) { - const decoded = api.registry.findMetaError(dispatchError.asModule); - errorMessage = `${decoded.section}.${decoded.name}: ${decoded.docs.join(' ')}`; - } - toast({ - title: 'Error', - description: errorMessage, - variant: 'destructive', - }); + handleBlockchainError(dispatchError, api, toast); setIsLoading(false); } else { - toast({ - title: 'Success', - description: `Unbonded ${unbondAmount} HEZ. Withdrawal available in ${bondingDuration} eras`, + handleBlockchainSuccess('staking.unbonded', toast, { + amount: unbondAmount, + duration: bondingDuration.toString() }); setUnbondAmount(''); setTimeout(() => {