Skip to content

Commit

Permalink
fix: remove remove backend gql data fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
msvstj committed Aug 16, 2023
1 parent 1cd49f1 commit efacfc3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
8 changes: 5 additions & 3 deletions src/components/AccountDrawer/MiniPortfolio/Pools/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { isSupportedChain } from 'constants/chains'
import { RPC_PROVIDERS } from 'constants/providers'
import { BaseContract } from 'ethers/lib/ethers'
import { useBaseEnabledChains } from 'featureFlags/flags/baseEnabled'
import { ContractInput, useUniswapPricesQuery } from 'graphql/data/__generated__/types-and-hooks'
import { ContractInput, UniswapPricesQuery } from 'graphql/data/__generated__/types-and-hooks'
import { toContractInput } from 'graphql/data/util'
import useStablecoinPrice from 'hooks/useStablecoinPrice'
import { useMemo } from 'react'
Expand Down Expand Up @@ -76,8 +76,10 @@ export function usePoolPriceMap(positions: PositionInfo[] | undefined) {
return Object.values(contractMap)
}, [positions])

const { data, loading } = useUniswapPricesQuery({ variables: { contracts }, skip: !contracts.length })

//Update, until GQL chain support returning empty data
// const { data, loading } = useUniswapPricesQuery({ variables: { contracts }, skip: !contracts.length })
const data: UniswapPricesQuery | undefined = {}
const loading = false
const priceMap = useMemo(
() =>
data?.tokens?.reduce((acc: PriceMap, current) => {
Expand Down
23 changes: 13 additions & 10 deletions src/components/AccountDrawer/PrefetchBalancesWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useWeb3React } from '@web3-react/core'
import { usePortfolioBalancesLazyQuery, usePortfolioBalancesQuery } from 'graphql/data/__generated__/types-and-hooks'
import { GQL_MAINNET_CHAINS } from 'graphql/data/util'
import { PortfolioBalancesQuery, usePortfolioBalancesLazyQuery } from 'graphql/data/__generated__/types-and-hooks'
import usePrevious from 'hooks/usePrevious'
import { atom, useAtom } from 'jotai'
import { PropsWithChildren, useCallback, useEffect, useMemo } from 'react'
Expand Down Expand Up @@ -34,14 +33,17 @@ function useHasUpdatedTx(account: string | undefined) {
)
}, [account, currentChainTxs, previousPendingTxs])
}

// UPDATE: until GQL data support - returning empty object
export function useCachedPortfolioBalancesQuery({ account }: { account?: string }) {
return usePortfolioBalancesQuery({
skip: !account,
variables: { ownerAddress: account ?? '', chains: GQL_MAINNET_CHAINS },
fetchPolicy: 'cache-only', // PrefetchBalancesWrapper handles balance fetching/staleness; this component only reads from cache
errorPolicy: 'all',
})
const data: PortfolioBalancesQuery | undefined = {}
const loading = false
return { data, loading }
// return usePortfolioBalancesQuery({
// skip: !account,
// variables: { ownerAddress: account ?? '', chains: GQL_MAINNET_CHAINS },
// fetchPolicy: 'cache-only', // PrefetchBalancesWrapper handles balance fetching/staleness; this component only reads from cache
// errorPolicy: 'all',
// })
}

const hasUnfetchedBalancesAtom = atom<boolean>(true)
Expand All @@ -58,7 +60,8 @@ export default function PrefetchBalancesWrapper({
const [hasUnfetchedBalances, setHasUnfetchedBalances] = useAtom(hasUnfetchedBalancesAtom)
const fetchBalances = useCallback(() => {
if (account) {
prefetchPortfolioBalances({ variables: { ownerAddress: account, chains: GQL_MAINNET_CHAINS } })
// UPDATE: removing prefecth option until GQL chain support
// prefetchPortfolioBalances({ variables: { ownerAddress: account, chains: GQL_MAINNET_CHAINS } })
setHasUnfetchedBalances(false)
}
}, [account, prefetchPortfolioBalances, setHasUnfetchedBalances])
Expand Down
9 changes: 7 additions & 2 deletions src/graphql/data/util.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const CHAIN_ID_TO_BACKEND_NAME: { [key: number]: InterfaceGqlChain } = {
export function chainIdToBackendName(chainId: number | undefined) {
return chainId && CHAIN_ID_TO_BACKEND_NAME[chainId]
? CHAIN_ID_TO_BACKEND_NAME[chainId]
: CHAIN_ID_TO_BACKEND_NAME[ChainId.MAINNET]
: CHAIN_ID_TO_BACKEND_NAME[ChainId.HARMONY]
}

const GQL_CHAINS = [ChainId.MAINNET, ChainId.OPTIMISM, ChainId.POLYGON, ChainId.ARBITRUM_ONE, ChainId.CELO] as const
Expand Down Expand Up @@ -184,7 +184,12 @@ export const BACKEND_SUPPORTED_CHAINS = [
Chain.Optimism,
Chain.Celo,
] as const
export const BACKEND_NOT_YET_SUPPORTED_CHAIN_IDS = [ChainId.BNB, ChainId.AVALANCHE, ChainId.BASE, ChainId.HARMONY] as const
export const BACKEND_NOT_YET_SUPPORTED_CHAIN_IDS = [
ChainId.BNB,
ChainId.AVALANCHE,
ChainId.BASE,
ChainId.HARMONY,
] as const

export function getTokenDetailsURL({
address,
Expand Down

0 comments on commit efacfc3

Please sign in to comment.