Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav Lysak committed Nov 19, 2024
1 parent e6df0a9 commit 36c7d89
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 67 deletions.
2 changes: 0 additions & 2 deletions src/hooks/pages/profile/useRenew.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import { useAccount } from 'wagmi'

import { useAbilities } from '@app/hooks/abilities/useAbilities'
import { useNameDetails } from '@app/hooks/useNameDetails'
import { useRouterWithHistory } from '@app/hooks/useRouterWithHistory'
import { useTransactionFlow } from '@app/transaction-flow/TransactionFlowProvider'
import { parseNumericString } from '@app/utils/string'

export function useRenew(name: string) {
const [opened, setOpened] = useState<boolean>(false)
const router = useRouterWithHistory()

const { registrationStatus, isLoading } = useNameDetails({ name })
const abilities = useAbilities({ name })
Expand Down
67 changes: 2 additions & 65 deletions src/components/pages/profile/[name]/Profile.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useConnectModal } from '@rainbow-me/rainbowkit'
import { useRenew } from '@root/ src/hooks/pages/profile/useRenew'
import Head from 'next/head'
import { useSearchParams } from 'next/navigation'
import { useEffect, useMemo, useState } from 'react'
import { useEffect, useMemo } from 'react'
import { Trans, useTranslation } from 'react-i18next'
import styled, { css } from 'styled-components'
import { match } from 'ts-pattern'
Expand All @@ -18,7 +17,6 @@ import { useProtectedRoute } from '@app/hooks/useProtectedRoute'
import { useQueryParameterState } from '@app/hooks/useQueryParameterState'
import { useRouterWithHistory } from '@app/hooks/useRouterWithHistory'
import { Content, ContentWarning } from '@app/layouts/Content'
import { useTransactionFlow } from '@app/transaction-flow/TransactionFlowProvider'
import { OG_IMAGE_URL } from '@app/utils/constants'
import { shouldRedirect } from '@app/utils/shouldRedirect'
import { formatFullExpiry, makeEtherscanLink } from '@app/utils/utils'
Expand Down Expand Up @@ -107,67 +105,6 @@ export const NameAvailableBanner = ({
)
}

function useRenew(name: string) {
const parseNumericString = (time: string | null) => {
if (!time) return

if (typeof +time === 'number' && !Number.isNaN(+time)) {
return +time
}
}

const [opened, setOpened] = useState<boolean>(false)
const router = useRouterWithHistory()

const { registrationStatus, isLoading } = useNameDetails({ name })
const abilities = useAbilities({ name })
const searchParams = useSearchParams()
const { isConnected, isDisconnected } = useAccount()
const { usePreparedDataInput } = useTransactionFlow()
const { openConnectModal } = useConnectModal()
const showExtendNamesInput = usePreparedDataInput('ExtendNames')

const { data: { canSelfExtend } = {} } = abilities
const isAvailableName = registrationStatus === 'available'
const renewSeconds = parseNumericString(searchParams.get('renew'))

useEffect(() => {
if (opened || !renewSeconds || isLoading) return

if (isAvailableName) {
setOpened(true)
router.push(`/${name}/register`)
return
}

if (!isAvailableName && isDisconnected) {
setOpened(true)
openConnectModal?.()
return
}

if (!isAvailableName && isConnected) {
setOpened(true)
showExtendNamesInput(`extend-names-${name}`, {
names: [name],
isSelf: canSelfExtend,
seconds: renewSeconds,
})
}

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
isAvailableName,
isLoading,
isConnected,
isDisconnected,
name,
canSelfExtend,
renewSeconds,
opened,
])
}

const ProfileContent = ({ isSelf, isLoading: parentIsLoading, name }: Props) => {
const router = useRouterWithHistory()
const { t } = useTranslation('profile')
Expand Down

0 comments on commit 36c7d89

Please sign in to comment.