diff --git a/src/components/pages/profile/[name]/registration/steps/Transactions.tsx b/src/components/pages/profile/[name]/registration/steps/Transactions.tsx
index 6fa915441..71640cd03 100644
--- a/src/components/pages/profile/[name]/registration/steps/Transactions.tsx
+++ b/src/components/pages/profile/[name]/registration/steps/Transactions.tsx
@@ -11,6 +11,7 @@ import MobileFullWidth from '@app/components/@atoms/MobileFullWidth'
import { TextWithTooltip } from '@app/components/@atoms/TextWithTooltip/TextWithTooltip'
import { Card } from '@app/components/Card'
import { useExistingCommitment } from '@app/hooks/registration/useExistingCommitment'
+import { useSimulateRegistration } from '@app/hooks/registration/useSimulateRegistration'
import { useDurationCountdown } from '@app/hooks/time/useDurationCountdown'
import useRegistrationParams from '@app/hooks/useRegistrationParams'
import { CenteredTypography } from '@app/transaction-flow/input/ProfileEditor/components/CenteredTypography'
@@ -126,6 +127,17 @@ const Transactions = ({ registrationData, name, callback, onStart }: Props) => {
commitKey,
})
+ const { isSuccess: canRegisterOveride } = useSimulateRegistration({
+ registrationParams,
+ query: {
+ enabled: true,
+ retry: true,
+ retryDelay: 10000,
+ },
+ })
+
+ const commitCompleteOrCanRegisterOveride = commitComplete || canRegisterOveride
+
const makeCommitNameFlow = useCallback(() => {
onStart()
createTransactionFlow(commitKey, {
@@ -228,7 +240,7 @@ const Transactions = ({ registrationData, name, callback, onStart }: Props) => {
callback={() => setCommitComplete(true)}
/>
- {match([commitTx, commitComplete, duration])
+ {match([commitTx, commitCompleteOrCanRegisterOveride, duration])
.with([{ stage: 'complete' }, false, P._], () => (
{
.otherwise(() => t('steps.transactions.subheading.default'))}
- {match([commitComplete, registerTx, commitTx])
+ {match([commitCompleteOrCanRegisterOveride, registerTx, commitTx])
.with([true, { stage: 'failed' }, P._], () => (
<>
{ResetBackButton}
diff --git a/src/hooks/registration/useSimulateRegistration.ts b/src/hooks/registration/useSimulateRegistration.ts
new file mode 100644
index 000000000..962e311ea
--- /dev/null
+++ b/src/hooks/registration/useSimulateRegistration.ts
@@ -0,0 +1,37 @@
+import { usePublicClient, useSimulateContract, UseSimulateContractParameters } from 'wagmi'
+
+import { ethRegistrarControllerRegisterSnippet } from '@ensdomains/ensjs/contracts'
+import { makeRegistrationTuple, RegistrationParameters } from '@ensdomains/ensjs/utils'
+
+import { calculateValueWithBuffer } from '@app/utils/utils'
+
+import { usePrice } from '../ensjs/public/usePrice'
+
+type UseSimulateRegistrationParameters = Pick & {
+ registrationParams: RegistrationParameters
+}
+
+export const useSimulateRegistration = ({
+ registrationParams,
+ query,
+}: UseSimulateRegistrationParameters) => {
+ const client = usePublicClient()
+
+ const { data: price } = usePrice({
+ nameOrNames: registrationParams.name,
+ duration: registrationParams.duration,
+ })
+
+ const base = price?.base ?? 0n
+ const premium = price?.premium ?? 0n
+ const value = base + premium
+
+ return useSimulateContract({
+ abi: ethRegistrarControllerRegisterSnippet,
+ address: client.chain.contracts.ensEthRegistrarController.address,
+ functionName: 'register',
+ args: makeRegistrationTuple(registrationParams),
+ value: calculateValueWithBuffer(value),
+ query,
+ })
+}