Commit e8c689e1 authored by Charles Bachmeier's avatar Charles Bachmeier Committed by GitHub

feat: Migrate trending nfts endpoint to graphql (#6049)

* defined useTrendingCollections hook and made fields optional

* working trending collections table

* add gql file

* add gql to search suggestions and handle floor wei vs eth

* gql carousel

* fontWeight typo and skip if flag disabled

---------
Co-authored-by: default avatarCharles Bachmeier <charlie@genie.xyz>
parent 70cd7272
...@@ -2,7 +2,9 @@ import { Trans } from '@lingui/macro' ...@@ -2,7 +2,9 @@ import { Trans } from '@lingui/macro'
import { useTrace } from '@uniswap/analytics' import { useTrace } from '@uniswap/analytics'
import { InterfaceSectionName, NavBarSearchTypes } from '@uniswap/analytics-events' import { InterfaceSectionName, NavBarSearchTypes } from '@uniswap/analytics-events'
import { useWeb3React } from '@web3-react/core' import { useWeb3React } from '@web3-react/core'
import { SafetyLevel } from 'graphql/data/__generated__/types-and-hooks' import { useNftGraphqlEnabled } from 'featureFlags/flags/nftlGraphql'
import { HistoryDuration, SafetyLevel } from 'graphql/data/__generated__/types-and-hooks'
import { useTrendingCollections } from 'graphql/data/nft/TrendingCollections'
import { SearchToken } from 'graphql/data/SearchTokens' import { SearchToken } from 'graphql/data/SearchTokens'
import useTrendingTokens from 'graphql/data/TrendingTokens' import useTrendingTokens from 'graphql/data/TrendingTokens'
import { useIsNftPage } from 'hooks/useIsNftPage' import { useIsNftPage } from 'hooks/useIsNftPage'
...@@ -56,7 +58,7 @@ const SearchBarDropdownSection = ({ ...@@ -56,7 +58,7 @@ const SearchBarDropdownSection = ({
</Row> </Row>
<Column gap="12"> <Column gap="12">
{suggestions.map((suggestion, index) => {suggestions.map((suggestion, index) =>
isLoading ? ( isLoading || !suggestion ? (
<SkeletonRow key={index} /> <SkeletonRow key={index} />
) : isCollection(suggestion) ? ( ) : isCollection(suggestion) ? (
<CollectionRow <CollectionRow
...@@ -123,6 +125,7 @@ export const SearchBarDropdown = ({ ...@@ -123,6 +125,7 @@ export const SearchBarDropdown = ({
const { pathname } = useLocation() const { pathname } = useLocation()
const isNFTPage = useIsNftPage() const isNFTPage = useIsNftPage()
const isNftGraphqlEnabled = useNftGraphqlEnabled()
const isTokenPage = pathname.includes('/tokens') const isTokenPage = pathname.includes('/tokens')
const [resultsState, setResultsState] = useState<ReactNode>() const [resultsState, setResultsState] = useState<ReactNode>()
...@@ -131,24 +134,25 @@ export const SearchBarDropdown = ({ ...@@ -131,24 +134,25 @@ export const SearchBarDropdown = ({
() => fetchTrendingCollections({ volumeType: 'eth', timePeriod: 'ONE_DAY' as TimePeriod, size: 3 }) () => fetchTrendingCollections({ volumeType: 'eth', timePeriod: 'ONE_DAY' as TimePeriod, size: 3 })
) )
const trendingCollections = useMemo( const { data: gqlData, loading } = useTrendingCollections(3, HistoryDuration.Day)
() =>
trendingCollectionResults const trendingCollections = useMemo(() => {
? trendingCollectionResults const gatedTrendingCollections = isNftGraphqlEnabled ? gqlData : trendingCollectionResults
.map((collection) => ({ return gatedTrendingCollections && (!isNftGraphqlEnabled || !loading)
...collection, ? gatedTrendingCollections
collectionAddress: collection.address, .map((collection) => ({
floorPrice: formatEthPrice(collection.floor?.toString()), ...collection,
stats: { collectionAddress: collection.address,
total_supply: collection.totalSupply, floorPrice: isNftGraphqlEnabled ? collection.floor : formatEthPrice(collection.floor?.toString()),
one_day_change: collection.floorChange, stats: {
floor_price: formatEthPrice(collection.floor?.toString()), total_supply: collection.totalSupply,
}, one_day_change: collection.floorChange,
})) floor_price: isNftGraphqlEnabled ? collection.floor : formatEthPrice(collection.floor?.toString()),
.slice(0, isNFTPage ? 3 : 2) },
: [...Array<GenieCollection>(isNFTPage ? 3 : 2)], }))
[isNFTPage, trendingCollectionResults] .slice(0, isNFTPage ? 3 : 2)
) : [...Array<GenieCollection>(isNFTPage ? 3 : 2)]
}, [gqlData, isNFTPage, isNftGraphqlEnabled, loading, trendingCollectionResults])
const { data: trendingTokenData } = useTrendingTokens(useWeb3React().chainId) const { data: trendingTokenData } = useTrendingTokens(useWeb3React().chainId)
......
...@@ -4,4 +4,8 @@ export function useNftGraphqlFlag(): BaseVariant { ...@@ -4,4 +4,8 @@ export function useNftGraphqlFlag(): BaseVariant {
return useBaseFlag(FeatureFlag.nftGraphql) return useBaseFlag(FeatureFlag.nftGraphql)
} }
export function useNftGraphqlEnabled(): boolean {
return useNftGraphqlFlag() === BaseVariant.Enabled
}
export { BaseVariant as NftGraphqlVariant } export { BaseVariant as NftGraphqlVariant }
...@@ -675,9 +675,11 @@ export type QueryNftAssetsArgs = { ...@@ -675,9 +675,11 @@ export type QueryNftAssetsArgs = {
asc?: InputMaybe<Scalars['Boolean']>; asc?: InputMaybe<Scalars['Boolean']>;
before?: InputMaybe<Scalars['String']>; before?: InputMaybe<Scalars['String']>;
chain?: InputMaybe<Chain>; chain?: InputMaybe<Chain>;
cursor?: InputMaybe<Scalars['String']>;
filter?: InputMaybe<NftAssetsFilterInput>; filter?: InputMaybe<NftAssetsFilterInput>;
first?: InputMaybe<Scalars['Int']>; first?: InputMaybe<Scalars['Int']>;
last?: InputMaybe<Scalars['Int']>; last?: InputMaybe<Scalars['Int']>;
limit?: InputMaybe<Scalars['Int']>;
orderBy?: InputMaybe<NftAssetSortableField>; orderBy?: InputMaybe<NftAssetSortableField>;
}; };
...@@ -1119,6 +1121,14 @@ export type NftRouteQueryVariables = Exact<{ ...@@ -1119,6 +1121,14 @@ export type NftRouteQueryVariables = Exact<{
export type NftRouteQuery = { __typename?: 'Query', nftRoute?: { __typename?: 'NftRouteResponse', id: string, calldata: string, toAddress: string, route?: Array<{ __typename?: 'NftTrade', amount: number, contractAddress: string, id: string, marketplace: NftMarketplace, tokenId: string, tokenType: NftStandard, price: { __typename?: 'TokenAmount', id: string, currency: Currency, value: string }, quotePrice?: { __typename?: 'TokenAmount', id: string, currency: Currency, value: string } }>, sendAmount: { __typename?: 'TokenAmount', id: string, currency: Currency, value: string } } }; export type NftRouteQuery = { __typename?: 'Query', nftRoute?: { __typename?: 'NftRouteResponse', id: string, calldata: string, toAddress: string, route?: Array<{ __typename?: 'NftTrade', amount: number, contractAddress: string, id: string, marketplace: NftMarketplace, tokenId: string, tokenType: NftStandard, price: { __typename?: 'TokenAmount', id: string, currency: Currency, value: string }, quotePrice?: { __typename?: 'TokenAmount', id: string, currency: Currency, value: string } }>, sendAmount: { __typename?: 'TokenAmount', id: string, currency: Currency, value: string } } };
export type TrendingCollectionsQueryVariables = Exact<{
size?: InputMaybe<Scalars['Int']>;
timePeriod?: InputMaybe<HistoryDuration>;
}>;
export type TrendingCollectionsQuery = { __typename?: 'Query', topCollections?: { __typename?: 'NftCollectionConnection', edges: Array<{ __typename?: 'NftCollectionEdge', node: { __typename?: 'NftCollection', name?: string, isVerified?: boolean, nftContracts?: Array<{ __typename?: 'NftContract', address: string, totalSupply?: number }>, image?: { __typename?: 'Image', url: string }, bannerImage?: { __typename?: 'Image', url: string }, markets?: Array<{ __typename?: 'NftCollectionMarket', owners?: number, floorPrice?: { __typename?: 'TimestampedAmount', value: number }, totalVolume?: { __typename?: 'TimestampedAmount', value: number }, volume?: { __typename?: 'TimestampedAmount', value: number }, volumePercentChange?: { __typename?: 'TimestampedAmount', value: number }, floorPricePercentChange?: { __typename?: 'TimestampedAmount', value: number }, sales?: { __typename?: 'TimestampedAmount', value: number }, listings?: { __typename?: 'TimestampedAmount', value: number } }> } }> } };
export const RecentlySearchedAssetsDocument = gql` export const RecentlySearchedAssetsDocument = gql`
query RecentlySearchedAssets($collectionAddresses: [String!]!, $contracts: [ContractInput!]!) { query RecentlySearchedAssets($collectionAddresses: [String!]!, $contracts: [ContractInput!]!) {
...@@ -2117,4 +2127,82 @@ export function useNftRouteLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<N ...@@ -2117,4 +2127,82 @@ export function useNftRouteLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<N
} }
export type NftRouteQueryHookResult = ReturnType<typeof useNftRouteQuery>; export type NftRouteQueryHookResult = ReturnType<typeof useNftRouteQuery>;
export type NftRouteLazyQueryHookResult = ReturnType<typeof useNftRouteLazyQuery>; export type NftRouteLazyQueryHookResult = ReturnType<typeof useNftRouteLazyQuery>;
export type NftRouteQueryResult = Apollo.QueryResult<NftRouteQuery, NftRouteQueryVariables>; export type NftRouteQueryResult = Apollo.QueryResult<NftRouteQuery, NftRouteQueryVariables>;
\ No newline at end of file export const TrendingCollectionsDocument = gql`
query TrendingCollections($size: Int, $timePeriod: HistoryDuration) {
topCollections(limit: $size, duration: $timePeriod) {
edges {
node {
name
nftContracts {
address
totalSupply
}
image {
url
}
bannerImage {
url
}
isVerified
markets(currencies: ETH) {
floorPrice {
value
}
owners
totalVolume {
value
}
volume(duration: $timePeriod) {
value
}
volumePercentChange(duration: $timePeriod) {
value
}
floorPricePercentChange(duration: $timePeriod) {
value
}
sales {
value
}
totalVolume {
value
}
listings {
value
}
}
}
}
}
}
`;
/**
* __useTrendingCollectionsQuery__
*
* To run a query within a React component, call `useTrendingCollectionsQuery` and pass it any options that fit your needs.
* When your component renders, `useTrendingCollectionsQuery` returns an object from Apollo Client that contains loading, error, and data properties
* you can use to render your UI.
*
* @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
*
* @example
* const { data, loading, error } = useTrendingCollectionsQuery({
* variables: {
* size: // value for 'size'
* timePeriod: // value for 'timePeriod'
* },
* });
*/
export function useTrendingCollectionsQuery(baseOptions?: Apollo.QueryHookOptions<TrendingCollectionsQuery, TrendingCollectionsQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useQuery<TrendingCollectionsQuery, TrendingCollectionsQueryVariables>(TrendingCollectionsDocument, options);
}
export function useTrendingCollectionsLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<TrendingCollectionsQuery, TrendingCollectionsQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useLazyQuery<TrendingCollectionsQuery, TrendingCollectionsQueryVariables>(TrendingCollectionsDocument, options);
}
export type TrendingCollectionsQueryHookResult = ReturnType<typeof useTrendingCollectionsQuery>;
export type TrendingCollectionsLazyQueryHookResult = ReturnType<typeof useTrendingCollectionsLazyQuery>;
export type TrendingCollectionsQueryResult = Apollo.QueryResult<TrendingCollectionsQuery, TrendingCollectionsQueryVariables>;
\ No newline at end of file
import { useNftGraphqlEnabled } from 'featureFlags/flags/nftlGraphql'
import gql from 'graphql-tag'
import { TrendingCollection } from 'nft/types'
import { useMemo } from 'react'
import { HistoryDuration, useTrendingCollectionsQuery } from '../__generated__/types-and-hooks'
gql`
query TrendingCollections($size: Int, $timePeriod: HistoryDuration) {
topCollections(limit: $size, duration: $timePeriod) {
edges {
node {
name
nftContracts {
address
totalSupply
}
image {
url
}
bannerImage {
url
}
isVerified
markets(currencies: ETH) {
floorPrice {
value
}
owners
totalVolume {
value
}
volume(duration: $timePeriod) {
value
}
volumePercentChange(duration: $timePeriod) {
value
}
floorPricePercentChange(duration: $timePeriod) {
value
}
sales {
value
}
listings {
value
}
}
}
}
}
}
`
export function useTrendingCollections(size: number, timePeriod: HistoryDuration) {
const isNftGraphqlEnabled = useNftGraphqlEnabled()
const { data, loading, error } = useTrendingCollectionsQuery({
variables: {
size,
timePeriod,
},
skip: !isNftGraphqlEnabled,
})
const trendingCollections: TrendingCollection[] | undefined = useMemo(
() =>
data?.topCollections?.edges?.map((edge) => {
const collection = edge?.node
return {
name: collection.name,
address: collection.nftContracts?.[0].address,
imageUrl: collection.image?.url,
bannerImageUrl: collection.bannerImage?.url,
isVerified: collection.isVerified,
volume: collection.markets?.[0].volume?.value,
volumeChange: collection.markets?.[0].volumePercentChange?.value,
floor: collection.markets?.[0].floorPrice?.value,
floorChange: collection.markets?.[0].floorPricePercentChange?.value,
marketCap: collection.markets?.[0].totalVolume?.value,
percentListed:
(collection.markets?.[0].listings?.value ?? 0) / (collection.nftContracts?.[0].totalSupply ?? 1),
owners: collection.markets?.[0].owners,
sales: collection.markets?.[0].sales?.value,
totalSupply: collection.nftContracts?.[0].totalSupply,
}
}),
[data?.topCollections?.edges]
)
return {
data: trendingCollections,
loading,
error,
}
}
import { useNftGraphqlEnabled } from 'featureFlags/flags/nftlGraphql'
import { HistoryDuration } from 'graphql/data/__generated__/types-and-hooks'
import { useTrendingCollections } from 'graphql/data/nft/TrendingCollections'
import { fetchTrendingCollections } from 'nft/queries' import { fetchTrendingCollections } from 'nft/queries'
import { TimePeriod } from 'nft/types' import { TimePeriod } from 'nft/types'
import { calculateCardIndex } from 'nft/utils' import { calculateCardIndex } from 'nft/utils'
...@@ -114,6 +117,7 @@ const TRENDING_COLLECTION_SIZE = 5 ...@@ -114,6 +117,7 @@ const TRENDING_COLLECTION_SIZE = 5
const Banner = () => { const Banner = () => {
const navigate = useNavigate() const navigate = useNavigate()
const isNftGraphqlEnabled = useNftGraphqlEnabled()
const { data } = useQuery( const { data } = useQuery(
['trendingCollections'], ['trendingCollections'],
...@@ -130,12 +134,18 @@ const Banner = () => { ...@@ -130,12 +134,18 @@ const Banner = () => {
refetchOnMount: false, refetchOnMount: false,
} }
) )
const { data: gqlData } = useTrendingCollections(
const collections = useMemo( TRENDING_COLLECTION_SIZE + EXCLUDED_COLLECTIONS.length,
() => data?.filter((collection) => !EXCLUDED_COLLECTIONS.includes(collection.address)).slice(0, 5), HistoryDuration.Day
[data]
) )
const collections = useMemo(() => {
const gatedData = isNftGraphqlEnabled ? gqlData : data
return gatedData
?.filter((collection) => collection.address && !EXCLUDED_COLLECTIONS.includes(collection.address))
.slice(0, 5)
}, [data, gqlData, isNftGraphqlEnabled])
const [activeCollectionIdx, setActiveCollectionIdx] = useState(0) const [activeCollectionIdx, setActiveCollectionIdx] = useState(0)
const onToggleNextSlide = useCallback( const onToggleNextSlide = useCallback(
(direction: number) => { (direction: number) => {
......
import { formatNumberOrString, NumberType } from '@uniswap/conedison/format' import { formatNumberOrString, NumberType } from '@uniswap/conedison/format'
import { loadingAnimation } from 'components/Loader/styled' import { loadingAnimation } from 'components/Loader/styled'
import { LoadingBubble } from 'components/Tokens/loading' import { LoadingBubble } from 'components/Tokens/loading'
import { useNftGraphqlEnabled } from 'featureFlags/flags/nftlGraphql'
import { useCollection } from 'graphql/data/nft/Collection' import { useCollection } from 'graphql/data/nft/Collection'
import { VerifiedIcon } from 'nft/components/icons' import { VerifiedIcon } from 'nft/components/icons'
import { Markets, TrendingCollection } from 'nft/types' import { Markets, TrendingCollection } from 'nft/types'
import { formatWeiToDecimal } from 'nft/utils' import { ethNumberStandardFormatter, formatWeiToDecimal } from 'nft/utils'
import styled from 'styled-components/macro' import styled from 'styled-components/macro'
import { ThemedText } from 'theme/components/text' import { ThemedText } from 'theme/components/text'
...@@ -235,7 +236,8 @@ const MARKETS_ENUM_TO_NAME = { ...@@ -235,7 +236,8 @@ const MARKETS_ENUM_TO_NAME = {
} }
export const CarouselCard = ({ collection, onClick }: CarouselCardProps) => { export const CarouselCard = ({ collection, onClick }: CarouselCardProps) => {
const { data: gqlCollection, loading } = useCollection(collection.address) const { data: gqlCollection, loading } = useCollection(collection.address ?? '')
const isNftGraphqlEnabled = useNftGraphqlEnabled()
if (loading) return <LoadingCarouselCard /> if (loading) return <LoadingCarouselCard />
...@@ -252,9 +254,14 @@ export const CarouselCard = ({ collection, onClick }: CarouselCardProps) => { ...@@ -252,9 +254,14 @@ export const CarouselCard = ({ collection, onClick }: CarouselCardProps) => {
</FirstColumnTextWrapper> </FirstColumnTextWrapper>
</TableElement> </TableElement>
<TableElement> <TableElement>
<ThemedText.SubHeaderSmall color="userThemeColor"> {collection.floor && (
{formatWeiToDecimal(collection.floor.toString())} ETH Floor <ThemedText.SubHeaderSmall color="userThemeColor">
</ThemedText.SubHeaderSmall> {isNftGraphqlEnabled
? ethNumberStandardFormatter(collection.floor)
: formatWeiToDecimal(collection.floor.toString())}{' '}
ETH Floor
</ThemedText.SubHeaderSmall>
)}
</TableElement> </TableElement>
<TableElement> <TableElement>
<ThemedText.SubHeaderSmall color="userThemeColor"> <ThemedText.SubHeaderSmall color="userThemeColor">
...@@ -304,7 +311,7 @@ const CollectionName = styled(ThemedText.MediumHeader)` ...@@ -304,7 +311,7 @@ const CollectionName = styled(ThemedText.MediumHeader)`
const CarouselCardHeader = ({ collection }: { collection: TrendingCollection }) => { const CarouselCardHeader = ({ collection }: { collection: TrendingCollection }) => {
return ( return (
<CardHeaderContainer src={collection.bannerImageUrl}> <CardHeaderContainer src={collection.bannerImageUrl ?? ''}>
<CardHeaderColumn> <CardHeaderColumn>
<CollectionImage src={collection.imageUrl} /> <CollectionImage src={collection.imageUrl} />
<CollectionNameContainer> <CollectionNameContainer>
......
import { formatEther } from '@ethersproject/units' import { formatEther } from '@ethersproject/units'
import { useNftGraphqlEnabled } from 'featureFlags/flags/nftlGraphql'
import { SquareArrowDownIcon, SquareArrowUpIcon, VerifiedIcon } from 'nft/components/icons' import { SquareArrowDownIcon, SquareArrowUpIcon, VerifiedIcon } from 'nft/components/icons'
import { useIsMobile } from 'nft/hooks' import { useIsMobile } from 'nft/hooks'
import { Denomination } from 'nft/types' import { Denomination } from 'nft/types'
...@@ -114,9 +115,12 @@ export const EthCell = ({ ...@@ -114,9 +115,12 @@ export const EthCell = ({
usdPrice?: number usdPrice?: number
}) => { }) => {
const denominatedValue = getDenominatedValue(denomination, true, value, usdPrice) const denominatedValue = getDenominatedValue(denomination, true, value, usdPrice)
const isNftGraphqlEnabled = useNftGraphqlEnabled()
const formattedValue = denominatedValue const formattedValue = denominatedValue
? denomination === Denomination.ETH ? denomination === Denomination.ETH
? formatWeiToDecimal(denominatedValue.toString(), true) + ' ETH' ? isNftGraphqlEnabled
? ethNumberStandardFormatter(denominatedValue.toString(), false, true, false) + ' ETH'
: formatWeiToDecimal(denominatedValue.toString(), true) + ' ETH'
: ethNumberStandardFormatter(denominatedValue, true, false, true) : ethNumberStandardFormatter(denominatedValue, true, false, true)
: '-' : '-'
......
...@@ -19,7 +19,9 @@ export enum ColumnHeaders { ...@@ -19,7 +19,9 @@ export enum ColumnHeaders {
const VOLUME_CHANGE_MAX_VALUE = 9999 const VOLUME_CHANGE_MAX_VALUE = 9999
const compareFloats = (a: number, b: number): 1 | -1 => { const compareFloats = (a?: number, b?: number): 1 | -1 => {
if (!a) return -1
if (!b) return 1
return Math.round(a * 100000) >= Math.round(b * 100000) ? 1 : -1 return Math.round(a * 100000) >= Math.round(b * 100000) ? 1 : -1
} }
...@@ -123,7 +125,7 @@ const CollectionTable = ({ data, timePeriod }: { data: CollectionTableColumn[]; ...@@ -123,7 +125,7 @@ const CollectionTable = ({ data, timePeriod }: { data: CollectionTableColumn[];
const { change } = cell.row.original.volume const { change } = cell.row.original.volume
return timePeriod === TimePeriod.AllTime ? ( return timePeriod === TimePeriod.AllTime ? (
<TextCell value="-" /> <TextCell value="-" />
) : change >= VOLUME_CHANGE_MAX_VALUE ? ( ) : change && change >= VOLUME_CHANGE_MAX_VALUE ? (
<ChangeCell change={change}>{`>${VOLUME_CHANGE_MAX_VALUE}`}%</ChangeCell> <ChangeCell change={change}>{`>${VOLUME_CHANGE_MAX_VALUE}`}%</ChangeCell>
) : ( ) : (
<ChangeCell change={change} /> <ChangeCell change={change} />
......
import { OpacityHoverState } from 'components/Common' import { OpacityHoverState } from 'components/Common'
import { useNftGraphqlEnabled } from 'featureFlags/flags/nftlGraphql'
import { HistoryDuration } from 'graphql/data/__generated__/types-and-hooks'
import { useTrendingCollections } from 'graphql/data/nft/TrendingCollections'
import ms from 'ms.macro' import ms from 'ms.macro'
import { CollectionTableColumn, Denomination, TimePeriod, VolumeType } from 'nft/types' import { CollectionTableColumn, Denomination, TimePeriod, VolumeType } from 'nft/types'
import { fetchPrice } from 'nft/utils' import { fetchPrice } from 'nft/utils'
...@@ -29,7 +32,7 @@ const StyledHeader = styled.div` ...@@ -29,7 +32,7 @@ const StyledHeader = styled.div`
color: ${({ theme }) => theme.textPrimary}; color: ${({ theme }) => theme.textPrimary};
font-size: 36px; font-size: 36px;
line-height: 44px; line-height: 44px;
weight: 500; font-weight: 500;
@media only screen and (max-width: ${({ theme }) => `${theme.breakpoint.sm}px`}) { @media only screen and (max-width: ${({ theme }) => `${theme.breakpoint.sm}px`}) {
font-size: 20px; font-size: 20px;
...@@ -69,9 +72,25 @@ const StyledSelectorText = styled(ThemedText.SubHeader)<{ active: boolean }>` ...@@ -69,9 +72,25 @@ const StyledSelectorText = styled(ThemedText.SubHeader)<{ active: boolean }>`
color: ${({ theme, active }) => (active ? theme.textPrimary : theme.textSecondary)}; color: ${({ theme, active }) => (active ? theme.textPrimary : theme.textSecondary)};
` `
function convertTimePeriodToHistoryDuration(timePeriod: TimePeriod): HistoryDuration {
switch (timePeriod) {
case TimePeriod.OneDay:
return HistoryDuration.Day
case TimePeriod.SevenDays:
return HistoryDuration.Week
case TimePeriod.ThirtyDays:
return HistoryDuration.Month
case TimePeriod.AllTime:
return HistoryDuration.Max
default:
return HistoryDuration.Day
}
}
const TrendingCollections = () => { const TrendingCollections = () => {
const [timePeriod, setTimePeriod] = useState<TimePeriod>(TimePeriod.OneDay) const [timePeriod, setTimePeriod] = useState<TimePeriod>(TimePeriod.OneDay)
const [isEthToggled, setEthToggled] = useState(true) const [isEthToggled, setEthToggled] = useState(true)
const isNftGraphqlEnabled = useNftGraphqlEnabled()
const { isSuccess, data } = useQuery( const { isSuccess, data } = useQuery(
['trendingCollections', timePeriod], ['trendingCollections', timePeriod],
...@@ -86,6 +105,8 @@ const TrendingCollections = () => { ...@@ -86,6 +105,8 @@ const TrendingCollections = () => {
} }
) )
const { data: gqlData, loading } = useTrendingCollections(100, convertTimePeriodToHistoryDuration(timePeriod))
const { data: usdPrice } = useQuery(['fetchPrice', {}], () => fetchPrice(), { const { data: usdPrice } = useQuery(['fetchPrice', {}], () => fetchPrice(), {
refetchOnReconnect: false, refetchOnReconnect: false,
refetchOnWindowFocus: false, refetchOnWindowFocus: false,
...@@ -94,8 +115,10 @@ const TrendingCollections = () => { ...@@ -94,8 +115,10 @@ const TrendingCollections = () => {
}) })
const trendingCollections = useMemo(() => { const trendingCollections = useMemo(() => {
if (isSuccess && data) { const gatedData = isNftGraphqlEnabled ? gqlData : data
return data.map((d) => ({ const dataLoaded = isNftGraphqlEnabled ? !loading : isSuccess
if (dataLoaded && gatedData) {
return gatedData.map((d) => ({
...d, ...d,
collection: { collection: {
name: d.name, name: d.name,
...@@ -114,7 +137,6 @@ const TrendingCollections = () => { ...@@ -114,7 +137,6 @@ const TrendingCollections = () => {
}, },
owners: { owners: {
value: d.owners, value: d.owners,
change: d.ownersChange,
}, },
sales: d.sales, sales: d.sales,
totalSupply: d.totalSupply, totalSupply: d.totalSupply,
...@@ -122,7 +144,7 @@ const TrendingCollections = () => { ...@@ -122,7 +144,7 @@ const TrendingCollections = () => {
usdPrice, usdPrice,
})) }))
} else return [] as CollectionTableColumn[] } else return [] as CollectionTableColumn[]
}, [data, isSuccess, isEthToggled, usdPrice]) }, [isNftGraphqlEnabled, gqlData, data, loading, isSuccess, isEthToggled, usdPrice])
return ( return (
<ExploreContainer> <ExploreContainer>
......
...@@ -35,21 +35,20 @@ export interface TransactionsResponse { ...@@ -35,21 +35,20 @@ export interface TransactionsResponse {
} }
export interface TrendingCollection { export interface TrendingCollection {
name: string name?: string
address: string address?: string
imageUrl: string imageUrl?: string
bannerImageUrl: string bannerImageUrl?: string
isVerified: boolean isVerified?: boolean
volume: number volume?: number
volumeChange: number volumeChange?: number
floor: number floor?: number
floorChange: number floorChange?: number
marketCap: number marketCap?: number
percentListed: number percentListed?: number
owners: number owners?: number
ownersChange: number totalSupply?: number
totalSupply: number sales?: number
sales: number
} }
export enum Denomination { export enum Denomination {
...@@ -59,26 +58,25 @@ export enum Denomination { ...@@ -59,26 +58,25 @@ export enum Denomination {
export interface CollectionTableColumn { export interface CollectionTableColumn {
collection: { collection: {
name: string name?: string
address: string address?: string
logo: string logo?: string
isVerified: boolean isVerified?: boolean
} }
volume: { volume: {
value: number value?: number
change: number change?: number
type: VolumeType type?: VolumeType
} }
floor: { floor: {
value: number value?: number
change: number change?: number
} }
owners: { owners: {
value: number value?: number
change: number
} }
sales: number sales?: number
totalSupply: number totalSupply?: number
denomination: Denomination denomination: Denomination
usdPrice?: number usdPrice?: number
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment