mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
Display highest liquidity assets fix (#802)
* correct offset set, empty result for no network selected * network-only policy used, logs deleted * cache and network policy used * Update src/components/pages/Home.tsx Co-authored-by: Matthias Kretschmann <m@kretschmann.io> Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
This commit is contained in:
parent
e500772d21
commit
e703f9b03d
@ -21,10 +21,10 @@ import styles from './Home.module.css'
|
|||||||
async function getQueryHighest(
|
async function getQueryHighest(
|
||||||
chainIds: number[]
|
chainIds: number[]
|
||||||
): Promise<[SearchQuery, string]> {
|
): Promise<[SearchQuery, string]> {
|
||||||
const dids = await getHighestLiquidityDIDs(chainIds)
|
const [dids, didsLength] = await getHighestLiquidityDIDs(chainIds)
|
||||||
const queryHighest = {
|
const queryHighest = {
|
||||||
page: 1,
|
page: 1,
|
||||||
offset: dids.length,
|
offset: didsLength,
|
||||||
query: {
|
query: {
|
||||||
query_string: {
|
query_string: {
|
||||||
query: `(${dids}) AND (${transformChainIdsListToQuery(
|
query: `(${dids}) AND (${transformChainIdsListToQuery(
|
||||||
@ -72,6 +72,7 @@ function SectionQueryResult({
|
|||||||
queryData?: string
|
queryData?: string
|
||||||
}) {
|
}) {
|
||||||
const { appConfig } = useSiteMetadata()
|
const { appConfig } = useSiteMetadata()
|
||||||
|
const { chainIds } = useUserPreferences()
|
||||||
const [result, setResult] = useState<QueryResult>()
|
const [result, setResult] = useState<QueryResult>()
|
||||||
const [loading, setLoading] = useState<boolean>()
|
const [loading, setLoading] = useState<boolean>()
|
||||||
|
|
||||||
@ -80,20 +81,31 @@ function SectionQueryResult({
|
|||||||
const source = axios.CancelToken.source()
|
const source = axios.CancelToken.source()
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
try {
|
if (chainIds.length === 0) {
|
||||||
setLoading(true)
|
const result: QueryResult = {
|
||||||
const result = await queryMetadata(query, source.token)
|
results: [],
|
||||||
if (queryData && result.totalResults > 0) {
|
page: 0,
|
||||||
const searchDIDs = queryData.split(' ')
|
totalPages: 0,
|
||||||
const sortedAssets = sortElements(result.results, searchDIDs)
|
totalResults: 0
|
||||||
const overflow = sortedAssets.length - 9
|
|
||||||
sortedAssets.splice(sortedAssets.length - overflow, overflow)
|
|
||||||
result.results = sortedAssets
|
|
||||||
}
|
}
|
||||||
setResult(result)
|
setResult(result)
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
} catch (error) {
|
} else {
|
||||||
Logger.log(error.message)
|
try {
|
||||||
|
setLoading(true)
|
||||||
|
const result = await queryMetadata(query, source.token)
|
||||||
|
if (queryData && result.totalResults > 0) {
|
||||||
|
const searchDIDs = queryData.split(' ')
|
||||||
|
const sortedAssets = sortElements(result.results, searchDIDs)
|
||||||
|
const overflow = sortedAssets.length - 9
|
||||||
|
sortedAssets.splice(sortedAssets.length - overflow, overflow)
|
||||||
|
result.results = sortedAssets
|
||||||
|
}
|
||||||
|
setResult(result)
|
||||||
|
setLoading(false)
|
||||||
|
} catch (error) {
|
||||||
|
Logger.error(error.message)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
init()
|
init()
|
||||||
|
@ -151,7 +151,7 @@ export function getQueryContext(chainId: number): OperationContext {
|
|||||||
url: `${getSubgraphUri(
|
url: `${getSubgraphUri(
|
||||||
Number(chainId)
|
Number(chainId)
|
||||||
)}/subgraphs/name/oceanprotocol/ocean-subgraph`,
|
)}/subgraphs/name/oceanprotocol/ocean-subgraph`,
|
||||||
requestPolicy: 'cache-first'
|
requestPolicy: 'cache-and-network'
|
||||||
}
|
}
|
||||||
|
|
||||||
return queryContext
|
return queryContext
|
||||||
@ -469,7 +469,7 @@ export async function getAssetsBestPrices(
|
|||||||
|
|
||||||
export async function getHighestLiquidityDIDs(
|
export async function getHighestLiquidityDIDs(
|
||||||
chainIds: number[]
|
chainIds: number[]
|
||||||
): Promise<string> {
|
): Promise<[string, number]> {
|
||||||
const didList: string[] = []
|
const didList: string[] = []
|
||||||
let highestLiquidiyAssets: HighestLiquidityAssetsPools[] = []
|
let highestLiquidiyAssets: HighestLiquidityAssetsPools[] = []
|
||||||
for (const chain of chainIds) {
|
for (const chain of chainIds) {
|
||||||
@ -495,5 +495,5 @@ export async function getHighestLiquidityDIDs(
|
|||||||
.replace(/"/g, '')
|
.replace(/"/g, '')
|
||||||
.replace(/(\[|\])/g, '')
|
.replace(/(\[|\])/g, '')
|
||||||
.replace(/(did:op:)/g, '0x')
|
.replace(/(did:op:)/g, '0x')
|
||||||
return searchDids
|
return [searchDids, didList.length]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user