diff --git a/components/Cart/ItemSummary.tsx b/components/Cart/ItemSummary.tsx index b5d82b79..5d15ad1c 100644 --- a/components/Cart/ItemSummary.tsx +++ b/components/Cart/ItemSummary.tsx @@ -29,7 +29,7 @@ const CartItemSummary: FC = ({ chainId, cartItems }) => { const orderedCartItems = useOrderByKey( offerIds, - data?.offerOpenSales?.nodes, + data?.listings?.nodes, (offers) => offers.id, ) diff --git a/components/Cart/Step/Selection.gql b/components/Cart/Step/Selection.gql index ca36937c..7987ac60 100644 --- a/components/Cart/Step/Selection.gql +++ b/components/Cart/Step/Selection.gql @@ -1,5 +1,5 @@ query FetchCartItems($offerIds: [UUID!]!) { - offerOpenSales(filter: { id: { in: $offerIds } }) { + listings(condition: { ids: $offerIds, status: [ACTIVE, EXPIRED] }) { nodes { id type diff --git a/components/Cart/Step/Selection.tsx b/components/Cart/Step/Selection.tsx index 24d8a555..557bdd87 100644 --- a/components/Cart/Step/Selection.tsx +++ b/components/Cart/Step/Selection.tsx @@ -53,14 +53,14 @@ const CartStepSelection: FC = ({ onSubmit }) => { const offers = useMemo( () => - (data?.offerOpenSales?.nodes || []).reduce( + (data?.listings?.nodes || []).reduce( (prev, x) => ({ ...prev, [x.id]: x }), {} as Record< string, - NonNullable['nodes'][number] + NonNullable['nodes'][number] >, ), - [data?.offerOpenSales?.nodes], + [data?.listings?.nodes], ) const nonExpiredSelectedCartItems = useMemo( diff --git a/components/Filter/FilterBy/Collection.tsx b/components/Filter/FilterBy/Collection.tsx index b5b1e2f7..32a84d0c 100644 --- a/components/Filter/FilterBy/Collection.tsx +++ b/components/Filter/FilterBy/Collection.tsx @@ -17,11 +17,7 @@ import useTranslation from 'next-translate/useTranslation' import { FC, useCallback, useMemo, useState } from 'react' import { UseFormReturn } from 'react-hook-form' import { concatToQuery } from '../../../concat' -import { - CollectionFilter, - StringFilter, - useSearchCollectionQuery, -} from '../../../graphql' +import { useSearchCollectionQuery } from '../../../graphql' import { Filter } from '../../../hooks/useAssetFilterFromQuery' import { formatError } from '../../../utils' import CollectionListItem from '../../Collection/ListItem' @@ -53,14 +49,8 @@ const FilterByCollection: FC = ({ variables: { offset: 0, // the offset change must be done when calling the fetchMore function to concat queries' results limit: PAGINATION_LIMIT, - filter: { - name: { - includesInsensitive: filterResult.collectionSearch || '', - } as StringFilter, - ...(filterResult.chains.length - ? { chainId: { in: filterResult.chains } } - : {}), - } as CollectionFilter, + chainIds: filterResult.chains, + search: filterResult.collectionSearch || null, }, notifyOnNetworkStatusChange: true, }) diff --git a/components/Filter/FilterBy/Trait.tsx b/components/Filter/FilterBy/Trait.tsx index 782df787..f2d80725 100644 --- a/components/Filter/FilterBy/Trait.tsx +++ b/components/Filter/FilterBy/Trait.tsx @@ -20,11 +20,7 @@ import SearchInput from 'components/SearchInput' import useTranslation from 'next-translate/useTranslation' import { FC, useCallback, useState } from 'react' import { UseFormReturn } from 'react-hook-form' -import { - CollectionTraitFilter, - StringFilter, - useFetchCollectionTraitsQuery, -} from '../../../graphql' +import { useFetchCollectionTraitsQuery } from '../../../graphql' import { Filter } from '../../../hooks/useAssetFilterFromQuery' import { formatError } from '../../../utils' @@ -56,11 +52,7 @@ const FilterByTrait: FC = ({ chainId: collection.chainId, offset: 0, // the offset change must be done when calling the fetchMore function to concat queries' results limit: PAGINATION_LIMIT, - filter: { - type: { - includesInsensitive: filterResult.propertySearch || '', - } as StringFilter, - } as CollectionTraitFilter, + search: filterResult.propertySearch || null, }, notifyOnNetworkStatusChange: true, }) @@ -199,7 +191,7 @@ const FilterByTrait: FC = ({ defaultValue={ filterResult?.traits?.find( (trait) => trait.type === type, - )?.values + )?.values || undefined } > diff --git a/components/History/HistoryList.gql b/components/History/HistoryList.gql index ca11dcbe..32aa3866 100644 --- a/components/History/HistoryList.gql +++ b/components/History/HistoryList.gql @@ -4,14 +4,14 @@ query FetchAssetHistory( $tokenId: String! $limit: Int! $offset: Int! - $filter: [AssetHistoryAction!] + $actions: [AssetHistoryAction!] ) { assetHistories( - filter: { - chainId: { equalTo: $chainId } - collectionAddress: { equalTo: $collectionAddress } - tokenId: { equalTo: $tokenId } - action: { in: $filter } + condition: { + chainId: $chainId + collectionAddress: $collectionAddress + tokenId: $tokenId + actions: $actions } orderBy: DATE_DESC first: $limit diff --git a/components/History/HistoryList.tsx b/components/History/HistoryList.tsx index 72ee147e..93d4ef13 100644 --- a/components/History/HistoryList.tsx +++ b/components/History/HistoryList.tsx @@ -54,7 +54,7 @@ const HistoryList: FC = ({ chainId, collectionAddress, tokenId }) => { tokenId, limit: LIMIT, offset, - filter, + actions: filter, }, }) const histories = historyData?.assetHistories?.nodes diff --git a/components/HomeSection/Assets.gql b/components/HomeSection/Assets.gql index 66d4d747..ae9b187d 100644 --- a/components/HomeSection/Assets.gql +++ b/components/HomeSection/Assets.gql @@ -1,9 +1,5 @@ query FetchDefaultAssetIds($limit: Int!) { - assets( - filter: { quantity: { greaterThan: "0" } } - orderBy: CREATED_AT_DESC - first: $limit - ) { + assets(orderBy: CREATED_AT_DESC, first: $limit) { nodes { chainId collectionAddress @@ -12,11 +8,12 @@ query FetchDefaultAssetIds($limit: Int!) { } } -query FetchAssets($limit: Int!, $filter: [AssetFilter!]!, $address: Address) { - assets( - filter: { quantity: { greaterThan: "0" }, and: $filter } - first: $limit - ) { +query FetchAssets( + $limit: Int! + $ids: [AssetIdsCondition!]! + $address: Address +) { + assets(condition: { ids: $ids }, first: $limit) { nodes { chainId collectionAddress diff --git a/components/HomeSection/Assets.tsx b/components/HomeSection/Assets.tsx index c79d4686..28327fdb 100644 --- a/components/HomeSection/Assets.tsx +++ b/components/HomeSection/Assets.tsx @@ -13,7 +13,6 @@ import useTranslation from 'next-translate/useTranslation' import { FC, useMemo } from 'react' import invariant from 'ts-invariant' import { - AssetFilter, useFetchAssetsQuery, useFetchDefaultAssetIdsQuery, } from '../../graphql' @@ -67,23 +66,21 @@ const AssetsHomeSection: FC = ({ date }) => { const assetsQuery = useFetchAssetsQuery({ variables: { limit: PAGINATION_LIMIT, - filter: { - or: (assetIds || []) - .map((x) => x.split('-')) - .map(([chainId, collectionAddress, tokenId]) => { - invariant( - chainId !== undefined && - collectionAddress !== undefined && - tokenId !== undefined, - 'invalid collection', - ) - return { - collectionAddress: { equalTo: collectionAddress.toLowerCase() }, - chainId: { equalTo: parseInt(chainId, 10) }, - tokenId: { equalTo: tokenId }, - } - }), - } as AssetFilter, + ids: (assetIds || []) + .map((x) => x.split('-')) + .map(([chainId, collectionAddress, tokenId]) => { + invariant( + chainId !== undefined && + collectionAddress !== undefined && + tokenId !== undefined, + 'invalid collection', + ) + return { + collectionAddress: collectionAddress.toLowerCase(), + chainId: parseInt(chainId, 10), + tokenId: tokenId, + } + }), address: address || '', }, skip: assetIds === undefined, diff --git a/components/HomeSection/Collections.gql b/components/HomeSection/Collections.gql index da8b65e4..c9d6769d 100644 --- a/components/HomeSection/Collections.gql +++ b/components/HomeSection/Collections.gql @@ -1,5 +1,9 @@ -query FetchCollections($filter: CollectionFilter!, $limit: Int!) { - collections(filter: $filter, first: $limit, orderBy: TOTAL_VOLUME_DESC) { +query FetchCollections($ids: [CollectionIdsCondition!]!, $limit: Int!) { + collections( + condition: { ids: $ids } + first: $limit + orderBy: TOTAL_VOLUME_DESC + ) { nodes { chainId address diff --git a/components/HomeSection/Collections.tsx b/components/HomeSection/Collections.tsx index d259c570..6e0739bd 100644 --- a/components/HomeSection/Collections.tsx +++ b/components/HomeSection/Collections.tsx @@ -3,11 +3,7 @@ import { useOrderByKey } from 'hooks/useOrderByKey' import useTranslation from 'next-translate/useTranslation' import { FC } from 'react' import invariant from 'ts-invariant' -import { - CollectionFilter, - FetchCollectionsQuery, - useFetchCollectionsQuery, -} from '../../graphql' +import { FetchCollectionsQuery, useFetchCollectionsQuery } from '../../graphql' import useEnvironment from '../../hooks/useEnvironment' import useHandleQueryError from '../../hooks/useHandleQueryError' import HomeGridSection from './Grid' @@ -19,17 +15,15 @@ const CollectionsHomeSection: FC = () => { const { t } = useTranslation('templates') const collectionsQuery = useFetchCollectionsQuery({ variables: { - filter: { - or: HOME_COLLECTIONS.map((x) => x.split('-')).map( - ([chainId, collectionAddress]) => { - invariant(chainId && collectionAddress, 'invalid collection') - return { - address: { equalTo: collectionAddress.toLowerCase() }, - chainId: { equalTo: parseInt(chainId, 10) }, - } - }, - ), - } as CollectionFilter, + ids: HOME_COLLECTIONS.map((x) => x.split('-')).map( + ([chainId, collectionAddress]) => { + invariant(chainId && collectionAddress, 'invalid collection') + return { + address: collectionAddress.toLowerCase(), + chainId: parseInt(chainId, 10), + } + }, + ), limit: PAGINATION_LIMIT, }, skip: !HOME_COLLECTIONS.length, diff --git a/components/HomeSection/Featured.tsx b/components/HomeSection/Featured.tsx index 23dc9902..ee0d8177 100644 --- a/components/HomeSection/Featured.tsx +++ b/components/HomeSection/Featured.tsx @@ -5,11 +5,7 @@ import useEnvironment from '../../hooks/useEnvironment' import Slider from '../Slider/Slider' import TokenHeader from './FeaturedToken' -type Props = { - date: Date -} - -const FeaturedHomeSection: FC = ({ date }) => { +const FeaturedHomeSection: FC = () => { const { FEATURED_TOKEN } = useEnvironment() const featuredAssets = useMemo( @@ -28,12 +24,11 @@ const FeaturedHomeSection: FC = ({ date }) => { chainId={parseInt(chainId, 10)} collectionAddress={collectionAddress.toLowerCase()} tokenId={tokenId} - date={date} /> ) }, ), - [FEATURED_TOKEN, date], + [FEATURED_TOKEN], ) if (FEATURED_TOKEN.length === 0) return null diff --git a/components/HomeSection/FeaturedToken.gql b/components/HomeSection/FeaturedToken.gql index 1b809a1a..95b7e208 100644 --- a/components/HomeSection/FeaturedToken.gql +++ b/components/HomeSection/FeaturedToken.gql @@ -2,7 +2,6 @@ query FetchFeaturedToken( $chainId: Int! $collectionAddress: Address! $tokenId: String! - $now: Datetime! $address: Address ) { asset( @@ -50,10 +49,10 @@ query FetchFeaturedToken( } } ownerships( - filter: { - chainId: { equalTo: $chainId } - collectionAddress: { equalTo: $collectionAddress } - tokenId: { equalTo: $tokenId } + condition: { + chainId: $chainId + collectionAddress: $collectionAddress + tokenId: $tokenId } orderBy: [ QUANTITY_DESC @@ -76,13 +75,13 @@ query FetchFeaturedToken( } } } - sales: offerOpenSales( + sales: listings( orderBy: [UNIT_PRICE_IN_REF_ASC, CREATED_AT_ASC] - filter: { - chainId: { equalTo: $chainId } - collectionAddress: { equalTo: $collectionAddress } - tokenId: { equalTo: $tokenId } - expiredAt: { greaterThan: $now } + condition: { + chainId: $chainId + collectionAddress: $collectionAddress + tokenId: $tokenId + status: ACTIVE } # TODO: implement pagination. when implementing pagination, find a way to get availableQuantity of all sales ) { nodes { @@ -112,9 +111,9 @@ query FetchFeaturedToken( } currencies( orderBy: CREATED_AT_ASC - filter: { - chainId: { equalTo: $chainId } - address: { isNull: false } # keep only non-native currency. Cannot create bid with native currency. + condition: { + chainId: $chainId + onlyToken: true # keep only non-native currency. Cannot create bid with native currency. } ) { nodes { diff --git a/components/HomeSection/FeaturedToken.tsx b/components/HomeSection/FeaturedToken.tsx index bf451c6c..61219317 100644 --- a/components/HomeSection/FeaturedToken.tsx +++ b/components/HomeSection/FeaturedToken.tsx @@ -20,18 +20,12 @@ import TokenMedia from '../Token/Media' import TokenMetadata from '../Token/Metadata' export type Props = { - date: Date chainId: number collectionAddress: string tokenId: string } -const FeaturedToken: FC = ({ - date, - chainId, - collectionAddress, - tokenId, -}) => { +const FeaturedToken: FC = ({ chainId, collectionAddress, tokenId }) => { const { address } = useAccount() const fetchFeaturedTokenQuery = useFetchFeaturedTokenQuery({ @@ -39,7 +33,6 @@ const FeaturedToken: FC = ({ chainId, collectionAddress, tokenId, - now: date, address: address || '', }, }) @@ -52,9 +45,7 @@ const FeaturedToken: FC = ({ const media = useDetectAssetMedia(asset) const refresh = useCallback(async () => { - await fetchFeaturedTokenQuery.refetch({ - now: new Date(), - }) + await fetchFeaturedTokenQuery.refetch() }, [fetchFeaturedTokenQuery]) useCart({ onCheckout: fetchFeaturedTokenQuery.refetch }) diff --git a/components/HomeSection/Users.gql b/components/HomeSection/Users.gql index dc244e35..5e077612 100644 --- a/components/HomeSection/Users.gql +++ b/components/HomeSection/Users.gql @@ -1,5 +1,5 @@ query FetchUsers($limit: Int!, $userIds: [Address!]!) { - users: accounts(filter: { address: { in: $userIds } }, first: $limit) { + users: accounts(condition: { addresses: $userIds }, first: $limit) { nodes { username address diff --git a/components/Offer/Form/Checkout.tsx b/components/Offer/Form/Checkout.tsx index 88b2f95c..4c12a7b2 100644 --- a/components/Offer/Form/Checkout.tsx +++ b/components/Offer/Form/Checkout.tsx @@ -41,7 +41,7 @@ type FormData = { } type Props = { - offer: NonNullable + offer: NonNullable onPurchased: () => void multiple?: boolean } diff --git a/hooks/useAssetFilterFromQuery.ts b/hooks/useAssetFilterFromQuery.ts index 0c9d8d21..9366c87b 100644 --- a/hooks/useAssetFilterFromQuery.ts +++ b/hooks/useAssetFilterFromQuery.ts @@ -2,21 +2,15 @@ import { useRouter } from 'next/router' import type { ParsedUrlQuery } from 'querystring' import invariant from 'ts-invariant' import { - AssetFilter, - AssetToManyOfferFilter, - IntFilter, - OfferFilter, - Uint256Filter, + AssetCondition, + AssetListingsCondition, + AssetOpenOffersCondition, + AssetTraitsCondition, } from '../graphql' import { parseBigNumber } from './useParseBigNumber' import useQueryParamMulti from './useQueryParamMulti' import useQueryParamSingle from './useQueryParamSingle' -type TraitFilter = { - type: string - values: string[] -} - export type Filter = { chains: number[] search: string | null @@ -28,7 +22,7 @@ export type Filter = { id: string decimals: number } | null - traits: TraitFilter[] + traits: AssetTraitsCondition[] collectionSearch?: string propertySearch?: string } @@ -38,103 +32,10 @@ export enum OfferFilterType { bids = 'bids', } -const chainFilter = (chains: number[]): AssetFilter => - ({ - chainId: { in: chains } as IntFilter, - }) as AssetFilter - -const searchFilter = (search: string): AssetFilter => - ({ - or: [ - { name: { includesInsensitive: search } } as AssetFilter, - { description: { includesInsensitive: search } } as AssetFilter, - { creatorAddress: { includesInsensitive: search } } as AssetFilter, - ], - }) as AssetFilter - -const traitFilter = (traits: TraitFilter[]): AssetFilter => - ({ - and: traits.map(({ type, values }) => ({ - traits: { - some: { - type: { equalTo: type }, - value: { in: values }, - }, - }, - })), - }) as AssetFilter - -const collectionFilter = (collection: string): AssetFilter => { - const [chainId, address] = collection.split('-') - return { - chainId: { equalTo: chainId && parseInt(chainId, 10) }, - collectionAddress: { equalTo: address }, - } as AssetFilter -} - -const minPriceFilter = ( - minPrice: number, - currency: { id: string; decimals: number }, - date: Date, -): AssetFilter => - ({ - sales: { - some: { - expiredAt: { greaterThan: date }, - currencyId: { equalTo: currency.id }, - unitPrice: { - greaterThanOrEqualTo: parseBigNumber( - minPrice.toString(), - currency.decimals, - ).toString(), - } as Uint256Filter, - } as OfferFilter, - } as AssetToManyOfferFilter, - }) as AssetFilter - -const maxPriceFilter = ( - maxPrice: number, - currency: { id: string; decimals: number }, - date: Date, -): AssetFilter => - ({ - sales: { - some: { - expiredAt: { greaterThan: date }, - currencyId: { equalTo: currency.id }, - unitPrice: { - lessThanOrEqualTo: parseBigNumber( - maxPrice.toString(), - currency.decimals, - ).toString(), - } as Uint256Filter, - } as OfferFilter, - } as AssetToManyOfferFilter, - }) as AssetFilter - -const offersFilter = (offers: OfferFilterType, date: Date): AssetFilter => { - if (offers === OfferFilterType.bids) { - return { - bidsExist: true, - bids: { some: { expiredAt: { greaterThan: date } } }, - } as AssetFilter - } - if (offers === OfferFilterType.fixed) { - return { - sales: { - some: { - expiredAt: { greaterThan: date }, - }, - }, - } as AssetFilter - } - invariant(false, 'Invalid offer filter') -} - export const extractTraitsFromQuery = ( query: ParsedUrlQuery, -): TraitFilter[] => { - const traits: TraitFilter[] = [] +): AssetTraitsCondition[] => { + const traits: AssetTraitsCondition[] = [] for (const typeQuery in query) { const typeMatch = typeQuery.match(/^traits\[(.+)\]$/) if (!typeMatch) continue @@ -150,25 +51,60 @@ export const extractTraitsFromQuery = ( return traits } -export const convertFilterToAssetFilter = ( - filter: Filter, - now: Date, -): AssetFilter[] => { - const queryFilter = [] +export const convertFilterToAssetFilter = (filter: Filter): AssetCondition => { + const queryFilter: Partial = {} + if (filter.chains && filter.chains.length > 0) - queryFilter.push(chainFilter(filter.chains)) - if (filter.search) queryFilter.push(searchFilter(filter.search)) - if (filter.collection) queryFilter.push(collectionFilter(filter.collection)) + queryFilter.chainIds = filter.chains + + if (filter.search) queryFilter.search = filter.search + + if (filter.traits && filter.traits.length > 0) + queryFilter.traits = filter.traits + + if (filter.collection) { + const [chainId, collectionAddress] = filter.collection.split('-') + if (chainId && collectionAddress) { + queryFilter.chainId = parseInt(chainId, 10) + queryFilter.collectionAddress = collectionAddress + } + } + if (filter.currency) { - if (filter.minPrice) - queryFilter.push(minPriceFilter(filter.minPrice, filter.currency, now)) - if (filter.maxPrice) - queryFilter.push(maxPriceFilter(filter.maxPrice, filter.currency, now)) + queryFilter.listings = { + currencyId: filter.currency.id, + maxUnitPrice: filter.maxPrice + ? parseBigNumber( + filter.maxPrice.toString(), + filter.currency.decimals, + ).toString() + : undefined, + minUnitPrice: filter.minPrice + ? parseBigNumber( + filter.minPrice.toString(), + filter.currency.decimals, + ).toString() + : undefined, + status: 'ACTIVE' as const, + } as AssetListingsCondition // force type to avoid putting other params with null value. codegen issue. } - if (filter.offers) queryFilter.push(offersFilter(filter.offers, now)) - if (filter.traits && filter.traits.length > 0) - queryFilter.push(traitFilter(filter.traits)) - return queryFilter + + if ( + filter.offers === OfferFilterType.fixed && + !queryFilter.listings // If we already have a listing filter, we don't need to add the listing.status filter because it's already set + ) { + queryFilter.listings = { + status: 'ACTIVE' as const, + } as AssetListingsCondition // force type to avoid putting other params with null value. codegen issue. + } + + if (filter.offers === OfferFilterType.bids) { + queryFilter.openOffers = { + status: 'ACTIVE' as const, + } as AssetOpenOffersCondition // force type to avoid putting other params with null value. codegen issue. + } + + return queryFilter as AssetCondition } const parseToFloat = (value?: string) => (value ? parseFloat(value) : null) diff --git a/hooks/useCollectionFilterFromQuery.ts b/hooks/useCollectionFilterFromQuery.ts index 549088e4..0ed7100e 100644 --- a/hooks/useCollectionFilterFromQuery.ts +++ b/hooks/useCollectionFilterFromQuery.ts @@ -1,5 +1,5 @@ import invariant from 'ts-invariant' -import { CollectionFilter, IntFilter } from '../graphql' +import { CollectionCondition } from '../graphql' import useQueryParamMulti from './useQueryParamMulti' import useQueryParamSingle from './useQueryParamSingle' @@ -8,28 +8,17 @@ export type Filter = { search: string | null } -const chainFilter = (chains: number[]): CollectionFilter => - ({ - chainId: { in: chains } as IntFilter, - }) as CollectionFilter - -const searchFilter = (search: string): CollectionFilter => - ({ - or: [ - { name: { includesInsensitive: search } } as CollectionFilter, - { address: { includesInsensitive: search } } as CollectionFilter, - { description: { includesInsensitive: search } } as CollectionFilter, - ], - }) as CollectionFilter - export const convertFilterToCollectionFilter = ( filter: Filter, -): CollectionFilter[] => { - const queryFilter = [] +): CollectionCondition => { + const queryFilter: Partial = {} + if (filter.chains && filter.chains.length > 0) - queryFilter.push(chainFilter(filter.chains)) - if (filter.search) queryFilter.push(searchFilter(filter.search)) - return queryFilter + queryFilter.chainIds = filter.chains + + if (filter.search) queryFilter.search = filter.search + + return queryFilter as CollectionCondition } const parseToInt = (value?: string): number => { diff --git a/hooks/useFetchCollectionTraits.gql b/hooks/useFetchCollectionTraits.gql index a37ab5c6..183ca4c5 100644 --- a/hooks/useFetchCollectionTraits.gql +++ b/hooks/useFetchCollectionTraits.gql @@ -1,17 +1,17 @@ query FetchCollectionTraits( $chainId: Int! $address: Address! - $filter: [CollectionTraitFilter!] + $search: String $limit: Int! $offset: Int! ) { collectionTraits( orderBy: [TYPE_ASC] first: $limit - filter: { - chainId: { equalTo: $chainId } - collectionAddress: { equalTo: $address } - and: $filter + condition: { + chainId: $chainId + collectionAddress: $address + search: $search } offset: $offset ) { diff --git a/hooks/useFetchOwners.gql b/hooks/useFetchOwners.gql index 0e7a6f9c..1e9ce8a1 100644 --- a/hooks/useFetchOwners.gql +++ b/hooks/useFetchOwners.gql @@ -6,10 +6,10 @@ query FetchOwners( $limit: Int! ) { ownerships( - filter: { - chainId: { equalTo: $chainId } - collectionAddress: { equalTo: $collectionAddress } - tokenId: { equalTo: $tokenId } + condition: { + chainId: $chainId + collectionAddress: $collectionAddress + tokenId: $tokenId } offset: $offset first: $limit diff --git a/hooks/useSearchCollection.gql b/hooks/useSearchCollection.gql index c5b60e3c..ebf92872 100644 --- a/hooks/useSearchCollection.gql +++ b/hooks/useSearchCollection.gql @@ -1,12 +1,13 @@ query SearchCollection( - $filter: CollectionFilter! + $chainIds: [Int!] + $search: String $limit: Int! $offset: Int! ) { collections( orderBy: TOTAL_VOLUME_DESC first: $limit - filter: $filter + condition: { chainIds: $chainIds, search: $search } offset: $offset ) { pageInfo { diff --git a/layouts/navbar.gql b/layouts/navbar.gql index 5773837e..be134ffd 100644 --- a/layouts/navbar.gql +++ b/layouts/navbar.gql @@ -5,10 +5,7 @@ query NavbarAccount($account: Address!, $lastNotification: Datetime!) { image } notifications( - filter: { - accountAddress: { equalTo: $account } - createdAt: { greaterThan: $lastNotification } - } + condition: { after: $lastNotification } includeWhenCollectionDeleted: YES includeWhenTradeDeleted: YES ) { diff --git a/package-lock.json b/package-lock.json index 77a4f420..2ba667cc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -55,7 +55,7 @@ "@graphql-codegen/typescript-react-apollo": "^4.1.0", "@graphql-eslint/eslint-plugin": "^3.20.1", "@next/bundle-analyzer": "^14.0.4", - "@nft/api-graphql": "^1.0.0-beta.52-prerelease-7", + "@nft/api-graphql": "^1.0.0-beta.52", "@types/nodemailer": "^6.4.14", "@types/nprogress": "^0.2.3", "@types/react": "^18.2.48", @@ -6724,9 +6724,9 @@ } }, "node_modules/@nft/api-graphql": { - "version": "1.0.0-beta.52-prerelease-7", - "resolved": "https://registry.npmjs.org/@nft/api-graphql/-/api-graphql-1.0.0-beta.52-prerelease-7.tgz", - "integrity": "sha512-H2tFbcBw3MYIhwMj4eiruP6UpDGU/P8EWgSkGMGR+te6WU4fDdwA7zXM6AMXkwn2kiXHwXpVb/4D0eplAZuqHQ==", + "version": "1.0.0-beta.52", + "resolved": "https://registry.npmjs.org/@nft/api-graphql/-/api-graphql-1.0.0-beta.52.tgz", + "integrity": "sha512-YX2AgQo2jeyFO/Rg+7E5E1iqoM8uzZgsgm+Tq/9zWbTjhad5aY9pxKsdH8zuZfhR6NDCpsHypOjEX1mScsoCLQ==", "dev": true }, "node_modules/@nft/chat": { @@ -26699,9 +26699,9 @@ "optional": true }, "@nft/api-graphql": { - "version": "1.0.0-beta.52-prerelease-7", - "resolved": "https://registry.npmjs.org/@nft/api-graphql/-/api-graphql-1.0.0-beta.52-prerelease-7.tgz", - "integrity": "sha512-H2tFbcBw3MYIhwMj4eiruP6UpDGU/P8EWgSkGMGR+te6WU4fDdwA7zXM6AMXkwn2kiXHwXpVb/4D0eplAZuqHQ==", + "version": "1.0.0-beta.52", + "resolved": "https://registry.npmjs.org/@nft/api-graphql/-/api-graphql-1.0.0-beta.52.tgz", + "integrity": "sha512-YX2AgQo2jeyFO/Rg+7E5E1iqoM8uzZgsgm+Tq/9zWbTjhad5aY9pxKsdH8zuZfhR6NDCpsHypOjEX1mScsoCLQ==", "dev": true }, "@nft/chat": { diff --git a/package.json b/package.json index 81707e80..b17ed23e 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "@graphql-codegen/typescript-react-apollo": "^4.1.0", "@graphql-eslint/eslint-plugin": "^3.20.1", "@next/bundle-analyzer": "^14.0.4", - "@nft/api-graphql": "^1.0.0-beta.52-prerelease-7", + "@nft/api-graphql": "^1.0.0-beta.52", "@types/nodemailer": "^6.4.14", "@types/nprogress": "^0.2.3", "@types/react": "^18.2.48", diff --git a/pages/checkout/[id].gql b/pages/checkout/[id].gql index bd19c421..35dee3d8 100644 --- a/pages/checkout/[id].gql +++ b/pages/checkout/[id].gql @@ -1,5 +1,5 @@ query Checkout($id: UUID!, $address: Address) { - offer(id: $id) { + listing(id: $id) { id type asset { diff --git a/pages/checkout/[id].tsx b/pages/checkout/[id].tsx index c252b12a..7216cf12 100644 --- a/pages/checkout/[id].tsx +++ b/pages/checkout/[id].tsx @@ -42,7 +42,7 @@ const CheckoutPage: NextPage = () => { address: address || '', }, }) - const offer = offerData?.offer + const offer = offerData?.listing const asset = offer?.asset const priceUnit = useMemo( diff --git a/pages/collection/[chainId]/[id]/drop.gql b/pages/collection/[chainId]/[id]/drop.gql index 32bad145..411dbdf0 100644 --- a/pages/collection/[chainId]/[id]/drop.gql +++ b/pages/collection/[chainId]/[id]/drop.gql @@ -26,10 +26,7 @@ query FetchCollectionDrops( $chainId: Int! ) { drops( - filter: { - chainId: { equalTo: $chainId } - collectionAddress: { equalTo: $address } - } + condition: { chainId: $chainId, collectionAddress: $address } orderBy: START_DATE_ASC ) { nodes { diff --git a/pages/collection/[chainId]/[id]/index.gql b/pages/collection/[chainId]/[id]/index.gql index e7f4c4f8..3aa46e17 100644 --- a/pages/collection/[chainId]/[id]/index.gql +++ b/pages/collection/[chainId]/[id]/index.gql @@ -52,18 +52,11 @@ query FetchCollectionAssets( $currentAccount: Address! $offset: Int! $limit: Int! - $chainId: Int! - $collectionAddress: Address! + $condition: AssetCondition! $orderBy: [AssetsOrderBy!] - $filter: [AssetFilter!] ) { assets( - filter: { - quantity: { greaterThan: "0" } - chainId: { equalTo: $chainId } - collectionAddress: { equalTo: $collectionAddress } - and: $filter - } + condition: $condition orderBy: $orderBy first: $limit offset: $offset diff --git a/pages/collection/[chainId]/[id]/index.tsx b/pages/collection/[chainId]/[id]/index.tsx index 24531346..cd4063e1 100644 --- a/pages/collection/[chainId]/[id]/index.tsx +++ b/pages/collection/[chainId]/[id]/index.tsx @@ -14,7 +14,7 @@ import { } from '@chakra-ui/react' import useTranslation from 'next-translate/useTranslation' import { useRouter } from 'next/router' -import { FC, useCallback, useMemo } from 'react' +import { FC, useCallback } from 'react' import CollectionHeader from '../../../../components/Collection/CollectionHeader' import CollectionHeaderSkeleton from '../../../../components/Collection/CollectionHeaderSkeleton' import CollectionMetrics from '../../../../components/Collection/CollectionMetrics' @@ -51,11 +51,7 @@ import LargeLayout from '../../../../layouts/large' import { removeEmptyFromObject } from '../../../../utils' import Error from '../../../_error' -type Props = { - now: string -} - -const CollectionPage: FC = ({ now }) => { +const CollectionPage: FC = () => { const { PAGINATION_LIMIT } = useEnvironment() const { query, push, pathname } = useRouter() const chainId = useRequiredQueryParamSingle('chainId', { @@ -67,7 +63,6 @@ const CollectionPage: FC = ({ now }) => { { fallback: 'md' }, ) const { t } = useTranslation('templates') - const date = useMemo(() => new Date(now), [now]) const { address } = useAccount() const { data: collectionData } = useFetchCollectionDetailsQuery({ variables: { @@ -90,13 +85,15 @@ const CollectionPage: FC = ({ now }) => { const filter = useAssetFilterFromQuery() const { data: assetData } = useFetchCollectionAssetsQuery({ variables: { - collectionAddress, currentAccount: address || '', limit, offset, orderBy, - chainId: chainId, - filter: convertFilterToAssetFilter(filter, date), + condition: { + ...convertFilterToAssetFilter(filter), + chainId, + collectionAddress, + }, }, }) const assets = assetData?.assets?.nodes diff --git a/pages/create/index.gql b/pages/create/index.gql index 18e22b04..1f10f871 100644 --- a/pages/create/index.gql +++ b/pages/create/index.gql @@ -1,6 +1,6 @@ query FetchCollectionsForMint { collections( - filter: { mintType: { equalTo: PUBLIC } } + condition: { mintType: PUBLIC } orderBy: CREATED_AT_ASC first: 100 # TODO: implement pagination ) { diff --git a/pages/drops.gql b/pages/drops.gql index 8a20818d..9e9575fd 100644 --- a/pages/drops.gql +++ b/pages/drops.gql @@ -27,18 +27,20 @@ fragment DropDetail on Drop { } } -query FetchDrops($now: Datetime!, $limit: Int!, $offset: Int!) { - active: drops( - orderBy: [START_DATE_ASC] - filter: { endDate: { greaterThan: $now } } - ) { +query FetchDrops($limit: Int!, $offset: Int!) { + active: drops(orderBy: [START_DATE_ASC], condition: { status: ACTIVE }) { + nodes { + ...DropDetail + } + } + upcoming: drops(orderBy: [START_DATE_ASC], condition: { status: UPCOMING }) { nodes { ...DropDetail } } ended: drops( orderBy: [START_DATE_DESC] - filter: { endDate: { lessThanOrEqualTo: $now } } + condition: { status: ENDED } first: $limit offset: $offset ) { diff --git a/pages/drops.tsx b/pages/drops.tsx index 5e477f55..c5c7083c 100644 --- a/pages/drops.tsx +++ b/pages/drops.tsx @@ -1,7 +1,7 @@ import { Divider, Heading, SimpleGrid } from '@chakra-ui/react' import { NextPage } from 'next' import useTranslation from 'next-translate/useTranslation' -import { useCallback, useMemo } from 'react' +import { useCallback } from 'react' import DropCard from '../components/Drop/DropCard' import Empty from '../components/Empty/Empty' import Head from '../components/Head' @@ -14,21 +14,18 @@ import usePaginate from '../hooks/usePaginate' import usePaginateQuery from '../hooks/usePaginateQuery' import LargeLayout from '../layouts/large' -type Props = { - now: string -} - -const DropsPage: NextPage = ({ now }) => { +const DropsPage: NextPage = () => { const { t } = useTranslation('templates') const { PAGINATION_LIMIT, REPORT_EMAIL } = useEnvironment() - const date = useMemo(() => new Date(now), [now]) const { page, limit, offset } = usePaginateQuery() const { changeLimit } = usePaginate() const { data, refetch } = useFetchDropsQuery({ - variables: { now: date, limit, offset }, + variables: { limit, offset }, }) - const activeDrops = data?.active?.nodes + const activeAndUpcomingDrops = data?.active?.nodes.concat( + data?.upcoming?.nodes || [], + ) const endedDrops = data?.ended?.nodes const onCountdownEnd = useCallback(async () => await refetch(), [refetch]) @@ -39,11 +36,11 @@ const DropsPage: NextPage = ({ now }) => { {t('drops.title')} - {!activeDrops || !endedDrops ? ( + {!activeAndUpcomingDrops || !endedDrops ? ( - ) : activeDrops.length === 0 && endedDrops.length === 0 ? ( + ) : activeAndUpcomingDrops.length === 0 && endedDrops.length === 0 ? ( = ({ now }) => { /> ) : ( <> - {activeDrops.length > 0 && ( + {activeAndUpcomingDrops.length > 0 && ( 0 ? 8 : 0} > - {activeDrops.map((drop) => { + {activeAndUpcomingDrops.map((drop) => { return ( = ({}) => { +const CollectionsPage: NextPage = () => { const { CHAINS, PAGINATION_LIMIT } = useEnvironment() const { pathname, push, query, replace } = useRouter() const isSmall = useBreakpointValue( @@ -64,7 +62,7 @@ const CollectionsPage: NextPage = ({}) => { limit, offset, orderBy, - filter: convertFilterToCollectionFilter(filter), + condition: convertFilterToCollectionFilter(filter), }, }) diff --git a/pages/explore/explore.gql b/pages/explore/explore.gql index 5e7501e8..aede4679 100644 --- a/pages/explore/explore.gql +++ b/pages/explore/explore.gql @@ -3,10 +3,10 @@ query FetchAllERC721And1155( $limit: Int! $offset: Int! $orderBy: [AssetsOrderBy!] - $filter: [AssetFilter!] + $condition: AssetCondition ) { assets( - filter: { quantity: { greaterThan: "0" }, and: $filter } + condition: $condition first: $limit offset: $offset orderBy: $orderBy diff --git a/pages/explore/explore.tsx b/pages/explore/explore.tsx index b3d2ad00..ac425e98 100644 --- a/pages/explore/explore.tsx +++ b/pages/explore/explore.tsx @@ -15,7 +15,7 @@ import { import { NextPage } from 'next' import useTranslation from 'next-translate/useTranslation' import { useRouter } from 'next/router' -import { useCallback, useMemo } from 'react' +import { useCallback } from 'react' import Empty from '../../components/Empty/Empty' import ExploreTemplate from '../../components/Explore' import FilterAsset, { NoFilter } from '../../components/Filter/FilterAsset' @@ -40,11 +40,7 @@ import usePaginate from '../../hooks/usePaginate' import usePaginateQuery from '../../hooks/usePaginateQuery' import { removeEmptyFromObject } from '../../utils' -type Props = { - now: string -} - -const ExplorePage: NextPage = ({ now }) => { +const ExplorePage: NextPage = () => { const { PAGINATION_LIMIT } = useEnvironment() const { query, pathname, push } = useRouter() const isSmall = useBreakpointValue( @@ -52,7 +48,6 @@ const ExplorePage: NextPage = ({ now }) => { { fallback: 'md' }, ) const { t } = useTranslation('templates') - const date = useMemo(() => new Date(now), [now]) const { address } = useAccount() const filter = useAssetFilterFromQuery() const orderBy = useOrderByQuery('BEST_PRICE_ASC') @@ -63,7 +58,7 @@ const ExplorePage: NextPage = ({ now }) => { limit, offset, orderBy, - filter: convertFilterToAssetFilter(filter, date), + condition: convertFilterToAssetFilter(filter), }, }) useCart({ onCheckout: refetch }) diff --git a/pages/explore/users.gql b/pages/explore/users.gql index bf8e09f1..223a5f87 100644 --- a/pages/explore/users.gql +++ b/pages/explore/users.gql @@ -2,13 +2,13 @@ query FetchExploreUsers( $limit: Int! $offset: Int! $orderBy: [AccountsOrderBy!] - $filter: [AccountFilter!] + $search: String ) { users: accounts( first: $limit offset: $offset orderBy: $orderBy - filter: { and: $filter } + condition: { search: $search } ) { pageInfo { hasNextPage diff --git a/pages/explore/users.tsx b/pages/explore/users.tsx index 029475b2..900d32c7 100644 --- a/pages/explore/users.tsx +++ b/pages/explore/users.tsx @@ -17,29 +17,14 @@ import Select from '../../components/Select/Select' import SkeletonGrid from '../../components/Skeleton/Grid' import SkeletonUserCard from '../../components/Skeleton/UserCard' import UserCard from '../../components/User/UserCard' -import { - AccountFilter, - AccountsOrderBy, - useFetchExploreUsersQuery, -} from '../../graphql' +import { AccountsOrderBy, useFetchExploreUsersQuery } from '../../graphql' import useEnvironment from '../../hooks/useEnvironment' import useOrderByQuery from '../../hooks/useOrderByQuery' import usePaginate from '../../hooks/usePaginate' import usePaginateQuery from '../../hooks/usePaginateQuery' import useQueryParamSingle from '../../hooks/useQueryParamSingle' -type Props = {} - -const searchFilter = (search: string): AccountFilter => - ({ - or: [ - { name: { includesInsensitive: search } } as AccountFilter, - { address: { includesInsensitive: search } } as AccountFilter, - { description: { includesInsensitive: search } } as AccountFilter, - ], - }) as AccountFilter - -const UsersPage: NextPage = () => { +const UsersPage: NextPage = () => { const { PAGINATION_LIMIT } = useEnvironment() const { query, pathname, push } = useRouter() const isSmall = useBreakpointValue( @@ -55,7 +40,7 @@ const UsersPage: NextPage = () => { limit, offset, orderBy, - filter: search ? searchFilter(search) : [], + search, }, }) diff --git a/pages/index.tsx b/pages/index.tsx index c7f0f446..0d9c7489 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -23,7 +23,7 @@ const HomePage: NextPage = ({ now }) => { - + diff --git a/pages/notification.gql b/pages/notification.gql index 861add0d..1025909f 100644 --- a/pages/notification.gql +++ b/pages/notification.gql @@ -1,18 +1,15 @@ -query GetNotifications($address: Address!, $limit: Int!, $offset: Int!) { +query GetNotifications($limit: Int!, $offset: Int!) { notifications( - filter: { - accountAddress: { equalTo: $address } - action: { - in: [ - ACCOUNT_VERIFICATION_VALIDATED - BID_ACCEPTED - BID_CREATED - OFFER_PURCHASED - BID_EXPIRED - OFFER_EXPIRED - REFERRAL_REFEREE_REGISTERED - ] - } + condition: { + actions: [ + ACCOUNT_VERIFICATION_VALIDATED + BID_ACCEPTED + BID_CREATED + OFFER_PURCHASED + BID_EXPIRED + OFFER_EXPIRED + REFERRAL_REFEREE_REGISTERED + ] } first: $limit orderBy: CREATED_AT_DESC diff --git a/pages/notification.tsx b/pages/notification.tsx index fc1982d2..913cd894 100644 --- a/pages/notification.tsx +++ b/pages/notification.tsx @@ -43,7 +43,6 @@ const NotificationPage: NextPage = ({}) => { variables: { offset: 0, // the offset change must be done when calling the fetchMore function to concat queries' results limit: PAGINATION_LIMIT, - address: address || '', }, notifyOnNetworkStatusChange: true, skip: !address, diff --git a/pages/tokens/[id]/bid.gql b/pages/tokens/[id]/bid.gql index dcc8c4d8..f485d18d 100644 --- a/pages/tokens/[id]/bid.gql +++ b/pages/tokens/[id]/bid.gql @@ -64,7 +64,10 @@ query BidOnAsset( } currencies( orderBy: CREATED_AT_ASC - filter: { chainId: { equalTo: $chainId }, address: { isNull: false } } + condition: { + chainId: $chainId + onlyToken: true # keep only non-native currency. Cannot create bid with native currency. + } ) { nodes { id diff --git a/pages/tokens/[id]/index.gql b/pages/tokens/[id]/index.gql index 7762f5b9..1b178c2a 100644 --- a/pages/tokens/[id]/index.gql +++ b/pages/tokens/[id]/index.gql @@ -3,7 +3,6 @@ query FetchAsset( $collectionAddress: Address! $tokenId: String! $address: Address - $now: Datetime! ) { asset( chainId: $chainId @@ -55,10 +54,10 @@ query FetchAsset( } } ownerships( - filter: { - chainId: { equalTo: $chainId } - collectionAddress: { equalTo: $collectionAddress } - tokenId: { equalTo: $tokenId } + condition: { + chainId: $chainId + collectionAddress: $collectionAddress + tokenId: $tokenId } orderBy: [ QUANTITY_DESC @@ -81,13 +80,13 @@ query FetchAsset( } } } - bids: offerOpenBuys( + bids: openOffers( orderBy: [UNIT_PRICE_IN_REF_DESC, CREATED_AT_ASC] - filter: { - chainId: { equalTo: $chainId } - collectionAddress: { equalTo: $collectionAddress } - tokenId: { equalTo: $tokenId } - expiredAt: { greaterThan: $now } + condition: { + chainId: $chainId + collectionAddress: $collectionAddress + tokenId: $tokenId + status: ACTIVE } first: 100 # TODO: implement pagination ) { @@ -118,13 +117,13 @@ query FetchAsset( } } } - sales: offerOpenSales( + sales: listings( orderBy: [UNIT_PRICE_IN_REF_ASC, CREATED_AT_ASC] - filter: { - chainId: { equalTo: $chainId } - collectionAddress: { equalTo: $collectionAddress } - tokenId: { equalTo: $tokenId } - expiredAt: { greaterThan: $now } + condition: { + chainId: $chainId + collectionAddress: $collectionAddress + tokenId: $tokenId + status: ACTIVE } # TODO: implement pagination. when implementing pagination, find a way to get availableQuantity of all sales ) { nodes { @@ -151,9 +150,9 @@ query FetchAsset( } currencies( orderBy: CREATED_AT_ASC - filter: { - chainId: { equalTo: $chainId } - address: { isNull: false } # keep only non-native currency. Cannot create bid with native currency. + condition: { + chainId: $chainId + onlyToken: true # keep only non-native currency. Cannot create bid with native currency. } ) { nodes { diff --git a/pages/tokens/[id]/index.tsx b/pages/tokens/[id]/index.tsx index 9f6dd0d6..d305a205 100644 --- a/pages/tokens/[id]/index.tsx +++ b/pages/tokens/[id]/index.tsx @@ -50,10 +50,6 @@ import LargeLayout from '../../../layouts/large' import { formatError } from '../../../utils' import Error from '../../_error' -type Props = { - now: string -} - enum AssetTabs { bids = 'bids', history = 'history', @@ -61,7 +57,7 @@ enum AssetTabs { const tabs = [AssetTabs.bids, AssetTabs.history] -const DetailPage: NextPage = ({ now: nowProp }) => { +const DetailPage: NextPage = () => { const { CHAINS, REPORT_EMAIL } = useEnvironment() const { t } = useTranslation('templates') const toast = useToast() @@ -74,13 +70,11 @@ const DetailPage: NextPage = ({ now: nowProp }) => { invariant(tokenId, 'tokenId is required') const chainId = parseInt(_chainId, 10) - const date = useMemo(() => new Date(nowProp), [nowProp]) const { data, refetch } = useFetchAssetQuery({ variables: { chainId, collectionAddress, tokenId, - now: date, address: address || '', }, }) @@ -117,9 +111,7 @@ const DetailPage: NextPage = ({ now: nowProp }) => { ) const refresh = useCallback(async () => { - await refetch({ - now: new Date(), - }) + await refetch() }, [refetch]) useCart({ onCheckout: refetch }) diff --git a/pages/tokens/[id]/offer.gql b/pages/tokens/[id]/offer.gql index cd7dbd12..f383bd82 100644 --- a/pages/tokens/[id]/offer.gql +++ b/pages/tokens/[id]/offer.gql @@ -65,10 +65,7 @@ query OfferForAsset( } } } - currencies( - orderBy: CREATED_AT_ASC - filter: { chainId: { equalTo: $chainId } } - ) { + currencies(orderBy: CREATED_AT_ASC, condition: { chainId: $chainId }) { nodes { id chainId diff --git a/pages/users/[id]/bids/placed.gql b/pages/users/[id]/bids/placed.gql index c868a597..f73880a7 100644 --- a/pages/users/[id]/bids/placed.gql +++ b/pages/users/[id]/bids/placed.gql @@ -4,16 +4,11 @@ query FetchUserBidsPlaced( $orderBy: [OffersOrderBy!] $address: Address! ) { - bids: offers( + bids: openOffers( orderBy: $orderBy first: $limit offset: $offset - filter: { - type: { equalTo: BUY } - availableQuantity: { greaterThan: "0" } - signature: { isNull: false } - makerAddress: { equalTo: $address } - } + condition: { status: [ACTIVE, EXPIRED], makerAddress: $address } includeWhenAssetDeleted: YES includeWhenCurrencyDeleted: YES ) { diff --git a/pages/users/[id]/bids/received.gql b/pages/users/[id]/bids/received.gql index e47884d0..f4ba9cce 100644 --- a/pages/users/[id]/bids/received.gql +++ b/pages/users/[id]/bids/received.gql @@ -3,19 +3,15 @@ query FetchUserBidsReceived( $offset: Int! $orderBy: [OffersOrderBy!] $address: Address! - $now: Datetime ) { - bids: offers( + bids: openOffers( orderBy: $orderBy first: $limit offset: $offset - filter: { - type: { equalTo: BUY } - availableQuantity: { greaterThan: "0" } - signature: { isNull: false } - expiredAt: { greaterThan: $now } - makerAddress: { notEqualTo: $address } - asset: { ownerships: { some: { ownerAddress: { equalTo: $address } } } } + condition: { + status: ACTIVE + not: { makerAddress: $address } + takerAddressV1: $address } includeWhenAssetDeleted: YES includeWhenCurrencyDeleted: YES diff --git a/pages/users/[id]/bids/received.tsx b/pages/users/[id]/bids/received.tsx index 18aa660b..5a3a22a0 100644 --- a/pages/users/[id]/bids/received.tsx +++ b/pages/users/[id]/bids/received.tsx @@ -20,7 +20,7 @@ import { HiOutlineSearch } from '@react-icons/all-files/hi/HiOutlineSearch' import { NextPage } from 'next' import useTranslation from 'next-translate/useTranslation' import { useRouter } from 'next/router' -import { useCallback, useMemo } from 'react' +import { useCallback } from 'react' import AcceptOfferButton from '../../../../components/Button/AcceptOffer' import Empty from '../../../../components/Empty/Empty' import Image from '../../../../components/Image/Image' @@ -43,11 +43,7 @@ import useRequiredQueryParamSingle from '../../../../hooks/useRequiredQueryParam import LargeLayout from '../../../../layouts/large' import { dateFromNow, formatError } from '../../../../utils' -type Props = { - now: string -} - -const BidReceivedPage: NextPage = ({ now }) => { +const BidReceivedPage: NextPage = () => { const { BASE_URL, PAGINATION_LIMIT } = useEnvironment() const { t } = useTranslation('templates') const { replace, pathname, query } = useRouter() @@ -58,14 +54,12 @@ const BidReceivedPage: NextPage = ({ now }) => { const userAddress = useRequiredQueryParamSingle('id') const ownerLoggedIn = useIsLoggedIn(userAddress) - const date = useMemo(() => new Date(now), [now]) const { data, refetch } = useFetchUserBidsReceivedQuery({ variables: { address: userAddress, limit, offset, orderBy, - now: date, }, }) const bids = data?.bids?.nodes diff --git a/pages/users/[id]/created.gql b/pages/users/[id]/created.gql index 4da36c6f..3ea4e8af 100644 --- a/pages/users/[id]/created.gql +++ b/pages/users/[id]/created.gql @@ -6,10 +6,7 @@ query FetchCreatedAssets( $orderBy: [AssetsOrderBy!] ) { created: assets( - filter: { - quantity: { greaterThan: "0" } - creatorAddress: { equalTo: $address } - } + condition: { creatorAddress: $address } first: $limit offset: $offset orderBy: $orderBy diff --git a/pages/users/[id]/offers.gql b/pages/users/[id]/offers.gql index 43b1911f..230e16b2 100644 --- a/pages/users/[id]/offers.gql +++ b/pages/users/[id]/offers.gql @@ -4,15 +4,11 @@ query FetchUserFixedPrice( $orderBy: [OffersOrderBy!] $address: Address! ) { - offers: offers( + offers: listings( orderBy: $orderBy first: $limit offset: $offset - filter: { - type: { equalTo: SALE } - signature: { isNull: false } - makerAddress: { equalTo: $address } - } + condition: { makerAddress: $address } includeWhenAssetDeleted: YES includeWhenCurrencyDeleted: YES ) { diff --git a/pages/users/[id]/on-sale.gql b/pages/users/[id]/on-sale.gql index 1ed07bfc..1fac17a9 100644 --- a/pages/users/[id]/on-sale.gql +++ b/pages/users/[id]/on-sale.gql @@ -1,21 +1,12 @@ query FetchOnSaleAssets( $address: Address! $currentAddress: Address! - $now: Datetime! $limit: Int! $offset: Int! $orderBy: [AssetsOrderBy!] ) { onSale: assets( - filter: { - quantity: { greaterThan: "0" } - sales: { - some: { - makerAddress: { equalTo: $address } - expiredAt: { greaterThan: $now } - } - } - } + condition: { listings: { status: ACTIVE, makerAddress: $address } } first: $limit offset: $offset orderBy: $orderBy diff --git a/pages/users/[id]/on-sale.tsx b/pages/users/[id]/on-sale.tsx index 09d2ce08..642b7617 100644 --- a/pages/users/[id]/on-sale.tsx +++ b/pages/users/[id]/on-sale.tsx @@ -14,11 +14,7 @@ import usePaginateQuery from '../../../hooks/usePaginateQuery' import useRequiredQueryParamSingle from '../../../hooks/useRequiredQueryParamSingle' import LargeLayout from '../../../layouts/large' -type Props = { - now: string -} - -const OnSalePage: NextPage = ({ now }) => { +const OnSalePage: NextPage = () => { const { BASE_URL, PAGINATION_LIMIT } = useEnvironment() const { t } = useTranslation('templates') const { pathname, replace, query } = useRouter() @@ -28,7 +24,6 @@ const OnSalePage: NextPage = ({ now }) => { const { address } = useAccount() const userAddress = useRequiredQueryParamSingle('id') - const date = useMemo(() => new Date(now), [now]) const { data, refetch } = useFetchOnSaleAssetsQuery({ variables: { address: userAddress, @@ -36,7 +31,6 @@ const OnSalePage: NextPage = ({ now }) => { limit, offset, orderBy, - now: date, }, }) diff --git a/pages/users/[id]/owned.gql b/pages/users/[id]/owned.gql index d1347fda..9df61d12 100644 --- a/pages/users/[id]/owned.gql +++ b/pages/users/[id]/owned.gql @@ -6,7 +6,7 @@ query FetchOwnedAssets( $orderBy: [OwnershipsOrderBy!] ) { owned: ownerships( - filter: { ownerAddress: { equalTo: $address }, assetExists: true } + condition: { ownerAddress: $address } first: $limit offset: $offset orderBy: $orderBy diff --git a/pages/users/[id]/trades/purchased.gql b/pages/users/[id]/trades/purchased.gql index ce0f19ca..5e5c7812 100644 --- a/pages/users/[id]/trades/purchased.gql +++ b/pages/users/[id]/trades/purchased.gql @@ -8,13 +8,7 @@ query FetchUserTradePurchased( orderBy: $orderBy first: $limit offset: $offset - filter: { - buyerAddress: { equalTo: $address } - or: [ - { deletedAt: { isNull: true } } # include trades not deleted - { deletedAt: { isNull: false }, offerExists: true } # include trades deleted but related to an offer - ] - } + condition: { buyerAddress: $address } includeWhenAssetDeleted: YES includeWhenCollectionDeleted: YES includeWhenCurrencyDeleted: YES diff --git a/pages/users/[id]/trades/sold.gql b/pages/users/[id]/trades/sold.gql index fa973f69..bd862939 100644 --- a/pages/users/[id]/trades/sold.gql +++ b/pages/users/[id]/trades/sold.gql @@ -8,13 +8,7 @@ query FetchUserTradeSold( orderBy: $orderBy first: $limit offset: $offset - filter: { - sellerAddress: { equalTo: $address } - or: [ - { deletedAt: { isNull: true } } # include trades not deleted - { deletedAt: { isNull: false }, offerExists: true } # include trades deleted but related to an offer - ] - } + condition: { sellerAddress: $address } includeWhenAssetDeleted: YES includeWhenCollectionDeleted: YES includeWhenCurrencyDeleted: YES