Skip to content

Commit

Permalink
add flag to track if connect modal has been opened
Browse files Browse the repository at this point in the history
  • Loading branch information
storywithoutend committed Nov 20, 2024
1 parent c0ae839 commit 4b32cf5
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/hooks/pages/profile/useRenew/useRenew.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useConnectModal } from '@rainbow-me/rainbowkit'
import { useSearchParams } from 'next/navigation'
import { useEffect } from 'react'
import { useEffect, useState } from 'react'
import { match } from 'ts-pattern'
import { useAccount } from 'wagmi'

Expand All @@ -23,6 +23,7 @@ export const calculateRenewState = ({
isAbilitiesLoading,
isRouterReady,
name,
openedConnectModal,
}: {
registrationStatus?: RegistrationStatus
isRegistrationStatusLoading: boolean
Expand All @@ -33,6 +34,7 @@ export const calculateRenewState = ({
isAbilitiesLoading: boolean
isRouterReady: boolean
name?: string
openedConnectModal: boolean
}): RenewStatus => {
const isNameRegisteredOrGracePeriod =
registrationStatus === 'registered' || registrationStatus === 'gracePeriod'
Expand All @@ -44,7 +46,13 @@ export const calculateRenewState = ({
!!renewSeconds &&
!connectModalOpen

if (isRenewActive && accountStatus === 'disconnected' && !!openConnectModal) return 'connect-user'
if (
isRenewActive &&
accountStatus === 'disconnected' &&
!!openConnectModal &&
!openedConnectModal
)
return 'connect-user'
if (isRenewActive && accountStatus === 'connected' && !isAbilitiesLoading)
return 'display-extend-names'
return 'idle'
Expand All @@ -69,7 +77,9 @@ export function useRenew(name: string) {
const abilities = useAbilities({ name })
const searchParams = useSearchParams()
const { status } = useAccount()

const { openConnectModal, connectModalOpen } = useConnectModal()
const [openedConnectModal, setOpenedConnectModal] = useState(connectModalOpen)

const { usePreparedDataInput } = useTransactionFlow()
const showExtendNamesInput = usePreparedDataInput('ExtendNames')
Expand All @@ -88,11 +98,15 @@ export function useRenew(name: string) {
name,
isRouterReady: router.isReady,
openConnectModal,
openedConnectModal,
})

useEffect(() => {
match(renewState)
.with('connect-user', () => openConnectModal?.())
.with('connect-user', () => {
openConnectModal?.()
setOpenedConnectModal(!!openConnectModal)
})
.with('display-extend-names', () => {
showExtendNamesInput(`extend-names-${name}`, {
names: [name],
Expand Down

0 comments on commit 4b32cf5

Please sign in to comment.