mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
refactor new frontpage queries
This commit is contained in:
parent
21792e9d4f
commit
fa5c2ed684
@ -18,28 +18,28 @@ import { useWeb3 } from '../../providers/Web3'
|
|||||||
import { useSiteMetadata } from '../../hooks/useSiteMetadata'
|
import { useSiteMetadata } from '../../hooks/useSiteMetadata'
|
||||||
import { getOceanConfig } from '../../utils/ocean'
|
import { getOceanConfig } from '../../utils/ocean'
|
||||||
|
|
||||||
// TODO: these queries need to adapt to chainIds
|
async function getQueryHighest(
|
||||||
function getQueryHighest(chainIds: number[]) {
|
chainIds: number[]
|
||||||
return {
|
): Promise<[SearchQuery, string]> {
|
||||||
|
const dids = await getHighestLiquidityDIDs()
|
||||||
|
|
||||||
|
// TODO: this query needs to adapt to chainIds
|
||||||
|
const queryHighest = {
|
||||||
page: 1,
|
page: 1,
|
||||||
offset: 9,
|
offset: 15,
|
||||||
query: {
|
query: {
|
||||||
query_string: {
|
query_string: {
|
||||||
query: `(price.type:pool) -isInPurgatory:true`
|
query: `(${dids}) AND -isInPurgatory:true`,
|
||||||
|
fields: ['dataToken']
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
sort: { 'price.ocean': -1 }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return [queryHighest, dids]
|
||||||
}
|
}
|
||||||
|
|
||||||
function sortElements(items: DDO[], sorted: string[]) {
|
function getQueryLatest(chainIds: number[]): SearchQuery {
|
||||||
items.sort(function (a, b) {
|
// TODO: this query needs to adapt to chainIds
|
||||||
return sorted.indexOf(a.dataToken) - sorted.indexOf(b.dataToken)
|
|
||||||
})
|
|
||||||
return items
|
|
||||||
}
|
|
||||||
|
|
||||||
function getQueryLatest(chainIds: number[]) {
|
|
||||||
return {
|
return {
|
||||||
page: 1,
|
page: 1,
|
||||||
offset: 9,
|
offset: 9,
|
||||||
@ -50,6 +50,12 @@ function getQueryLatest(chainIds: number[]) {
|
|||||||
},
|
},
|
||||||
sort: { created: -1 }
|
sort: { created: -1 }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function sortElements(items: DDO[], sorted: string[]) {
|
||||||
|
items.sort(function (a, b) {
|
||||||
|
return sorted.indexOf(a.dataToken) - sorted.indexOf(b.dataToken)
|
||||||
|
})
|
||||||
return items
|
return items
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,7 +108,7 @@ function SectionQueryResult({
|
|||||||
return () => {
|
return () => {
|
||||||
source.cancel()
|
source.cancel()
|
||||||
}
|
}
|
||||||
}, [appConfig.metadataCacheUri, query])
|
}, [appConfig.metadataCacheUri, query, queryData])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className={styles.section}>
|
<section className={styles.section}>
|
||||||
@ -118,27 +124,15 @@ function SectionQueryResult({
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function HomePage(): ReactElement {
|
export default function HomePage(): ReactElement {
|
||||||
// TODO: appConfig.chainIds needs to come from UserPreferences instead
|
|
||||||
const [queryAndDids, setQueryAndDids] = useState<[SearchQuery, string]>()
|
const [queryAndDids, setQueryAndDids] = useState<[SearchQuery, string]>()
|
||||||
|
// TODO: appConfig.chainIds needs to come from UserPreferences instead
|
||||||
const { appConfig } = useSiteMetadata()
|
const { appConfig } = useSiteMetadata()
|
||||||
const { web3Loading, web3Provider } = useWeb3()
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (loading || (web3Loading && web3Provider)) return
|
getQueryHighest(appConfig.chainIds).then((results) => {
|
||||||
getHighestLiquidityDIDs().then((results) => {
|
setQueryAndDids(results)
|
||||||
const queryHighest = {
|
|
||||||
page: 1,
|
|
||||||
offset: 15,
|
|
||||||
query: {
|
|
||||||
query_string: {
|
|
||||||
query: `(${results}) AND -isInPurgatory:true`,
|
|
||||||
fields: ['dataToken']
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setQueryAndDids([queryHighest, results])
|
|
||||||
})
|
})
|
||||||
}, [config.subgraphUri, loading, web3Loading])
|
}, [appConfig.chainIds])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@ -155,7 +149,6 @@ export default function HomePage(): ReactElement {
|
|||||||
<SectionQueryResult
|
<SectionQueryResult
|
||||||
title="Highest Liquidity"
|
title="Highest Liquidity"
|
||||||
query={queryAndDids[0]}
|
query={queryAndDids[0]}
|
||||||
// query={getQueryHighest(appConfig.chainIds)}
|
|
||||||
queryData={queryAndDids[1]}
|
queryData={queryAndDids[1]}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
Loading…
Reference in New Issue
Block a user