Skip to content

Commit

Permalink
fix: add dnsclaim redirect for claimed names
Browse files Browse the repository at this point in the history
  • Loading branch information
TateB committed Mar 28, 2024
1 parent eba13b7 commit 2e6f649
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions src/components/pages/import/[name]/DnsClaim.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,54 @@ import { useEffect } from 'react'
import { useTranslation } from 'react-i18next'
import { useAccount } from 'wagmi'

import { useBasicName } from '@app/hooks/useBasicName'
import { useRouterWithHistory } from '@app/hooks/useRouterWithHistory'
import { useValidate } from '@app/hooks/useValidate'
import { Content } from '@app/layouts/Content'
import { useTransactionFlow } from '@app/transaction-flow/TransactionFlowProvider'
import { RegistrationStatus } from '@app/utils/registrationStatus'

import { CompleteImport } from './steps/CompleteImport'
import { EnableDnssec } from './steps/EnableDnssec'
import { ImportTransaction } from './steps/onchain/ImportTransaction'
import { VerifyOnchainOwnership } from './steps/onchain/VerifyOnchainOwnership'
import { SelectImportType } from './steps/SelectImportType'
import { VerifyOffchainOwnership } from './steps/VerifyOffchainOwnership'
import { useDnsImportReducer } from './useDnsImportReducer'
import { DnsImportReducerDataItem, DnsStep, useDnsImportReducer } from './useDnsImportReducer'

const getShouldRedirect = ({
isLoading,
registrationStatus,
item,
step,
}: {
isLoading: boolean
registrationStatus?: RegistrationStatus
item: DnsImportReducerDataItem
step: DnsStep
}) => {
console.log({ isLoading, registrationStatus, item, step })
if (isLoading) return false
if (!registrationStatus) return false
if (registrationStatus === 'notImported') return false
if (registrationStatus === 'notOwned') return false

if (!item.started) return true

if (step === 'completeOnchain') return false
if (step === 'completeOffchain') return false

return true
}

export const DnsClaim = () => {
const router = useRouterWithHistory()
const { address } = useAccount()
const {
registrationStatus,
isLoading,
name = '',
} = useBasicName({ name: router.query.name as string })

const { name = '' } = useValidate({ input: router.query.name as string })
const { t } = useTranslation('dnssec')

const { dispatch, item, selected } = useDnsImportReducer({
Expand Down Expand Up @@ -62,6 +92,10 @@ export const DnsClaim = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [dispatch, step, selected, router.asPath])

if (router.isReady && getShouldRedirect({ isLoading, registrationStatus, item, step })) {
router.push(`/profile/${name}`)
}

return (
<>
<Head>
Expand Down

0 comments on commit 2e6f649

Please sign in to comment.