diff --git a/src/helpers/hasRevertFlag.ts b/src/helpers/hasRevertFlag.ts new file mode 100644 index 00000000..41d265cd --- /dev/null +++ b/src/helpers/hasRevertFlag.ts @@ -0,0 +1,8 @@ +// Copyright 2022 @paritytech/contracts-ui authors & contributors +// SPDX-License-Identifier: GPL-3.0-only + +import { ContractInstantiateResult } from 'types'; + +export function hasRevertFlag(dryRunResult: ContractInstantiateResult | undefined) { + return dryRunResult?.result.isOk ? dryRunResult.result.asOk.result.flags.isRevert : false; +} diff --git a/src/ui/components/instantiate/DryRun.tsx b/src/ui/components/instantiate/DryRun.tsx index 206fc775..60eefb9a 100644 --- a/src/ui/components/instantiate/DryRun.tsx +++ b/src/ui/components/instantiate/DryRun.tsx @@ -6,6 +6,7 @@ import { SidePanel } from '../common/SidePanel'; import { Account } from '../account/Account'; import { OutcomeItem } from '../contract/OutcomeItem'; import { useApi, useInstantiate } from 'ui/contexts'; +import { hasRevertFlag } from 'helpers/hasRevertFlag'; export function DryRun() { const { @@ -18,6 +19,8 @@ export function DryRun() { ? api.registry.findMetaError(dryRunResult?.result.asErr.asModule) : null; + const isReverted = hasRevertFlag(dryRunResult); + return (
@@ -96,12 +99,18 @@ export function DryRun() {
- {dryRunResult?.result.isOk && ( + {dryRunResult?.result.isOk && !isReverted && (
The instantiation will be successful.
)} + {isReverted && ( +
+ + Contract reverted! The instantiation will not be successful. +
+ )} {dryRunError && dryRunResult && ( <>
diff --git a/src/ui/components/instantiate/Step2.tsx b/src/ui/components/instantiate/Step2.tsx index 35a92064..ddd1ccf9 100644 --- a/src/ui/components/instantiate/Step2.tsx +++ b/src/ui/components/instantiate/Step2.tsx @@ -32,6 +32,7 @@ import { useBalance, } from 'ui/hooks'; import { AbiMessage, Balance, OrFalsy } from 'types'; +import { hasRevertFlag } from 'helpers/hasRevertFlag'; function validateSalt(value: OrFalsy) { if (!!value && value.length === 66) { @@ -60,6 +61,8 @@ export function Step2() { const { codeHash: codeHashUrlParam } = useParams<{ codeHash: string }>(); const isCustom = refTime.mode === 'custom' || proofSize.mode === 'custom'; + const isReverted = hasRevertFlag(dryRunResult); + useEffect(() => { setConstructorIndex(0); metadata && setDeployConstructor(metadata.constructors[0]); @@ -205,7 +208,8 @@ export function Step2() { !storageDepositLimit.isValid || !deployConstructor?.method || !!dryRunResult?.result.isErr || - !dryRunResult + !dryRunResult || + isReverted } onClick={onSubmit} variant="primary"