Skip to content

Commit dfa11fd

Browse files
authored
fix: mf-6690 modal naviate (#12199)
1 parent 084a19f commit dfa11fd

File tree

5 files changed

+27
-27
lines changed

5 files changed

+27
-27
lines changed

packages/mask/popups/Popup.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const PopupShell = memo(function PopupShell() {
5050
const navigate = useNavigate()
5151
useEffect(() => {
5252
return MaskMessages.events.popupRouteUpdated.on((url) => navigate(url, { replace: true }))
53-
}, [])
53+
}, [navigate])
5454

5555
useEffect(() => {
5656
document.getElementById('app-spinner')?.remove()

packages/mask/popups/components/ActionModal/ActionModalContext.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { useTheme } from '@mui/material'
2-
import { useCallback, useRef, useState } from 'react'
3-
import { useNavigate, useLocation, useSearchParams } from 'react-router-dom'
41
import type { PopupModalRoutes } from '@masknet/shared-base'
52
import { createContainer } from '@masknet/shared-base-ui'
3+
import { useTheme } from '@mui/material'
4+
import { useCallback, useRef, useState } from 'react'
5+
import { useNavigate, useSearchParams } from 'react-router-dom'
66
import urlcat from 'urlcat'
77

88
function useModal() {
@@ -42,16 +42,17 @@ export function useActionModal() {
4242
* Open a modal
4343
*/
4444
export function useModalNavigate() {
45-
const location = useLocation()
46-
const [, setSearchParams] = useSearchParams()
45+
const [searchParams] = useSearchParams()
46+
const navigate = useNavigate()
4747
const openModal = useCallback(
4848
(path: PopupModalRoutes, params?: Record<string, any>) => {
49-
setSearchParams((prev) => {
50-
prev.set('modal', urlcat(path, params || {}))
51-
return prev
52-
})
49+
searchParams.set('modal', urlcat(path, params || {}))
50+
// useLocation().pathname is pathname of modal Routes (maybe since a certain version)
51+
// So we use pathname in hash instead
52+
const mainLocationPathname = location.hash.slice(1).replace(/\?.*$/, '')
53+
navigate(`${mainLocationPathname}?${searchParams.toString()}`)
5354
},
54-
[location, setSearchParams],
55+
[navigate, searchParams],
5556
)
5657
return openModal
5758
}

packages/mask/popups/components/NFTAvatarPicker/index.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1+
import { Trans } from '@lingui/react/macro'
2+
import { Flags } from '@masknet/flags'
13
import { ElementAnchor, NetworkTab, PluginVerifiedWalletStatusBar, RetryHint } from '@masknet/shared'
2-
import { Box, Button, Stack } from '@mui/material'
3-
import { memo, useCallback, useMemo, useState } from 'react'
4-
import { getRegisteredWeb3Networks } from '@masknet/web3-providers'
5-
import { useChainContext, useNetworkContext, useNonFungibleAssets, useWallet } from '@masknet/web3-hooks-base'
6-
import { first, uniqBy } from 'lodash-es'
4+
import { EMPTY_LIST, PopupModalRoutes, type BindingProof, type NetworkPluginID } from '@masknet/shared-base'
75
import { LoadingBase, makeStyles } from '@masknet/theme'
86
import type { Web3Helper } from '@masknet/web3-helpers'
9-
import { CollectionList } from './CollectionList.js'
10-
import { EMPTY_LIST, type NetworkPluginID, PopupModalRoutes, type BindingProof } from '@masknet/shared-base'
7+
import { useChainContext, useNetworkContext, useNonFungibleAssets, useWallet } from '@masknet/web3-hooks-base'
8+
import { getRegisteredWeb3Networks } from '@masknet/web3-providers'
9+
import { Box, Button, Stack } from '@mui/material'
10+
import { first, uniqBy } from 'lodash-es'
11+
import { memo, useCallback, useMemo, useState } from 'react'
1112
import { useModalNavigate } from '../index.js'
12-
import { Flags } from '@masknet/flags'
13-
import { Trans } from '@lingui/react/macro'
13+
import { CollectionList } from './CollectionList.js'
1414

1515
const useStyles = makeStyles()((theme) => ({
1616
picker: {
@@ -54,7 +54,7 @@ export const NFTAvatarPicker = memo<NFTAvatarPickerProps>(function NFTAvatarPick
5454
const chains = useMemo(() => {
5555
const networks = getRegisteredWeb3Networks(pluginID)
5656
return networks.filter((x) => (Flags.support_testnet_switch ? true : x.isMainnet)).map((x) => x.chainId)
57-
}, [])
57+
}, [pluginID])
5858

5959
const [selected, setSelected] = useState<Web3Helper.NonFungibleAssetAll | undefined>()
6060

packages/mask/popups/modals/PersonaSettingModal/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ export const PersonaSettingModal = memo<ActionModalBaseProps>(function PersonaSe
120120
!user.backupPassword ?
121121
PopupModalRoutes.SetBackupPassword
122122
: PopupModalRoutes.verifyBackupPassword,
123-
{ to: PopupRoutes.ExportPrivateKey },
124123
)
125124
}}
126125
/>

packages/mask/popups/modals/VerifyBackupPasswordModal/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { memo, useCallback, useState } from 'react'
1+
import { Trans, useLingui } from '@lingui/react/macro'
2+
import { PopupRoutes } from '@masknet/shared-base'
23
import { ActionButton } from '@masknet/theme'
34
import { Box } from '@mui/material'
4-
import { ActionModal, type ActionModalBaseProps } from '../../components/index.js'
5+
import { memo, useCallback, useState } from 'react'
6+
import { useNavigate } from 'react-router-dom'
57
import { UserContext } from '../../../shared-ui/index.js'
8+
import { ActionModal, type ActionModalBaseProps } from '../../components/index.js'
69
import { PasswordField } from '../../components/PasswordField/index.js'
7-
import { useNavigate } from 'react-router-dom'
8-
import { PopupRoutes } from '@masknet/shared-base'
910
import { MATCH_PASSWORD_RE } from '../../constants.js'
10-
import { Trans, useLingui } from '@lingui/react/macro'
1111

1212
export const VerifyBackupPasswordModal = memo<ActionModalBaseProps>(function VerifyBackupPasswordModal() {
1313
const { t } = useLingui()

0 commit comments

Comments
 (0)