Skip to content

Commit

Permalink
Merge pull request #562 from liteflow-labs/chore/flatten-ownerships-f…
Browse files Browse the repository at this point in the history
…etchAsset-query

Flatten `ownerships` in `fetchAsset` query
  • Loading branch information
NicolasMahe authored Feb 2, 2024
2 parents 6c91ee7 + 7c9fe50 commit 96f5dfb
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 62 deletions.
6 changes: 5 additions & 1 deletion components/Token/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ const TokenHeader: FC<Props> = ({
{asset.name}
</Heading>
</Stack>
<TokenMetadata asset={asset} sales={asset.sales} />
<TokenMetadata
asset={asset}
sales={asset.sales}
ownerships={asset.ownerships}
/>
<SaleDetail
asset={asset}
sales={asset.sales}
Expand Down
38 changes: 19 additions & 19 deletions components/Token/Metadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,35 @@ export type Props = {
status: AccountVerificationStatus
} | null
}
ownerships: {
totalCount: number
nodes: {
ownerAddress: string
quantity: string
owner: {
address: string
name: string | null
image: string | null
verification: {
status: AccountVerificationStatus
} | null
}
}[]
}
}
ownerships: {
totalCount: number
nodes: {
ownerAddress: string
quantity: string
owner: {
address: string
name: string | null
image: string | null
verification: {
status: AccountVerificationStatus
} | null
}
}[]
}
sales: {
totalAvailableQuantitySum: string
}
}

const TokenMetadata: FC<Props> = ({ asset, sales }) => {
const TokenMetadata: FC<Props> = ({ asset, sales, ownerships }) => {
const { t } = useTranslation('components')

const isOpenCollection = asset.collection.mintType === 'PUBLIC'
const numberOfOwners = asset.ownerships.totalCount
const numberOfOwners = ownerships.totalCount
const saleSupply = BigNumber.from(sales.totalAvailableQuantitySum)
const totalSupply = BigNumber.from(asset.quantity)
const owners = asset.ownerships.nodes
const owners = ownerships.nodes

return (
<Flex wrap="wrap" rowGap={6} columnGap={8}>
Expand All @@ -81,7 +81,7 @@ const TokenMetadata: FC<Props> = ({ asset, sales }) => {
<Heading as="h5" variant="heading3" color="gray.500">
{t('token.metadata.owners')}
</Heading>
<OwnersModal asset={asset} />
<OwnersModal asset={asset} ownerships={ownerships} />
</Stack>
)}
{asset.collection.standard === 'ERC721' && (
Expand Down
39 changes: 18 additions & 21 deletions components/Token/Owners/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,27 @@ export type Props = {
chainId: number
collectionAddress: string
tokenId: string
ownerships: {
totalCount: number
nodes: {
ownerAddress: string
quantity: string
owner: {
address: string
name: string | null
image: string | null
verification: {
status: AccountVerificationStatus
} | null
}
}[]
}
}
ownerships: {
totalCount: number
nodes: {
ownerAddress: string
quantity: string
owner: {
address: string
name: string | null
image: string | null
verification: {
status: AccountVerificationStatus
} | null
}
}[]
}
}

const OwnerPaginationLimit = 8

const OwnersModal: FC<Props> = ({ asset }) => {
const OwnersModal: FC<Props> = ({ asset, ownerships }) => {
const { t } = useTranslation('components')
const { isOpen, onOpen, onClose } = useDisclosure()
const [page, setPage] = useState(1)
Expand All @@ -76,10 +76,7 @@ const OwnersModal: FC<Props> = ({ asset }) => {

return (
<>
<OwnersModalActivator
ownerships={asset.ownerships}
onClick={openOwners}
/>
<OwnersModalActivator ownerships={ownerships} onClick={openOwners} />
<Modal
isOpen={isOpen}
onClose={closeOwners}
Expand All @@ -103,7 +100,7 @@ const OwnersModal: FC<Props> = ({ asset }) => {
px={2.5}
>
<Text as="span" variant="caption" color="brand.500">
{asset.ownerships.totalCount}
{ownerships.totalCount}
</Text>
</Flex>
</Flex>
Expand Down
43 changes: 24 additions & 19 deletions pages/tokens/[id]/index.gql
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,30 @@ query FetchAsset(
owned: ownership(ownerAddress: $address) {
quantity
}
ownerships(
orderBy: [
QUANTITY_DESC
ACCOUNT_BY_OWNER_ADDRESS__NAME_ASC
OWNER_ADDRESS_ASC
]
first: 5
) {
totalCount
nodes {
ownerAddress
quantity
owner {
address
name
image
verification {
status
}
}
ownerships(
filter: {
chainId: { equalTo: $chainId }
collectionAddress: { equalTo: $collectionAddress }
tokenId: { equalTo: $tokenId }
}
orderBy: [
QUANTITY_DESC
ACCOUNT_BY_OWNER_ADDRESS__NAME_ASC
OWNER_ADDRESS_ASC
]
first: 5
) {
totalCount
nodes {
ownerAddress
quantity
owner {
address
name
image
verification {
status
}
}
}
Expand Down
9 changes: 7 additions & 2 deletions pages/tokens/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const DetailPage: NextPage<Props> = ({ now: nowProp }) => {
const asset = data?.asset
const sales = data?.sales
const bids = data?.bids
const ownerships = data?.ownerships

const media = useDetectAssetMedia(asset)

Expand Down Expand Up @@ -227,10 +228,14 @@ const DetailPage: NextPage<Props> = ({ now: nowProp }) => {
)}
</Flex>

{!asset || !sales ? (
{!asset || !sales || !ownerships ? (
<SkeletonProperty items={3} />
) : (
<TokenMetadata asset={asset} sales={sales} />
<TokenMetadata
asset={asset}
sales={sales}
ownerships={ownerships}
/>
)}
{!asset || !sales || !data?.currencies?.nodes ? (
<>
Expand Down

0 comments on commit 96f5dfb

Please sign in to comment.