Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flatten FetchDrops query #566

Merged
merged 2 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 29 additions & 35 deletions components/Drop/DropCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
Stack,
Text,
} from '@chakra-ui/react'
import { BigNumber } from '@ethersproject/bignumber'
import { HiArrowNarrowRight } from '@react-icons/all-files/hi/HiArrowNarrowRight'
import { HiBadgeCheck } from '@react-icons/all-files/hi/HiBadgeCheck'
import Trans from 'next-translate/Trans'
Expand All @@ -25,21 +24,21 @@ import Link from '../Link/Link'
import Price from '../Price/Price'

type Props = {
collection: {
address: string
chainId: number
cover: string | null
image: string | null
name: string
deployer: {
drop: {
collection: {
address: string
name: string | null
verification: {
status: AccountVerificationStatus
} | null
chainId: number
cover: string | null
image: string | null
name: string
deployer: {
address: string
name: string | null
verification: {
status: AccountVerificationStatus
} | null
}
}
}
drop: {
startDate: Date
endDate: Date
unitPrice: string
Expand All @@ -48,17 +47,12 @@ type Props = {
symbol: string
image: string
}
supply: string | null
}
totalSupply: BigNumber | null
onCountdownEnd?: () => void
}

export default function DropCard({
collection,
drop,
totalSupply,
onCountdownEnd,
}: Props) {
export default function DropCard({ drop, onCountdownEnd }: Props) {
const { t } = useTranslation('components')
const status = useTimeStatus(drop)

Expand All @@ -71,7 +65,7 @@ export default function DropCard({
return (
<Box
as={Link}
href={`/collection/${collection.chainId}/${collection.address}/drop`}
href={`/collection/${drop.collection.chainId}/${drop.collection.address}/drop`}
borderWidth="1px"
borderRadius="2xl"
w="full"
Expand All @@ -90,10 +84,10 @@ export default function DropCard({
}}
bg="gray.100"
>
{collection.cover && (
{drop.collection.cover && (
<Image
src={collection.cover}
alt={collection.name}
src={drop.collection.cover}
alt={drop.collection.name}
fill
sizes="(min-width: 62em) 600px, 100vw"
objectFit="cover"
Expand Down Expand Up @@ -140,10 +134,10 @@ export default function DropCard({
mb={4}
bg="gray.200"
>
{collection.image && (
{drop.collection.image && (
<Image
src={collection.image}
alt={collection.name}
src={drop.collection.image}
alt={drop.collection.name}
fill
sizes="72px"
objectFit="cover"
Expand All @@ -154,34 +148,34 @@ export default function DropCard({
<Flex position="relative" justifyContent="space-between" gap={4} w="full">
<Flex flexDir="column" gap={1}>
<Heading variant="heading2" color="white" isTruncated>
{collection.name}
{drop.collection.name}
</Heading>

<Flex alignItems="center" gap={1.5}>
<Text variant="button2" color="white">
{t('drop.by', {
address:
collection.deployer.name ||
formatAddress(collection.deployer.address, 10),
drop.collection.deployer.name ||
formatAddress(drop.collection.deployer.address, 10),
})}
</Text>
{collection.deployer.verification?.status === 'VALIDATED' && (
{drop.collection.deployer.verification?.status === 'VALIDATED' && (
<Icon as={HiBadgeCheck} color="brand.500" h={4} w={4} />
)}
</Flex>

<Flex alignItems="center" gap={2}>
{totalSupply ? (
{drop.supply ? (
antho1404 marked this conversation as resolved.
Show resolved Hide resolved
<Text variant="caption" color="white">
<Trans
ns="components"
i18nKey="drop.supply.available"
values={{
count: totalSupply.toNumber(),
count: parseInt(drop.supply, 10),
}}
components={[
<>
{numbro(totalSupply).format({
{numbro(drop.supply).format({
thousandSeparated: true,
})}
</>,
Expand Down
163 changes: 33 additions & 130 deletions pages/drops.gql
Original file line number Diff line number Diff line change
@@ -1,110 +1,44 @@
query FetchDrops($now: Datetime!, $limit: Int!, $offset: Int!) {
inProgress: collections(
orderBy: [DROPS_MIN_START_DATE_ASC]
filter: {
dropsExist: true
drops: {
some: {
startDate: { lessThanOrEqualTo: $now }
endDate: { greaterThan: $now }
}
}
}
) {
nodes {
cover
image
fragment DropDetail on Drop {
id
startDate
endDate
unitPrice
supply
currency {
id
decimals
symbol
image
}
collection {
cover
image
address
chainId
name
deployer {
address
chainId
name
deployer {
address
name
username
verification {
status
}
}
drops(
orderBy: [START_DATE_ASC]
filter: {
startDate: { lessThanOrEqualTo: $now }
endDate: { greaterThan: $now }
}
first: 1
) {
nodes {
id
startDate
endDate
unitPrice
supply
currency {
id
decimals
symbol
image
}
}
username
verification {
status
}
}
}
upcoming: collections(
orderBy: [DROPS_MIN_START_DATE_ASC]
filter: {
dropsExist: true
drops: {
some: {
startDate: { greaterThan: $now }
endDate: { greaterThan: $now }
}
}
}
}

query FetchDrops($now: Datetime!, $limit: Int!, $offset: Int!) {
active: drops(
orderBy: [START_DATE_ASC]
filter: { endDate: { greaterThan: $now } }
) {
nodes {
cover
image
address
chainId
name
deployer {
address
name
username
verification {
status
}
}
drops(
orderBy: [START_DATE_ASC]
filter: {
startDate: { greaterThan: $now }
endDate: { greaterThan: $now }
}
first: 1
) {
nodes {
id
startDate
endDate
unitPrice
supply
currency {
id
decimals
symbol
image
}
}
}
...DropDetail
}
}
ended: collections(
orderBy: [DROPS_MIN_START_DATE_ASC]
filter: {
dropsExist: true
drops: { every: { endDate: { lessThanOrEqualTo: $now } } }
}
ended: drops(
orderBy: [START_DATE_DESC]
filter: { endDate: { lessThanOrEqualTo: $now } }
first: $limit
NicolasMahe marked this conversation as resolved.
Show resolved Hide resolved
offset: $offset
) {
Expand All @@ -113,38 +47,7 @@ query FetchDrops($now: Datetime!, $limit: Int!, $offset: Int!) {
hasPreviousPage
}
nodes {
cover
image
address
chainId
name
deployer {
address
name
username
verification {
status
}
}
allDrops: drops {
nodes {
supply
}
}
lastDrop: drops(orderBy: [START_DATE_DESC], first: 1) {
nodes {
id
startDate
endDate
unitPrice
currency {
id
decimals
symbol
image
}
}
}
...DropDetail
}
}
}
Loading
Loading