Skip to content

Commit

Permalink
eligible names rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
talentlessguy committed Oct 29, 2024
1 parent b18615c commit ed6719e
Showing 1 changed file with 61 additions and 26 deletions.
87 changes: 61 additions & 26 deletions src/transaction-flow/input/BulkRenewal/BulkRenewal-flow.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import Link from 'next/link'
import { useState } from 'react'
import { namehash } from 'viem'
import { useTranslation } from 'react-i18next'
import styled, { css } from 'styled-components'
import { ContractFunctionRevertedError, decodeErrorResult, namehash } from 'viem'
import { useClient, useReadContract } from 'wagmi'

import { NameWithRelation } from '@ensdomains/ensjs/subgraph'
import { Dialog } from '@ensdomains/thorin'
import { Dialog, Heading, Helper, OutlinkSVG, Typography } from '@ensdomains/thorin'

import { InvoiceItem } from '@app/components/@atoms/Invoice/Invoice'
import { DateSelection } from '@app/components/@molecules/DateSelection/DateSelection'
Expand Down Expand Up @@ -52,33 +55,59 @@ const abi = [
},
] as const

const EligibleForTokens = styled.div(
({ theme }) => css`
padding: ${theme.space['4']};
gap: ${theme.space['2']};
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content: center;
width: ${theme.space.full};
border-radius: ${theme.radii['2xLarge']};
background: ${theme.colors.greenSurface};
a {
display: flex;
flex-direction: row;
align-items: center;
gap: ${theme.space['2']};
color: ${theme.colors.greenPrimary};
}
`,
)

const BulkRenewalFlow = ({ data }: Props) => {
// Sort from the ones that expire earlier to later
const sortedNames = data.names.toSorted((a, b) => a.expiryDate!.value! - b.expiryDate!.value!)

const minDateDiff = calculateDatesDiff(sortedNames[0].expiryDate!.date, REBATE_DATE)

const minSeconds = secondsFromDateDiff({
startDate: sortedNames[0].expiryDate!.date,
additionalDays: minDateDiff.diff.days,
additionalMonths: minDateDiff.diff.months,
additionalYears: minDateDiff.diff.years,
})
const minSeconds =
secondsFromDateDiff({
startDate: sortedNames[0].expiryDate!.date,
additionalDays: minDateDiff.diff.days,
additionalMonths: minDateDiff.diff.months,
additionalYears: minDateDiff.diff.years,
}) + 84600

const [seconds, setSeconds] = useState(() => minSeconds)
const [seconds, setSeconds] = useState(minSeconds)
const [durationType, setDurationType] = useState<'years' | 'date'>('years')

// const client = useClient()
const client = useClient()

const {
data: expiryData,
error,
status,
} = useReadContract({
abi,
address: bulkRenewalContract[client.chain.id!]!,
functionName: 'getTargetExpiryPriceData',
args: [data.names.map((name) => namehash(name.name!)), BigInt(seconds)],
})

// const {
// data: expiryData,
// error,
// status,
// } = useReadContract({
// abi,
// address: bulkRenewalContract[client.chain.id!]!,
// functionName: 'getTargetExpiryPriceData',
// args: [data.names.map((name) => namehash(name.name!)), BigInt(seconds)],
// })
const { t } = useTranslation('common')

return (
<>
Expand All @@ -91,12 +120,18 @@ const BulkRenewalFlow = ({ data }: Props) => {
onChangeDurationType={setDurationType}
/>
</Dialog.Content>
{sortedNames.map((name) => (
<div key={name.name}>
<span>{name.name}</span>
<span>{name.expiryDate?.date.toDateString()}</span>
</div>
))}
{status}
{error ? <Helper type="error">{error.message}</Helper> : null}
<EligibleForTokens>
<Typography fontVariant="largeBold">Eligible for {data.names.length} $ENS</Typography>
something something
<Link href="#" target="_blank" rel="noreferrer noopener">
<Typography color="greenPrimary" fontVariant="bodyBold">
{t('action.learnMore')}
</Typography>
<OutlinkSVG />
</Link>
</EligibleForTokens>
</>
)
}
Expand Down

0 comments on commit ed6719e

Please sign in to comment.