From b55c22e51ce10b23969fe1edccc3815d4f10d3ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=CC=81=20Molina?= Date: Mon, 18 Mar 2024 08:47:23 +0100 Subject: [PATCH 1/2] dry run transactions prior to execution --- packages/react-signer/src/PaymentInfo.tsx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/react-signer/src/PaymentInfo.tsx b/packages/react-signer/src/PaymentInfo.tsx index dd0b1f4cac7f..25fe9752c205 100644 --- a/packages/react-signer/src/PaymentInfo.tsx +++ b/packages/react-signer/src/PaymentInfo.tsx @@ -9,8 +9,9 @@ import type { BN } from '@polkadot/util'; import React, { useEffect, useState } from 'react'; import { Trans } from 'react-i18next'; -import { Expander, MarkWarning } from '@polkadot/react-components'; +import { Expander, MarkError, MarkWarning } from '@polkadot/react-components'; import { useApi, useCall, useIsMountedRef } from '@polkadot/react-hooks'; +import { keyring } from '@polkadot/ui-keyring'; import { formatBalance, nextTick } from '@polkadot/util'; import { useTranslation } from './translate.js'; @@ -28,6 +29,7 @@ function PaymentInfo ({ accountId, className = '', extrinsic, isHeader }: Props) const { t } = useTranslation(); const { api } = useApi(); const [dispatchInfo, setDispatchInfo] = useState(null); + const [isDryRunError, setIsDryRunError] = useState(false); const balances = useCall(api.derive.balances?.all, [accountId]); const mountedRef = useIsMountedRef(); @@ -53,6 +55,16 @@ function PaymentInfo ({ accountId, className = '', extrinsic, isHeader }: Props) balances.freeBalance.sub(dispatchInfo.partialFee).lte(api.consts.balances.existentialDeposit) ); + if (extrinsic.hasDryRun && accountId) { + const pair = keyring.getPair(accountId); + + if (!pair.isLocked) { + extrinsic.dryRun(pair, { nonce: -1 }) + .then(({ isErr }) => setIsDryRunError(isErr)) + .catch(() => setIsDryRunError(false)); + } + } + return ( <> )} + {isDryRunError && ( + + )} ); } From 2a028cf1a5dad555483efbc34c6c9b151b15be5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=CC=81=20Molina?= Date: Mon, 25 Mar 2024 17:34:43 +0100 Subject: [PATCH 2/2] improve error message --- packages/react-signer/src/PaymentInfo.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-signer/src/PaymentInfo.tsx b/packages/react-signer/src/PaymentInfo.tsx index 25fe9752c205..bc6b15497bab 100644 --- a/packages/react-signer/src/PaymentInfo.tsx +++ b/packages/react-signer/src/PaymentInfo.tsx @@ -80,7 +80,7 @@ function PaymentInfo ({ accountId, className = '', extrinsic, isHeader }: Props) )} {isDryRunError && ( - + )} );