Skip to content

Commit fa5fdb4

Browse files
authored
fix: firefly wallet avatar and name (#12298)
* fix(popups): mf-6747 show firefly avatar and display name in wallet UI * fix(wallet-settings): mf-6746 show firefly displayName and disable backup use firefly account displayName in wallet UI and rename modal, pass walletName to modal, disable ShowPrivateKey for firefly wallets, and clear default privy wallet name.
1 parent 21d7659 commit fa5fdb4

File tree

8 files changed

+123
-25
lines changed

8 files changed

+123
-25
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { Icons } from '@masknet/icons'
2+
import { Image } from '@masknet/shared'
3+
import { PersistentStorages } from '@masknet/shared-base'
4+
import { makeStyles } from '@masknet/theme'
5+
import { isSameAddress } from '@masknet/web3-shared-base'
6+
import { useWallets } from '@privy-io/react-auth'
7+
import { memo, useMemo } from 'react'
8+
import { useSubscription } from 'use-subscription'
9+
10+
const useStyles = makeStyles()((theme) => ({
11+
container: {
12+
position: 'relative',
13+
},
14+
badgeIcon: {
15+
position: 'absolute',
16+
right: -3,
17+
bottom: -1,
18+
border: `1px solid ${theme.palette.common.white}`,
19+
borderRadius: '50%',
20+
},
21+
}))
22+
23+
interface Props {
24+
size?: number
25+
address: string
26+
}
27+
export const WalletAvatar = memo<Props>(function WalletAvatar({ size = 30, address }) {
28+
const { classes } = useStyles()
29+
const { wallets: fireflyWallets } = useWallets()
30+
31+
const isFireflyWallet = useMemo(
32+
() => fireflyWallets.some((w) => isSameAddress(w.address, address)),
33+
[fireflyWallets, address],
34+
)
35+
const fireflyAccount = useSubscription(PersistentStorages.Settings.storage.firefly_account.subscription)
36+
37+
if (isFireflyWallet && fireflyAccount)
38+
return (
39+
<div className={classes.container}>
40+
<Image size={size} src={fireflyAccount.avatar} rounded />
41+
<Icons.Firefly className={classes.badgeIcon} size={12} />
42+
</div>
43+
)
44+
return <Icons.MaskBlue size={size} />
45+
})

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { memo, useCallback } from 'react'
1+
import { memo, useCallback, useMemo } from 'react'
22
import { makeStyles } from '@masknet/theme'
33
import { formatDomainName, formatEthereumAddress } from '@masknet/web3-shared-evm'
4-
import { NetworkPluginID, ImportSource, type Wallet } from '@masknet/shared-base'
4+
import { NetworkPluginID, ImportSource, type Wallet, PersistentStorages } from '@masknet/shared-base'
55
import { useReverseAddress } from '@masknet/web3-hooks-base'
6-
import { Icons } from '@masknet/icons'
76
import {
87
Box,
98
ListItem,
@@ -16,6 +15,10 @@ import {
1615
import { FormattedAddress } from '@masknet/shared'
1716
import { WalletBalance } from '../index.js'
1817
import { Trans } from '@lingui/react/macro'
18+
import { WalletAvatar } from '../WalletAvatar/index.js'
19+
import { useWallets } from '@privy-io/react-auth'
20+
import { isSameAddress } from '@masknet/web3-shared-base'
21+
import { useSubscription } from 'use-subscription'
1922

2023
const useStyles = makeStyles()((theme) => ({
2124
item: {
@@ -106,18 +109,26 @@ export const WalletItem = memo<WalletItemProps>(function WalletItem({
106109
}, [wallet])
107110

108111
const extraName = domain && domain !== wallet.name ? ` (${formatDomainName(domain)})` : ''
112+
const { wallets: fireflyWallets } = useWallets()
113+
const isFireflyWallet = useMemo(
114+
() => fireflyWallets.some((w) => isSameAddress(w.address, wallet.address)),
115+
[fireflyWallets, wallet.address],
116+
)
117+
const fireflyAccount = useSubscription(PersistentStorages.Settings.storage.firefly_account.subscription)
109118

110119
return (
111120
<ListItem
112121
className={cx(classes.item, className)}
113122
onClick={handleSelect}
114123
secondaryAction={<Radio sx={{ marginLeft: 0.75 }} checked={isSelected} />}
115124
{...rest}>
116-
<Icons.MaskBlue size={24} />
125+
<WalletAvatar address={wallet.address} size={24} />
117126
<Box className={classes.text}>
118127
<Box width={180} overflow="auto">
119128
<Typography className={classes.mainLine} component="div">
120-
<Typography className={classes.name}>{`${wallet.name}${extraName}`}</Typography>
129+
<Typography className={classes.name}>
130+
{isFireflyWallet ? fireflyAccount.displayName : `${wallet.name}${extraName}`}
131+
</Typography>
121132
{wallet.source === ImportSource.LocalGenerated || hiddenTag ? null : (
122133
<Typography component="span" className={classes.badge}>
123134
<Trans>Imported</Trans>

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ import { Trans } from '@lingui/react/macro'
1313

1414
interface WalletRenameDrawerProps extends BottomDrawerProps {
1515
wallet?: Wallet
16+
walletName?: string
1617
}
1718

18-
function WalletRenameDrawer({ wallet, ...rest }: WalletRenameDrawerProps) {
19+
function WalletRenameDrawer({ wallet, walletName, ...rest }: WalletRenameDrawerProps) {
1920
const theme = useTheme()
20-
const [name, setName] = useState('')
21+
const [name, setName] = useState(walletName || '')
2122
const [error, setError] = useState<ReactNode>()
2223
const contacts = useContacts()
2324

@@ -60,7 +61,7 @@ function WalletRenameDrawer({ wallet, ...rest }: WalletRenameDrawerProps) {
6061
sx={{ mt: 2 }}
6162
fullWidth
6263
autoFocus
63-
placeholder={wallet?.name}
64+
placeholder={walletName || wallet?.name}
6465
error={!!error}
6566
value={name}
6667
onChange={(e) => {

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,21 @@ import { Box, ListItem, Typography } from '@mui/material'
44
import { useStyles } from './useStyles.js'
55
import { WalletRenameModal } from '../../../modals/modal-controls.js'
66
import { Trans } from '@lingui/react/macro'
7+
import { useWallets } from '@privy-io/react-auth'
8+
import { useMemo } from 'react'
9+
import { isSameAddress } from '@masknet/web3-shared-base'
10+
import { useSubscription } from 'use-subscription'
11+
import { PersistentStorages } from '@masknet/shared-base'
712

813
export function Rename() {
914
const wallet = useWallet()
1015
const { classes, theme } = useStyles()
16+
const { wallets: fireflyWallets } = useWallets()
17+
const isFireflyWallet = useMemo(
18+
() => fireflyWallets.some((w) => isSameAddress(w.address, wallet?.address)),
19+
[fireflyWallets, wallet?.address],
20+
)
21+
const fireflyAccount = useSubscription(PersistentStorages.Settings.storage.firefly_account.subscription)
1122

1223
if (!wallet) return null
1324

@@ -17,6 +28,7 @@ export function Rename() {
1728
onClick={() =>
1829
WalletRenameModal.open({
1930
wallet,
31+
walletName: wallet.name || (isFireflyWallet ? fireflyAccount.displayName : wallet.name),
2032
title: <Trans>Rename</Trans>,
2133
})
2234
}>
@@ -27,7 +39,9 @@ export function Rename() {
2739
</Typography>
2840
</Box>
2941
<Box className={classes.itemBox}>
30-
<Typography className={classes.itemText}>{wallet.name}</Typography>
42+
<Typography className={classes.itemText}>
43+
{isFireflyWallet ? fireflyAccount.displayName : wallet.name}
44+
</Typography>
3145
<Icons.ArrowRight color={theme.palette.maskColor.second} size={24} />
3246
</Box>
3347
</ListItem>

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
1+
import { Trans } from '@lingui/react/macro'
12
import { Icons } from '@masknet/icons'
23
import { Box, ListItem, Typography } from '@mui/material'
3-
import { useStyles } from './useStyles.js'
44
import { ShowPrivateKeyModal } from '../../../modals/modal-controls.js'
5-
import { Trans } from '@lingui/react/macro'
5+
import { useStyles } from './useStyles.js'
66

7-
export function ShowPrivateKey() {
7+
interface Props {
8+
disabled?: boolean
9+
}
10+
export const ShowPrivateKey = function ShowPrivateKey({ disabled }: Props) {
811
const { classes, theme } = useStyles()
912

1013
return (
1114
<ListItem
1215
className={classes.item}
13-
onClick={() =>
16+
sx={disabled ? { opacity: 0.5, cursor: 'not-allowed' } : undefined}
17+
onClick={() => {
18+
if (disabled) return
1419
ShowPrivateKeyModal.open({
1520
title: <Trans>Enter Payment Password</Trans>,
1621
})
17-
}>
22+
}}>
1823
<Box className={classes.itemBox}>
1924
<Icons.PublicKey2 size={20} color={theme.palette.maskColor.second} />
2025
<Typography className={classes.itemText}>

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { Icons } from '@masknet/icons'
2-
import { EMPTY_LIST, PopupModalRoutes } from '@masknet/shared-base'
2+
import { EMPTY_LIST, PersistentStorages, PopupModalRoutes } from '@masknet/shared-base'
33
import { ActionButton } from '@masknet/theme'
44
import { useWallet, useWallets } from '@masknet/web3-hooks-base'
5+
import { useWallets as usePrivyWallets } from '@privy-io/react-auth'
56
import { isSameAddress } from '@masknet/web3-shared-base'
67
import { Box, List, Typography } from '@mui/material'
78
import { first } from 'lodash-es'
@@ -21,6 +22,8 @@ import { useStyles } from './useStyles.js'
2122
import { HidingScamTx } from './HidingScamTx.js'
2223
import { Trans, useLingui } from '@lingui/react/macro'
2324
import { DisablePermit } from './DisablePermit.js'
25+
import { useSubscription } from 'use-subscription'
26+
import { WalletAvatar } from '../../../components/WalletAvatar/index.js'
2427

2528
function getPathIndex(path?: string) {
2629
const rawIndex = path?.split('/').pop()
@@ -33,6 +36,12 @@ export const Component = memo(function WalletSettings() {
3336
const modalNavigate = useModalNavigate()
3437
const wallet = useWallet()
3538
const allWallets = useWallets()
39+
const { wallets: fireflyWallets } = usePrivyWallets()
40+
const isFireflyWallet = useMemo(
41+
() => fireflyWallets.some((w) => isSameAddress(w.address, wallet?.address)),
42+
[fireflyWallets, wallet?.address],
43+
)
44+
const fireflyAccount = useSubscription(PersistentStorages.Settings.storage.firefly_account.subscription)
3645

3746
const handleSwitchWallet = useCallback(() => {
3847
modalNavigate(PopupModalRoutes.WalletAccount)
@@ -65,9 +74,11 @@ export const Component = memo(function WalletSettings() {
6574
<div className={classes.content}>
6675
<Box className={cx(classes.item, classes.primaryItem)} onClick={handleSwitchWallet}>
6776
<Box className={classes.primaryItemBox}>
68-
<Icons.MaskBlue size={24} className={classes.maskBlue} />
77+
<WalletAvatar size={24} address={wallet.address} />
6978
<div className={classes.walletInfo}>
70-
<Typography className={classes.primaryItemText}>{wallet.name}</Typography>
79+
<Typography className={classes.primaryItemText}>
80+
{isFireflyWallet ? fireflyAccount.displayName : wallet.name}
81+
</Typography>
7182
<Typography className={classes.primaryItemSecondText}>{wallet.address}</Typography>
7283
</div>
7384
</Box>
@@ -82,7 +93,7 @@ export const Component = memo(function WalletSettings() {
8293
<AutoLock />
8394
<ChangeCurrency />
8495
<ChangePaymentPassword />
85-
<ShowPrivateKey />
96+
<ShowPrivateKey disabled={isFireflyWallet} />
8697
<ChangeNetwork />
8798
</List>
8899
<Box className={classes.bottomAction}>

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1+
import { Trans } from '@lingui/react/macro'
12
import { Icons } from '@masknet/icons'
23
import { ChainIcon, CopyButton, FormattedAddress, ImageIcon, ProgressiveText } from '@masknet/shared'
3-
import type { Wallet } from '@masknet/shared-base'
4+
import { PersistentStorages, type Wallet } from '@masknet/shared-base'
45
import { makeStyles, TextOverflowTooltip } from '@masknet/theme'
56
import { EVMExplorerResolver } from '@masknet/web3-providers'
6-
import type { ReasonableNetwork } from '@masknet/web3-shared-base'
7+
import { isSameAddress, type ReasonableNetwork } from '@masknet/web3-shared-base'
78
import { formatEthereumAddress, type ChainId, type NetworkType, type SchemaType } from '@masknet/web3-shared-evm'
89
import { Box, Link, Typography } from '@mui/material'
9-
import { memo, type MouseEvent } from 'react'
10+
import { memo, useMemo, type MouseEvent } from 'react'
1011
import { useConnectedWallets } from '../../hooks/useConnected.js'
1112
import { ActionGroup } from '../ActionGroup/index.js'
1213
import { WalletAssetsValue } from './WalletAssetsValue.js'
13-
import { Trans } from '@lingui/react/macro'
14+
import { useWallets } from '@privy-io/react-auth'
15+
import { useSubscription } from 'use-subscription'
16+
import { WalletAvatar } from '../../../../components/WalletAvatar/index.js'
1417

1518
const useStyles = makeStyles<{ disabled: boolean }>()((theme, { disabled }) => {
1619
const isDark = theme.palette.mode === 'dark'
@@ -144,7 +147,13 @@ export const WalletHeaderUI = memo<WalletHeaderUIProps>(function WalletHeaderUI(
144147
}) {
145148
const { classes, cx } = useStyles({ disabled })
146149
const { data: connectedWallets, isPending } = useConnectedWallets(origin)
150+
const { wallets: fireflyWallets } = useWallets()
147151
const connected = connectedWallets?.has(wallet.address)
152+
const isFireflyWallet = useMemo(
153+
() => fireflyWallets.some((w) => isSameAddress(w.address, wallet.address)),
154+
[fireflyWallets, wallet.address],
155+
)
156+
const fireflyAccount = useSubscription(PersistentStorages.Settings.storage.firefly_account.subscription)
148157
const addressLink = EVMExplorerResolver.addressLink(chainId, wallet.address)
149158

150159
const networkName = currentNetwork?.name || currentNetwork?.fullName
@@ -199,10 +208,12 @@ export const WalletHeaderUI = memo<WalletHeaderUIProps>(function WalletHeaderUI(
199208
if (disabled) return
200209
onActionClick()
201210
}}>
202-
<Icons.MaskBlue size={30} />
211+
<WalletAvatar address={wallet.address} size={30} />
203212
<Box ml={0.5} overflow="hidden">
204213
<TextOverflowTooltip title={wallet.name}>
205-
<Typography className={classes.nickname}>{wallet.name}</Typography>
214+
<Typography className={classes.nickname}>
215+
{isFireflyWallet ? fireflyAccount.displayName : wallet.name}
216+
</Typography>
206217
</TextOverflowTooltip>
207218
<Typography className={classes.identifier}>
208219
<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: 'Privy Wallet',
55+
name: '',
5656
source: ImportSource.Privy,
5757
address: wallet.address,
5858
configurable: false,

0 commit comments

Comments
 (0)