Skip to content

Commit b55c22e

Browse files
committed
dry run transactions prior to execution
1 parent b79463b commit b55c22e

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

packages/react-signer/src/PaymentInfo.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import type { BN } from '@polkadot/util';
99
import React, { useEffect, useState } from 'react';
1010
import { Trans } from 'react-i18next';
1111

12-
import { Expander, MarkWarning } from '@polkadot/react-components';
12+
import { Expander, MarkError, MarkWarning } from '@polkadot/react-components';
1313
import { useApi, useCall, useIsMountedRef } from '@polkadot/react-hooks';
14+
import { keyring } from '@polkadot/ui-keyring';
1415
import { formatBalance, nextTick } from '@polkadot/util';
1516

1617
import { useTranslation } from './translate.js';
@@ -28,6 +29,7 @@ function PaymentInfo ({ accountId, className = '', extrinsic, isHeader }: Props)
2829
const { t } = useTranslation();
2930
const { api } = useApi();
3031
const [dispatchInfo, setDispatchInfo] = useState<RuntimeDispatchInfo | null>(null);
32+
const [isDryRunError, setIsDryRunError] = useState(false);
3133
const balances = useCall<DeriveBalancesAll>(api.derive.balances?.all, [accountId]);
3234
const mountedRef = useIsMountedRef();
3335

@@ -53,6 +55,16 @@ function PaymentInfo ({ accountId, className = '', extrinsic, isHeader }: Props)
5355
balances.freeBalance.sub(dispatchInfo.partialFee).lte(api.consts.balances.existentialDeposit)
5456
);
5557

58+
if (extrinsic.hasDryRun && accountId) {
59+
const pair = keyring.getPair(accountId);
60+
61+
if (!pair.isLocked) {
62+
extrinsic.dryRun(pair, { nonce: -1 })
63+
.then(({ isErr }) => setIsDryRunError(isErr))
64+
.catch(() => setIsDryRunError(false));
65+
}
66+
}
67+
5668
return (
5769
<>
5870
<Expander
@@ -67,6 +79,9 @@ function PaymentInfo ({ accountId, className = '', extrinsic, isHeader }: Props)
6779
{isFeeError && (
6880
<MarkWarning content={t('The account does not have enough free funds (excluding locked/bonded/reserved) available to cover the transaction fees without dropping the balance below the account existential amount.')} />
6981
)}
82+
{isDryRunError && (
83+
<MarkError content={t('The transaction would not be successfully executed')} />
84+
)}
7085
</>
7186
);
7287
}

0 commit comments

Comments
 (0)