From d950b2d522a12c9d5248aed87d8110d9de3b9276 Mon Sep 17 00:00:00 2001 From: iamoskvin Date: Fri, 17 May 2024 15:47:45 +0300 Subject: [PATCH] parallel requests --- src/pages/Pool/index.tsx | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/pages/Pool/index.tsx b/src/pages/Pool/index.tsx index 44a25aab..002752df 100644 --- a/src/pages/Pool/index.tsx +++ b/src/pages/Pool/index.tsx @@ -22,6 +22,7 @@ import { getClient } from 'apollo/client' import { ChainId } from '@vnaysn/jediswap-sdk-core' import { useDefaultActiveTokens } from 'hooks/Tokens' import { PositionDetails } from './PositionDetails' +import { ApolloQueryResult } from '@apollo/client' export function PositionsLoadingPlaceholder() { return ( @@ -88,21 +89,32 @@ export default function Pool() { const allTokens = useDefaultActiveTokens(chainIdFinal) const whitelistedIds = Object.keys(allTokens) const graphqlClient = getClient(chainIdFinal) - //fetch pools data + //fetch pools data and rewards data useEffect(() => { let ignore = false; const getPoolsData = async () => { if (whitelistedIds.length === 0) { return } - const poolsDataRaw = await getAllPools(graphqlClient, [...whitelistedIds, ETH_ADDRESS]) //add ETH token - const rewardsResp = await graphqlClient.query({ - query: STRK_REWARDS_DATA(), - fetchPolicy: 'cache-first' - }) - const jediRewards = rewardsResp?.data?.strkGrantData + const requests = [ + getAllPools(graphqlClient, [...whitelistedIds, ETH_ADDRESS]), //add ETH token + graphqlClient.query({ + query: STRK_REWARDS_DATA(), + fetchPolicy: 'cache-first' + }) + ]; + const [poolsDataRawResult, rewardsRespResult] = await Promise.allSettled(requests); + let poolsDataRaw: any = null + if (poolsDataRawResult.status === "fulfilled") { + poolsDataRaw = poolsDataRawResult.value as ApolloQueryResult;; + } + let jediRewards: any = null; + if (rewardsRespResult.status === "fulfilled") { + const rewardsResp = rewardsRespResult.value as ApolloQueryResult; + jediRewards = rewardsResp.data?.strkGrantData; + } const poolsData: any = {} - poolsDataRaw?.forEach((data) => { + poolsDataRaw?.forEach((data: any) => { const rewardName = data?.token0?.symbol + '/' + data?.token1?.symbol const rewardsData = jediRewards?.[rewardName] @@ -249,13 +261,13 @@ export default function Pool() { - setShowMyPositions(false)} style={{fontSize: "0.875rem"}}> + setShowMyPositions(false)} style={{ fontSize: "0.875rem" }}> Top Pools - setShowMyPositions(true)} style={{fontSize: "0.875rem"}}> + setShowMyPositions(true)} style={{ fontSize: "0.875rem" }}> My Positions - + + New position