Skip to content

Commit

Permalink
fix: sync app chainId and swapform chainId when not connected
Browse files Browse the repository at this point in the history
  • Loading branch information
viet-nv committed Nov 14, 2023
1 parent 21f51b2 commit f96862f
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/pages/PartnerSwap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ import {
import { TRANSACTION_STATE_DEFAULT } from 'constants/index'
import { SUPPORTED_NETWORKS } from 'constants/networks'
import { DEFAULT_OUTPUT_TOKEN_BY_CHAIN, NativeCurrencies } from 'constants/tokens'
import { useActiveWeb3React } from 'hooks'
import { useAllTokens, useCurrencyV2 } from 'hooks/Tokens'
import useTheme from 'hooks/useTheme'
import { useChangeNetwork } from 'hooks/web3/useChangeNetwork'
import { BodyWrapper } from 'pages/AppBody'
import CrossChain from 'pages/CrossChain'
import CrossChainLink from 'pages/CrossChain/CrossChainLink'
Expand Down Expand Up @@ -86,6 +88,8 @@ export const RoutingIconWrapper = styled(RoutingIcon)`
`

export default function Swap() {
const { account, chainId: walletChainId } = useActiveWeb3React()
const { changeNetwork } = useChangeNetwork()
const [searchParams, setSearchParams] = useSearchParams()

const chainIdFromParam = searchParams.get('chainId')
Expand All @@ -94,6 +98,13 @@ export default function Swap() {
const expectedChainId =
chainIdFromParam && SUPPORTED_NETWORKS.includes(+chainIdFromParam) ? +chainIdFromParam : ChainId.MAINNET

// sync form chainId and wallet chainId when disconnected
useEffect(() => {
if (!account && walletChainId !== expectedChainId) {
changeNetwork(expectedChainId)
}
}, [account, walletChainId, expectedChainId, changeNetwork])

const currencyIn =
useCurrencyV2(inputTokenFromParam || undefined, expectedChainId) || NativeCurrencies[expectedChainId as ChainId]
const currencyOut =
Expand Down Expand Up @@ -135,20 +146,8 @@ export default function Swap() {

const theme = useTheme()

// dismiss warning if all imported tokens are in active lists
const allTokens = useAllTokens()

// const handleConfirmTokenWarning = useCallback(
// (tokens: Currency[]) => {
// // handleDismissTokenWarning()
// if (isLimitPage) {
// onSelectPairLimit(tokens[0], tokens[1])
// setIsSelectCurrencyManually(true)
// }
// },
// [isLimitPage, onSelectPairLimit],
// )

const onBackToSwapTab = () => setActiveTab(previousTab || TAB.SWAP)

const tradeRouteComposition = useMemo(() => {
Expand Down

0 comments on commit f96862f

Please sign in to comment.