Skip to content

Commit e544f39

Browse files
refactor: move referrer dispatch to pricingCallback and add loading state
Move setReferrer dispatch from useEffect to pricingCallback to ensure referrer is set synchronously when user proceeds. Add isLoading prop to Pricing component to disable continue button while referrer is resolving. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 0577d0f commit e544f39

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

src/components/pages/profile/[name]/registration/Registration.tsx

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,8 @@ const Registration = ({ nameDetails, isLoading }: Props) => {
113113
const { address } = useAccount()
114114
const primary = usePrimaryName({ address })
115115
const referrerParam = useReferrer()
116-
const { data: resolvedReferrerHex } = useResolvedReferrer(referrerParam)
117-
// Note: referrer is not included in `selected` to prevent creating new registration
118-
// sessions when the referrer changes. It's updated separately via setReferrer action.
116+
const { data: resolvedReferrerHex, isLoading: isResolvingReferrer } =
117+
useResolvedReferrer(referrerParam)
119118
const selected = useMemo(
120119
() => ({ name: nameDetails.normalisedName, address: address!, chainId }),
121120
[address, chainId, nameDetails.normalisedName],
@@ -131,18 +130,6 @@ const Registration = ({ nameDetails, isLoading }: Props) => {
131130
const { dispatch, item } = useRegistrationReducer(selected)
132131
const step = item.queue[item.stepIndex]
133132

134-
// Update referrer in registration data when resolved.
135-
// This happens asynchronously and won't block the registration flow.
136-
useEffect(() => {
137-
if (resolvedReferrerHex) {
138-
dispatch({
139-
name: 'setReferrer',
140-
selected,
141-
payload: resolvedReferrerHex,
142-
})
143-
}
144-
}, [resolvedReferrerHex, selected, dispatch])
145-
146133
const keySuffix = `${nameDetails.normalisedName}-${address}`
147134
const commitKey = `commit-${keySuffix}`
148135
const registerKey = `register-${keySuffix}`
@@ -183,6 +170,13 @@ const Registration = ({ nameDetails, isLoading }: Props) => {
183170
initiateMoonpayRegistrationMutation.mutate(secondsToYears(seconds))
184171
return
185172
}
173+
if (resolvedReferrerHex) {
174+
dispatch({
175+
name: 'setReferrer',
176+
selected,
177+
payload: resolvedReferrerHex,
178+
})
179+
}
186180
dispatch({
187181
name: 'setPricingData',
188182
payload: { seconds, reverseRecord, durationType },
@@ -356,6 +350,7 @@ const Registration = ({ nameDetails, isLoading }: Props) => {
356350
registrationData={item}
357351
moonpayTransactionStatus={moonpayTransactionStatus}
358352
initiateMoonpayRegistrationMutation={initiateMoonpayRegistrationMutation}
353+
isLoading={isResolvingReferrer}
359354
/>
360355
))
361356
.with([false, 'profile'], () => (

src/components/pages/profile/[name]/registration/steps/Pricing/Pricing.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ export type ActionButtonProps = {
367367
estimatedTotal?: bigint
368368
ethPrice?: bigint
369369
durationType: 'date' | 'years'
370+
isLoading?: boolean
370371
}
371372

372373
export const ActionButton = (props: ActionButtonProps) => {
@@ -384,6 +385,11 @@ export const ActionButton = (props: ActionButtonProps) => {
384385
{t('steps.info.processing')}
385386
</Button>
386387
))
388+
.with({ isLoading: true }, () => (
389+
<Button data-testid="next-button" disabled loading>
390+
{t('loading', { ns: 'common' })}
391+
</Button>
392+
))
387393
.with(
388394
{ paymentMethodChoice: PaymentMethod.moonpay },
389395
({
@@ -486,6 +492,7 @@ export type PricingProps = {
486492
initiateMoonpayRegistrationMutation: ReturnType<
487493
typeof useMoonpayRegistration
488494
>['initiateMoonpayRegistrationMutation']
495+
isLoading?: boolean
489496
}
490497

491498
const minSeconds = 28 * ONE_DAY
@@ -501,6 +508,7 @@ const Pricing = ({
501508
resolverExists,
502509
moonpayTransactionStatus,
503510
initiateMoonpayRegistrationMutation,
511+
isLoading,
504512
}: PricingProps) => {
505513
const { t } = useTranslation('register')
506514

@@ -621,6 +629,7 @@ const Pricing = ({
621629
estimatedTotal,
622630
ethPrice,
623631
durationType,
632+
isLoading,
624633
}}
625634
/>
626635
</MobileFullWidth>

0 commit comments

Comments
 (0)