diff --git a/index.html b/index.html index fc957827ad..a8a39ca983 100644 --- a/index.html +++ b/index.html @@ -52,78 +52,78 @@ window.EventEmitter = EventEmitter - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/hooks/useSyncTokenSymbolToUrl.ts b/src/hooks/useSyncTokenSymbolToUrl.ts index ecd1616e3a..9499dc686d 100644 --- a/src/hooks/useSyncTokenSymbolToUrl.ts +++ b/src/hooks/useSyncTokenSymbolToUrl.ts @@ -129,7 +129,7 @@ export default function useSyncTokenSymbolToUrl( !disabled ) { // call once - setTimeout(() => findTokenPairFromUrl(chainId)) + // setTimeout(() => findTokenPairFromUrl(chainId)) checkedTokenFromUrlWhenInit.current = true } }, [isLoadedTokenDefault, firstTokenChainId, chainId, network, disabled, findTokenPairFromUrl]) diff --git a/src/pages/SwapV3/PopulatedSwapForm.tsx b/src/pages/SwapV3/PopulatedSwapForm.tsx index 7dc23ccfe9..d3c85f540b 100644 --- a/src/pages/SwapV3/PopulatedSwapForm.tsx +++ b/src/pages/SwapV3/PopulatedSwapForm.tsx @@ -4,34 +4,22 @@ import { useLocation, useSearchParams } from 'react-router-dom' import SwapForm, { SwapFormProps } from 'components/SwapForm' import { APP_PATHS } from 'constants/index' -import useSyncTokenSymbolToUrl from 'hooks/useSyncTokenSymbolToUrl' -import { useAppSelector } from 'state/hooks' import { Field } from 'state/swap/actions' import { useInputCurrency, useOutputCurrency, useSwapActionHandlers } from 'state/swap/hooks' import { useDegenModeManager, usePermitData, useUserSlippageTolerance, useUserTransactionTTL } from 'state/user/hooks' import { useCurrencyBalances } from 'state/wallet/hooks' import { DetailedRouteSummary } from 'types/route' -import useResetCurrenciesOnRemoveImportedTokens from './useResetCurrenciesOnRemoveImportedTokens' - type Props = { routeSummary: DetailedRouteSummary | undefined setRouteSummary: React.Dispatch> - onSelectSuggestedPair: (fromToken: Currency | undefined, toToken: Currency | undefined, amount?: string) => void hidden: boolean onOpenGasToken: () => void } -const PopulatedSwapForm: React.FC = ({ - routeSummary, - setRouteSummary, - hidden, - onSelectSuggestedPair, - onOpenGasToken, -}) => { +const PopulatedSwapForm: React.FC = ({ routeSummary, setRouteSummary, hidden, onOpenGasToken }) => { const currencyIn = useInputCurrency() const currencyOut = useOutputCurrency() - const isSelectTokenManually = useAppSelector(state => state.swap.isSelectTokenManually) const [balanceIn, balanceOut] = useCurrencyBalances( useMemo(() => [currencyIn ?? undefined, currencyOut ?? undefined], [currencyIn, currencyOut]), ) @@ -40,13 +28,11 @@ const PopulatedSwapForm: React.FC = ({ const [slippage] = useUserSlippageTolerance() const permitData = usePermitData(currencyIn?.wrapped.address) - const { onCurrencySelection, onResetSelectCurrency } = useSwapActionHandlers() + const { onCurrencySelection } = useSwapActionHandlers() const { pathname } = useLocation() const [searchParams, setSearchParams] = useSearchParams() const isPartnerSwap = pathname.startsWith(APP_PATHS.PARTNER_SWAP) - useSyncTokenSymbolToUrl(currencyIn, currencyOut, onSelectSuggestedPair, isSelectTokenManually, isPartnerSwap) - useResetCurrenciesOnRemoveImportedTokens(currencyIn, currencyOut, onResetSelectCurrency) const outId = searchParams.get('outputCurrency') || (currencyOut?.isNative ? currencyOut.symbol : currencyOut?.wrapped.address) diff --git a/src/pages/SwapV3/index.tsx b/src/pages/SwapV3/index.tsx index ed810285ce..c409bf6fc2 100644 --- a/src/pages/SwapV3/index.tsx +++ b/src/pages/SwapV3/index.tsx @@ -1,8 +1,7 @@ -import { Currency } from '@kyberswap/ks-sdk-core' import { Trans } from '@lingui/macro' import { ReactNode, Suspense, lazy, useCallback, useEffect, useMemo, useState } from 'react' import Skeleton from 'react-loading-skeleton' -import { useLocation } from 'react-router-dom' +import { useLocation, useNavigate, useSearchParams } from 'react-router-dom' import { Flex, Text } from 'rebass' import styled from 'styled-components' @@ -29,6 +28,7 @@ import { import { APP_PATHS } from 'constants/index' import { useActiveWeb3React } from 'hooks' import { useAllTokens } from 'hooks/Tokens' +import { NETWORKS_INFO } from 'hooks/useChainsConfig' import useParsedQueryString from 'hooks/useParsedQueryString' import useTheme from 'hooks/useTheme' import { BodyWrapper } from 'pages/AppBody' @@ -37,9 +37,6 @@ import CrossChainLink from 'pages/CrossChain/CrossChainLink' import CrossChainTransfersHistory from 'pages/CrossChain/TransfersHistory' import Header from 'pages/SwapV3/Header' import useCurrenciesByPage from 'pages/SwapV3/useCurrenciesByPage' -import { useLimitActionHandlers } from 'state/limit/hooks' -import { Field } from 'state/swap/actions' -import { useDefaultsFromURLSearch, useSwapActionHandlers } from 'state/swap/hooks' import { useTutorialSwapGuide } from 'state/tutorial/hooks' import { useShowTradeRoutes } from 'state/user/hooks' import { DetailedRouteSummary } from 'types/route' @@ -105,6 +102,17 @@ export default function Swap() { const [isSelectCurrencyManually, setIsSelectCurrencyManually] = useState(false) // true when: select token input, output manually or click rotate token. const { pathname } = useLocation() + const [searchParams] = useSearchParams() + const navigate = useNavigate() + useEffect(() => { + const inputCurrency = searchParams.get('inputCurrency') + const outputCurrency = searchParams.get('outputCurrency') + console.log(inputCurrency, outputCurrency) + + if (inputCurrency || outputCurrency) { + navigate(`/swap/${NETWORKS_INFO[chainId].route}/${inputCurrency || ''}-to-${outputCurrency || ''}`) + } + }, [searchParams, chainId, navigate]) const shouldHighlightSwapBox = qs.highlightBox === 'true' @@ -119,42 +127,14 @@ export default function Swap() { const [activeTab, setActiveTab] = useState(getDefaultTab()) - const { onSelectPair: onSelectPairLimit } = useLimitActionHandlers() - useEffect(() => { setActiveTab(getDefaultTab()) }, [getDefaultTab]) - useDefaultsFromURLSearch() - - const { onCurrencySelection, onUserInput } = useSwapActionHandlers() - const tradeRouteComposition = useMemo(() => { return getTradeComposition(chainId, routeSummary?.parsedAmountIn, undefined, routeSummary?.route, defaultTokens) }, [chainId, defaultTokens, routeSummary]) - const handleTypeInput = useCallback( - (value: string) => { - onUserInput(Field.INPUT, value) - }, - [onUserInput], - ) - - const onSelectSuggestedPair = useCallback( - (fromToken: Currency | undefined, toToken: Currency | undefined, amount?: string) => { - if (isLimitPage) { - onSelectPairLimit(fromToken, toToken, amount) - setIsSelectCurrencyManually(true) - return - } - - if (fromToken) onCurrencySelection(Field.INPUT, fromToken) - if (toToken) onCurrencySelection(Field.OUTPUT, toToken) - if (amount) handleTypeInput(amount) - }, - [handleTypeInput, onCurrencySelection, onSelectPairLimit, isLimitPage], - ) - const onBackToSwapTab = () => setActiveTab(getDefaultTab()) return ( @@ -173,7 +153,6 @@ export default function Swap() { > {isSwapPage && (