mirror of
https://github.com/oceanprotocol/market.git
synced 2024-11-15 09:44:53 +01:00
frontpage tweaks preparing querying for liquidity
This commit is contained in:
parent
6949547043
commit
8fbd98260b
@ -3,38 +3,59 @@ import SearchBar from '../molecules/SearchBar'
|
|||||||
import styles from './Home.module.css'
|
import styles from './Home.module.css'
|
||||||
import { MetadataStore, Logger } from '@oceanprotocol/lib'
|
import { MetadataStore, Logger } from '@oceanprotocol/lib'
|
||||||
import AssetList from '../organisms/AssetList'
|
import AssetList from '../organisms/AssetList'
|
||||||
import { QueryResult } from '@oceanprotocol/lib/dist/node/metadatastore/MetadataStore'
|
import {
|
||||||
|
QueryResult,
|
||||||
|
SearchQuery
|
||||||
|
} from '@oceanprotocol/lib/dist/node/metadatastore/MetadataStore'
|
||||||
import Container from '../atoms/Container'
|
import Container from '../atoms/Container'
|
||||||
import Loader from '../atoms/Loader'
|
import Loader from '../atoms/Loader'
|
||||||
import { useOcean } from '@oceanprotocol/react'
|
import { useOcean } from '@oceanprotocol/react'
|
||||||
|
|
||||||
async function getLatestAssets(metadataStoreUri: string) {
|
const queryHighest = {
|
||||||
|
page: 1,
|
||||||
|
offset: 3,
|
||||||
|
query: {},
|
||||||
|
sort: { dtPrice: 1 }
|
||||||
|
}
|
||||||
|
|
||||||
|
const queryLatest = {
|
||||||
|
page: 1,
|
||||||
|
offset: 20,
|
||||||
|
query: {},
|
||||||
|
sort: { created: -1 }
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getAssets(query: SearchQuery, metadataStoreUri: string) {
|
||||||
try {
|
try {
|
||||||
const metadataStore = new MetadataStore(metadataStoreUri, Logger)
|
const metadataStore = new MetadataStore(metadataStoreUri, Logger)
|
||||||
|
|
||||||
const result = await metadataStore.queryMetadata({
|
const result = await metadataStore.queryMetadata(query)
|
||||||
page: 1,
|
|
||||||
// TODO: reduce assets here, once faulty assets pushed by external devs are removed
|
|
||||||
offset: 100,
|
|
||||||
query: {},
|
|
||||||
sort: { created: -1 }
|
|
||||||
})
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error.message)
|
Logger.error(error.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function HomePage(): ReactElement {
|
export default function HomePage(): ReactElement {
|
||||||
const { config } = useOcean()
|
const { config } = useOcean()
|
||||||
const [queryResult, setQueryResult] = useState<QueryResult>()
|
const [queryResultLatest, setQueryResultLatest] = useState<QueryResult>()
|
||||||
|
const [queryResultHighest, setQueryResultHighest] = useState<QueryResult>()
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function init() {
|
async function init() {
|
||||||
const results = await getLatestAssets(config.metadataStoreUri)
|
const queryResultHighest = await getAssets(
|
||||||
setQueryResult(results)
|
queryHighest,
|
||||||
|
config.metadataStoreUri
|
||||||
|
)
|
||||||
|
setQueryResultHighest(queryResultHighest)
|
||||||
|
|
||||||
|
const queryResultLatest = await getAssets(
|
||||||
|
queryLatest,
|
||||||
|
config.metadataStoreUri
|
||||||
|
)
|
||||||
|
setQueryResultLatest(queryResultLatest)
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
init()
|
init()
|
||||||
@ -47,11 +68,20 @@ export default function HomePage(): ReactElement {
|
|||||||
</Container>
|
</Container>
|
||||||
|
|
||||||
<section className={styles.latest}>
|
<section className={styles.latest}>
|
||||||
<h3>Latest Data Sets</h3>
|
<h3>Highest Liquidity</h3>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<Loader />
|
<Loader />
|
||||||
) : (
|
) : (
|
||||||
queryResult && <AssetList queryResult={queryResult} />
|
queryResultHighest && <AssetList queryResult={queryResultHighest} />
|
||||||
|
)}
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section className={styles.latest}>
|
||||||
|
<h3>Latest</h3>
|
||||||
|
{loading ? (
|
||||||
|
<Loader />
|
||||||
|
) : (
|
||||||
|
queryResultLatest && <AssetList queryResult={queryResultLatest} />
|
||||||
)}
|
)}
|
||||||
</section>
|
</section>
|
||||||
</>
|
</>
|
||||||
|
Loading…
Reference in New Issue
Block a user