From 308cca189732aab752f3a8b4a76e42bfdfd49a87 Mon Sep 17 00:00:00 2001 From: ryanml Date: Mon, 18 Oct 2021 10:31:34 -0700 Subject: [PATCH] Preventing swaps data re-fetch when navigating back to home screeen (#12370) --- ui/pages/swaps/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ui/pages/swaps/index.js b/ui/pages/swaps/index.js index 03772d4df..d10cf24e4 100644 --- a/ui/pages/swaps/index.js +++ b/ui/pages/swaps/index.js @@ -118,6 +118,7 @@ export default function Swap() { const chainId = useSelector(getCurrentChainId); const isSwapsChain = useSelector(getIsSwapsChain); const useNewSwapsApi = useSelector(getUseNewSwapsApi); + const prevUseNewSwapsApi = useRef(useNewSwapsApi); const networkAndAccountSupports1559 = useSelector( checkNetworkAndAccountSupports1559, ); @@ -193,7 +194,7 @@ export default function Swap() { // eslint-disable-next-line useEffect(() => { - if (isFeatureFlagLoaded) { + if (isFeatureFlagLoaded && prevUseNewSwapsApi.current === useNewSwapsApi) { fetchTokens(chainId, useNewSwapsApi) .then((tokens) => { dispatch(setSwapsTokens(tokens)); @@ -214,6 +215,7 @@ export default function Swap() { dispatch(prepareToLeaveSwaps()); }; } + prevUseNewSwapsApi.current = useNewSwapsApi; }, [ dispatch, chainId,