Skip to content

Commit

Permalink
added additional condition for router ready and function to remove re…
Browse files Browse the repository at this point in the history
…new parameter from query
  • Loading branch information
storywithoutend committed Nov 20, 2024
1 parent f74504b commit c0ae839
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/hooks/pages/profile/useRenew/useRenew.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const calculateRenewState = ({
connectModalOpen,
accountStatus,
isAbilitiesLoading,
isRouterReady,
name,
}: {
registrationStatus?: RegistrationStatus
Expand All @@ -30,11 +31,13 @@ export const calculateRenewState = ({
openConnectModal: ReturnType<typeof useConnectModal>['openConnectModal']
accountStatus: ReturnType<typeof useAccount>['status']
isAbilitiesLoading: boolean
isRouterReady: boolean
name?: string
}): RenewStatus => {
const isNameRegisteredOrGracePeriod =
registrationStatus === 'registered' || registrationStatus === 'gracePeriod'
const isRenewActive =
isRouterReady &&
!isRegistrationStatusLoading &&
!!name &&
isNameRegisteredOrGracePeriod &&
Expand All @@ -47,6 +50,19 @@ export const calculateRenewState = ({
return 'idle'
}

export const removeRenewParam = ({
query,
}: {
query: ReturnType<typeof useRouterWithHistory>['query']
}): string => {
const searchParams = new URLSearchParams(query as any)
// remove the name param in case the page is a redirect from /profile page
searchParams.delete('name')
searchParams.delete('renew')
const newParams = searchParams.toString()
return newParams ? `?${newParams}` : ''
}

export function useRenew(name: string) {
const router = useRouterWithHistory()
const { registrationStatus, isLoading: isBasicNameLoading } = useBasicName({ name })
Expand All @@ -70,6 +86,7 @@ export function useRenew(name: string) {
accountStatus: status,
isAbilitiesLoading,
name,
isRouterReady: router.isReady,
openConnectModal,
})

Expand All @@ -82,7 +99,8 @@ export function useRenew(name: string) {
isSelf: canSelfExtend,
seconds: renewSeconds!,
})
router.replace(`/${name}`)
const params = removeRenewParam({ query: router.query })
router.replace(`/${name}${params}`)
})
.with('idle', () => {})
.exhaustive()
Expand Down

0 comments on commit c0ae839

Please sign in to comment.