Skip to content

Commit

Permalink
Fix: improve chain switch redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh committed May 29, 2024
1 parent 050e58b commit 9bc2c69
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/components/common/NetworkSelector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ import { type ReactElement, useMemo } from 'react'
import { useCallback } from 'react'
import { AppRoutes } from '@/config/routes'
import { trackEvent, OVERVIEW_EVENTS } from '@/services/analytics'
import useWallet from '@/hooks/wallets/useWallet'

const NetworkSelector = (props: { onChainSelect?: () => void }): ReactElement => {
const isDarkMode = useDarkMode()
const theme = useTheme()
const { configs } = useChains()
const chainId = useChainId()
const router = useRouter()
const isWalletConnected = !!useWallet()

const [testNets, prodNets] = useMemo(() => partition(configs, (config) => config.isTestnet), [configs])

Expand All @@ -30,7 +32,11 @@ const NetworkSelector = (props: { onChainSelect?: () => void }): ReactElement =>
const shouldKeepPath = !router.query.safe

const route = {
pathname: shouldKeepPath ? router.pathname : AppRoutes.index,
pathname: shouldKeepPath
? router.pathname
: isWalletConnected
? AppRoutes.welcome.accounts
: AppRoutes.welcome.index,
query: {
chain: shortName,
} as {
Expand All @@ -45,7 +51,7 @@ const NetworkSelector = (props: { onChainSelect?: () => void }): ReactElement =>

return route
},
[router],
[router, isWalletConnected],
)

const onChange = (event: SelectChangeEvent) => {
Expand Down

0 comments on commit 9bc2c69

Please sign in to comment.