Skip to content

Commit bdb6963

Browse files
committed
dry run transactions prior to execution
1 parent c8036d6 commit bdb6963

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

packages/react-signer/src/PaymentInfo.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ 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';
1414
import { formatBalance, nextTick } from '@polkadot/util';
1515

1616
import { useTranslation } from './translate.js';
17+
import { keyring } from '@polkadot/ui-keyring';
1718

1819
interface Props {
1920
accountId?: string | null;
@@ -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,15 @@ 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+
if (!pair.isLocked) {
61+
extrinsic.dryRun(pair, {nonce: -1})
62+
.then(({isErr}) => setIsDryRunError(isErr))
63+
.catch(() => setIsDryRunError(false));
64+
}
65+
}
66+
5667
return (
5768
<>
5869
<Expander
@@ -67,6 +78,9 @@ function PaymentInfo ({ accountId, className = '', extrinsic, isHeader }: Props)
6778
{isFeeError && (
6879
<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.')} />
6980
)}
81+
{isDryRunError && (
82+
<MarkError content={t('The transaction would not be successfully executed')} />
83+
)}
7084
</>
7185
);
7286
}

0 commit comments

Comments
 (0)