From cf09e80934afec82f077fef30ec846b02ec15149 Mon Sep 17 00:00:00 2001
From: eddie <66155195+just-toby@users.noreply.github.com>
Date: Mon, 18 Sep 2023 14:49:39 -0700
Subject: [PATCH] fix: fetch balances when opening token selector in LP page
(#7321)
* fix: fetch balances when opening token selector in LP page
* fix: move PrefetchBalancesWrapper
---
.../AccountDrawer/AuthenticatedHeader.tsx | 2 +-
.../MiniPortfolio/Tokens/index.tsx | 2 +-
.../SwapCurrencyInputPanel.tsx | 2 +-
src/components/CurrencyInputPanel/index.tsx | 84 ++++++++++---------
.../PrefetchBalancesWrapper.tsx | 2 +-
src/components/SearchModal/CurrencySearch.tsx | 2 +-
src/components/Web3Status/index.tsx | 2 +-
7 files changed, 51 insertions(+), 45 deletions(-)
rename src/components/{AccountDrawer => PrefetchBalancesWrapper}/PrefetchBalancesWrapper.tsx (97%)
diff --git a/src/components/AccountDrawer/AuthenticatedHeader.tsx b/src/components/AccountDrawer/AuthenticatedHeader.tsx
index 79edfd363c..d82cf1778e 100644
--- a/src/components/AccountDrawer/AuthenticatedHeader.tsx
+++ b/src/components/AccountDrawer/AuthenticatedHeader.tsx
@@ -31,11 +31,11 @@ import { useCloseModal, useFiatOnrampAvailability, useOpenModal, useToggleModal
import { ApplicationModal } from '../../state/application/reducer'
import { useUserHasAvailableClaim, useUserUnclaimedAmount } from '../../state/claim/hooks'
import StatusIcon from '../Identicon/StatusIcon'
+import { useCachedPortfolioBalancesQuery } from '../PrefetchBalancesWrapper/PrefetchBalancesWrapper'
import { useToggleAccountDrawer } from '.'
import IconButton, { IconHoverText, IconWithConfirmTextButton } from './IconButton'
import MiniPortfolio from './MiniPortfolio'
import { portfolioFadeInAnimation } from './MiniPortfolio/PortfolioRow'
-import { useCachedPortfolioBalancesQuery } from './PrefetchBalancesWrapper'
const AuthenticatedHeaderWrapper = styled.div`
padding: 20px 16px;
diff --git a/src/components/AccountDrawer/MiniPortfolio/Tokens/index.tsx b/src/components/AccountDrawer/MiniPortfolio/Tokens/index.tsx
index abd7a23894..c87b400f40 100644
--- a/src/components/AccountDrawer/MiniPortfolio/Tokens/index.tsx
+++ b/src/components/AccountDrawer/MiniPortfolio/Tokens/index.tsx
@@ -1,6 +1,6 @@
import { BrowserEvent, InterfaceElementName, SharedEventName } from '@uniswap/analytics-events'
import { TraceEvent } from 'analytics'
-import { useCachedPortfolioBalancesQuery } from 'components/AccountDrawer/PrefetchBalancesWrapper'
+import { useCachedPortfolioBalancesQuery } from 'components/PrefetchBalancesWrapper/PrefetchBalancesWrapper'
import Row from 'components/Row'
import { DeltaArrow, formatDelta } from 'components/Tokens/TokenDetails/Delta'
import { TokenBalance } from 'graphql/data/__generated__/types-and-hooks'
diff --git a/src/components/CurrencyInputPanel/SwapCurrencyInputPanel.tsx b/src/components/CurrencyInputPanel/SwapCurrencyInputPanel.tsx
index 30f08bd967..1e0ab78e32 100644
--- a/src/components/CurrencyInputPanel/SwapCurrencyInputPanel.tsx
+++ b/src/components/CurrencyInputPanel/SwapCurrencyInputPanel.tsx
@@ -4,10 +4,10 @@ import { Currency, CurrencyAmount, Percent } from '@uniswap/sdk-core'
import { Pair } from '@uniswap/v2-sdk'
import { useWeb3React } from '@web3-react/core'
import { TraceEvent } from 'analytics'
-import PrefetchBalancesWrapper from 'components/AccountDrawer/PrefetchBalancesWrapper'
import { AutoColumn } from 'components/Column'
import { LoadingOpacityContainer, loadingOpacityMixin } from 'components/Loader/styled'
import CurrencyLogo from 'components/Logo/CurrencyLogo'
+import PrefetchBalancesWrapper from 'components/PrefetchBalancesWrapper/PrefetchBalancesWrapper'
import Tooltip from 'components/Tooltip'
import { isSupportedChain } from 'constants/chains'
import ms from 'ms'
diff --git a/src/components/CurrencyInputPanel/index.tsx b/src/components/CurrencyInputPanel/index.tsx
index ff04c27104..028a7e58c8 100644
--- a/src/components/CurrencyInputPanel/index.tsx
+++ b/src/components/CurrencyInputPanel/index.tsx
@@ -5,6 +5,7 @@ import { Pair } from '@uniswap/v2-sdk'
import { useWeb3React } from '@web3-react/core'
import { TraceEvent } from 'analytics'
import { LoadingOpacityContainer, loadingOpacityMixin } from 'components/Loader/styled'
+import PrefetchBalancesWrapper from 'components/PrefetchBalancesWrapper/PrefetchBalancesWrapper'
import { isSupportedChain } from 'constants/chains'
import { darken } from 'polished'
import { ReactNode, useCallback, useState } from 'react'
@@ -230,45 +231,50 @@ export default function CurrencyInputPanel({
/>
)}
- {
- if (onCurrencySelect) {
- setModalOpen(true)
- }
- }}
- pointerEvents={!onCurrencySelect ? 'none' : undefined}
- >
-
-
- {pair ? (
-
-
-
- ) : (
- currency &&
- )}
- {pair ? (
-
- {pair?.token0.symbol}:{pair?.token1.symbol}
-
- ) : (
-
- {(currency && currency.symbol && currency.symbol.length > 20
- ? currency.symbol.slice(0, 4) +
- '...' +
- currency.symbol.slice(currency.symbol.length - 5, currency.symbol.length)
- : currency?.symbol) || Select a token}
-
- )}
-
- {onCurrencySelect && }
-
-
+
+ {
+ if (onCurrencySelect) {
+ setModalOpen(true)
+ }
+ }}
+ pointerEvents={!onCurrencySelect ? 'none' : undefined}
+ >
+
+
+ {pair ? (
+
+
+
+ ) : (
+ currency &&
+ )}
+ {pair ? (
+
+ {pair?.token0.symbol}:{pair?.token1.symbol}
+
+ ) : (
+
+ {(currency && currency.symbol && currency.symbol.length > 20
+ ? currency.symbol.slice(0, 4) +
+ '...' +
+ currency.symbol.slice(currency.symbol.length - 5, currency.symbol.length)
+ : currency?.symbol) || Select a token}
+
+ )}
+
+ {onCurrencySelect && }
+
+
+
{Boolean(!hideInput && !hideBalance && currency) && (
diff --git a/src/components/AccountDrawer/PrefetchBalancesWrapper.tsx b/src/components/PrefetchBalancesWrapper/PrefetchBalancesWrapper.tsx
similarity index 97%
rename from src/components/AccountDrawer/PrefetchBalancesWrapper.tsx
rename to src/components/PrefetchBalancesWrapper/PrefetchBalancesWrapper.tsx
index eb68b527a9..933caad16b 100644
--- a/src/components/AccountDrawer/PrefetchBalancesWrapper.tsx
+++ b/src/components/PrefetchBalancesWrapper/PrefetchBalancesWrapper.tsx
@@ -5,7 +5,7 @@ import usePrevious from 'hooks/usePrevious'
import { atom, useAtom } from 'jotai'
import { PropsWithChildren, useCallback, useEffect } from 'react'
-import { usePendingActivity } from './MiniPortfolio/Activity/hooks'
+import { usePendingActivity } from '../AccountDrawer/MiniPortfolio/Activity/hooks'
/** Returns true if the number of pending activities has decreased */
function useHasUpdatedTx() {
diff --git a/src/components/SearchModal/CurrencySearch.tsx b/src/components/SearchModal/CurrencySearch.tsx
index 010d60661d..8bd3dc5a4b 100644
--- a/src/components/SearchModal/CurrencySearch.tsx
+++ b/src/components/SearchModal/CurrencySearch.tsx
@@ -4,7 +4,7 @@ import { InterfaceEventName, InterfaceModalName } from '@uniswap/analytics-event
import { Currency, Token } from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core'
import { Trace } from 'analytics'
-import { useCachedPortfolioBalancesQuery } from 'components/AccountDrawer/PrefetchBalancesWrapper'
+import { useCachedPortfolioBalancesQuery } from 'components/PrefetchBalancesWrapper/PrefetchBalancesWrapper'
import { supportedChainIdFromGQLChain } from 'graphql/data/util'
import useDebounce from 'hooks/useDebounce'
import { useOnClickOutside } from 'hooks/useOnClickOutside'
diff --git a/src/components/Web3Status/index.tsx b/src/components/Web3Status/index.tsx
index e4cf12b149..efcf1c3a7b 100644
--- a/src/components/Web3Status/index.tsx
+++ b/src/components/Web3Status/index.tsx
@@ -4,9 +4,9 @@ import { useWeb3React } from '@web3-react/core'
import { sendAnalyticsEvent, TraceEvent } from 'analytics'
import PortfolioDrawer, { useAccountDrawer } from 'components/AccountDrawer'
import { usePendingActivity } from 'components/AccountDrawer/MiniPortfolio/Activity/hooks'
-import PrefetchBalancesWrapper from 'components/AccountDrawer/PrefetchBalancesWrapper'
import Loader from 'components/Icons/LoadingSpinner'
import { IconWrapper } from 'components/Identicon/StatusIcon'
+import PrefetchBalancesWrapper from 'components/PrefetchBalancesWrapper/PrefetchBalancesWrapper'
import { getConnection } from 'connection'
import useENSName from 'hooks/useENSName'
import useLast from 'hooks/useLast'