Skip to content

Commit 882c28d

Browse files
authored
fix(wallet): mf-6749 fix rename handler and wallet name display (#12305)
1 parent 6be8fd3 commit 882c28d

File tree

6 files changed

+26
-45
lines changed

6 files changed

+26
-45
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function WalletRenameDrawer({ wallet, walletName, ...rest }: WalletRenameDrawerP
2222
const [error, setError] = useState<ReactNode>()
2323
const contacts = useContacts()
2424

25-
const [{ loading }, handleClick] = useAsyncFn(async () => {
25+
const [{ loading }, handleConfirm] = useAsyncFn(async () => {
2626
if (!name || !wallet) return
2727
const _name = name.trim()
2828
if (_name.length > 18 || _name.length < 3) {
@@ -92,7 +92,7 @@ function WalletRenameDrawer({ wallet, walletName, ...rest }: WalletRenameDrawerP
9292
<ActionButton
9393
loading={loading}
9494
disabled={loading || !name.length || !!error}
95-
onClick={handleClick}
95+
onClick={handleConfirm}
9696
sx={{ marginTop: '16px' }}>
9797
<Trans>Confirm</Trans>
9898
</ActionButton>

packages/mask/popups/pages/Wallet/SwitchWallet/index.tsx

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import Services from '#services'
2+
import { Trans } from '@lingui/react/macro'
13
import { Icons } from '@masknet/icons'
24
import { DashboardRoutes, ECKeyIdentifier, NetworkPluginID, PopupRoutes, type Wallet } from '@masknet/shared-base'
35
import { ActionButton, makeStyles } from '@masknet/theme'
@@ -8,10 +10,8 @@ import { ProviderType } from '@masknet/web3-shared-evm'
810
import { Box, List, Typography } from '@mui/material'
911
import { memo, useCallback } from 'react'
1012
import { useNavigate } from 'react-router-dom'
11-
import Services from '#services'
1213
import { ActionModal, useActionModal } from '../../../components/index.js'
1314
import { WalletItem } from '../../../components/WalletItem/index.js'
14-
import { Trans } from '@lingui/react/macro'
1515

1616
const useStyles = makeStyles()((theme) => ({
1717
content: {
@@ -49,24 +49,6 @@ const SwitchWallet = memo(function SwitchWallet() {
4949
const wallets = useWallets()
5050
const { chainId } = useChainContext<NetworkPluginID.PLUGIN_EVM>()
5151

52-
const handleClickCreate = useCallback(async () => {
53-
if (!wallets.some((x) => !x.configurable)) {
54-
const hasPaymentPassword = await Services.Wallet.hasPassword()
55-
await browser.tabs.create({
56-
active: true,
57-
url: browser.runtime.getURL(
58-
`/dashboard.html#${
59-
hasPaymentPassword ?
60-
DashboardRoutes.CreateMaskWalletMnemonic
61-
: DashboardRoutes.CreateMaskWalletForm
62-
}`,
63-
),
64-
})
65-
} else {
66-
navigate(PopupRoutes.CreateWallet)
67-
}
68-
}, [wallets])
69-
7052
const handleImport = useCallback(async () => {
7153
await browser.tabs.create({
7254
active: true,
@@ -107,7 +89,9 @@ const SwitchWallet = memo(function SwitchWallet() {
10789
fullWidth
10890
size="small"
10991
variant="outlined"
110-
onClick={handleClickCreate}>
92+
onClick={() => {
93+
navigate(PopupRoutes.CreateWallet)
94+
}}>
11195
<Icons.Wallet size={20} color={theme.palette.maskColor.second} />
11296
<Typography className={classes.actionLabel} component="span">
11397
<Trans>Add Wallet</Trans>

packages/mask/popups/pages/Wallet/WalletSettings/Rename.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
import { Trans } from '@lingui/react/macro'
12
import { Icons } from '@masknet/icons'
3+
import { PersistentStorages } from '@masknet/shared-base'
24
import { useWallet } from '@masknet/web3-hooks-base'
5+
import { isSameAddress } from '@masknet/web3-shared-base'
36
import { Box, ListItem, Typography } from '@mui/material'
4-
import { useStyles } from './useStyles.js'
5-
import { WalletRenameModal } from '../../../modals/modal-controls.js'
6-
import { Trans } from '@lingui/react/macro'
77
import { useWallets } from '@privy-io/react-auth'
88
import { useMemo } from 'react'
9-
import { isSameAddress } from '@masknet/web3-shared-base'
109
import { useSubscription } from 'use-subscription'
11-
import { PersistentStorages } from '@masknet/shared-base'
10+
import { WalletRenameModal } from '../../../modals/modal-controls.js'
11+
import { useStyles } from './useStyles.js'
1212

1313
export function Rename() {
1414
const wallet = useWallet()
@@ -22,13 +22,14 @@ export function Rename() {
2222

2323
if (!wallet) return null
2424

25+
const walletName = wallet.name || (isFireflyWallet ? fireflyAccount.displayName : wallet.name)
2526
return (
2627
<ListItem
2728
className={classes.item}
2829
onClick={() =>
2930
WalletRenameModal.open({
3031
wallet,
31-
walletName: wallet.name || (isFireflyWallet ? fireflyAccount.displayName : wallet.name),
32+
walletName,
3233
title: <Trans>Rename</Trans>,
3334
})
3435
}>
@@ -39,9 +40,7 @@ export function Rename() {
3940
</Typography>
4041
</Box>
4142
<Box className={classes.itemBox}>
42-
<Typography className={classes.itemText}>
43-
{isFireflyWallet ? fireflyAccount.displayName : wallet.name}
44-
</Typography>
43+
<Typography className={classes.itemText}>{walletName}</Typography>
4544
<Icons.ArrowRight color={theme.palette.maskColor.second} size={24} />
4645
</Box>
4746
</ListItem>

packages/mask/popups/pages/Wallet/WalletSettings/index.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
import { Trans, useLingui } from '@lingui/react/macro'
12
import { Icons } from '@masknet/icons'
23
import { EMPTY_LIST, PersistentStorages, PopupModalRoutes } from '@masknet/shared-base'
34
import { ActionButton } from '@masknet/theme'
45
import { useWallet, useWallets } from '@masknet/web3-hooks-base'
5-
import { useWallets as usePrivyWallets } from '@privy-io/react-auth'
66
import { isSameAddress } from '@masknet/web3-shared-base'
77
import { Box, List, Typography } from '@mui/material'
8+
import { useWallets as usePrivyWallets } from '@privy-io/react-auth'
89
import { first } from 'lodash-es'
910
import { memo, useCallback, useMemo } from 'react'
11+
import { useSubscription } from 'use-subscription'
1012
import { useModalNavigate } from '../../../components/index.js'
13+
import { WalletAvatar } from '../../../components/WalletAvatar/index.js'
1114
import { useTitle } from '../../../hooks/index.js'
1215
import { WalletRemoveModal } from '../../../modals/modal-controls.js'
1316
import { AutoLock } from './AutoLock.js'
@@ -16,14 +19,11 @@ import { ChangeNetwork } from './ChangeNetwork.js'
1619
import { ChangePaymentPassword } from './ChangePaymentPassword.js'
1720
import { ConnectedOrigins } from './ConnectedOrigins.js'
1821
import { Contacts } from './Contacts.js'
22+
import { DisablePermit } from './DisablePermit.js'
23+
import { HidingScamTx } from './HidingScamTx.js'
1924
import { Rename } from './Rename.js'
2025
import { ShowPrivateKey } from './ShowPrivateKey.js'
2126
import { useStyles } from './useStyles.js'
22-
import { HidingScamTx } from './HidingScamTx.js'
23-
import { Trans, useLingui } from '@lingui/react/macro'
24-
import { DisablePermit } from './DisablePermit.js'
25-
import { useSubscription } from 'use-subscription'
26-
import { WalletAvatar } from '../../../components/WalletAvatar/index.js'
2727

2828
function getPathIndex(path?: string) {
2929
const rawIndex = path?.split('/').pop()
@@ -66,6 +66,7 @@ export const Component = memo(function WalletSettings() {
6666
}, [allWallets, wallet?.mnemonicId])
6767

6868
if (!wallet) return null
69+
const walletName = wallet.name || (isFireflyWallet ? fireflyAccount.displayName : wallet.name)
6970

7071
// The wallet has derivationPath is also the one with minimum derivation path
7172
const isTheFirstWallet = wallet.mnemonicId ? isSameAddress(first(siblingWallets)?.address, wallet.address) : false
@@ -76,9 +77,7 @@ export const Component = memo(function WalletSettings() {
7677
<Box className={classes.primaryItemBox}>
7778
<WalletAvatar size={24} address={wallet.address} />
7879
<div className={classes.walletInfo}>
79-
<Typography className={classes.primaryItemText}>
80-
{isFireflyWallet ? fireflyAccount.displayName : wallet.name}
81-
</Typography>
80+
<Typography className={classes.primaryItemText}>{walletName}</Typography>
8281
<Typography className={classes.primaryItemSecondText}>{wallet.address}</Typography>
8382
</div>
8483
</Box>

packages/mask/popups/pages/Wallet/components/WalletHeader/UI.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ export const WalletHeaderUI = memo<WalletHeaderUIProps>(function WalletHeaderUI(
157157
const addressLink = EVMExplorerResolver.addressLink(chainId, wallet.address)
158158

159159
const networkName = currentNetwork?.name || currentNetwork?.fullName
160+
const walletName = wallet.name || (isFireflyWallet ? fireflyAccount.displayName : wallet.name)
160161
return (
161162
<Box className={classes.container}>
162163
<div className={classes.topBar}>
@@ -211,9 +212,7 @@ export const WalletHeaderUI = memo<WalletHeaderUIProps>(function WalletHeaderUI(
211212
<WalletAvatar address={wallet.address} size={30} />
212213
<Box ml={0.5} overflow="hidden">
213214
<TextOverflowTooltip title={wallet.name}>
214-
<Typography className={classes.nickname}>
215-
{isFireflyWallet ? fireflyAccount.displayName : wallet.name}
216-
</Typography>
215+
<Typography className={classes.nickname}>{walletName}</Typography>
217216
</TextOverflowTooltip>
218217
<Typography className={classes.identifier}>
219218
<FormattedAddress address={wallet.address} formatter={formatEthereumAddress} size={4} />

packages/web3-providers/src/Web3/EVM/providers/MaskWallet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class MaskWalletProvider extends BaseHostedProvider {
5252
const privyWallets = await Privy.getEvmWallets()
5353
const formattedPrivyWallets: Wallet[] = privyWallets.map((wallet) => ({
5454
id: wallet.address,
55-
name: '',
55+
name: this.walletStorage.wallets.value.find((w) => isSameAddress(w.address, wallet.address))?.name || '',
5656
source: ImportSource.Privy,
5757
address: wallet.address,
5858
configurable: false,

0 commit comments

Comments
 (0)