Skip to content

Commit 21e85f9

Browse files
committed
fix(Tips): refine recipient UI
closes MF-6265
1 parent 98df0dd commit 21e85f9

File tree

7 files changed

+105
-54
lines changed

7 files changed

+105
-54
lines changed

packages/mask/content-script/components/InjectedComponents/ProfileCard/ProfileCardTitle.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Icons } from '@masknet/icons'
22
import { useIsMinimalMode } from '@masknet/plugin-infra/content-script'
3-
import { TipButton } from '@masknet/plugin-tips'
3+
import { TipsButton } from '@masknet/plugin-tips'
44
import { PersonaSelectPanelModal, SocialAccountList, useCurrentPersonaConnectStatus } from '@masknet/shared'
55
import {
66
CrossIsolationMessages,
@@ -14,8 +14,8 @@ import type { Web3Helper } from '@masknet/web3-helpers'
1414
import { Web3Bio } from '@masknet/web3-providers'
1515
import { useQuery } from '@tanstack/react-query'
1616
import type { HTMLProps } from 'react'
17-
import { useLastRecognizedIdentity } from '../../DataSource/useActivatedUI.js'
1817
import { useCurrentPersona, usePersonasFromDB } from '../../../../shared-ui/hooks/index.js'
18+
import { useLastRecognizedIdentity } from '../../DataSource/useActivatedUI.js'
1919
import { ProfileBar, ProfileBarSkeleton } from './ProfileBar.js'
2020

2121
const useStyles = makeStyles()((theme) => {
@@ -146,7 +146,7 @@ export function ProfileCardTitle({
146146
{itsMe ?
147147
<Web3ProfileSettingButton />
148148
: !tipsDisabled ?
149-
<TipButton className={classes.tipButton} receiver={identity.identifier} />
149+
<TipsButton className={classes.tipButton} receiver={identity.identifier} />
150150
: null}
151151
</div>
152152
</ProfileBar>

packages/mask/content-script/site-adaptors/mirror.xyz/injection/Tips/TipsButtonWrapper.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { memo, useMemo, useState } from 'react'
2-
import { EMPTY_LIST, PluginID, type SocialAccount } from '@masknet/shared-base'
2+
import { EMPTY_LIST, EnhanceableSite, PluginID, type SocialAccount } from '@masknet/shared-base'
33
import { makeStyles } from '@masknet/theme'
44
import type { Web3Helper } from '@masknet/web3-helpers'
55
import { useNetworkContext, useWeb3Utils } from '@masknet/web3-hooks-base'
@@ -48,10 +48,7 @@ export const TipsButtonWrapper = memo(function TipsButtonWrapper({ slot }: Props
4848
{
4949
pluginID,
5050
address: visitingIdentity.identifier.userId,
51-
label:
52-
visitingIdentity.nickname ?
53-
`(${visitingIdentity.nickname}) ${Utils.formatAddress(visitingIdentity.identifier.userId, 4)}`
54-
: visitingIdentity.identifier.userId,
51+
label: visitingIdentity.nickname || visitingIdentity.identifier.userId,
5552
},
5653
]
5754
}, [visitingIdentity, Utils.formatAddress])
@@ -72,7 +69,13 @@ export const TipsButtonWrapper = memo(function TipsButtonWrapper({ slot }: Props
7269
)
7370
}, [visitingIdentity.identifier, accounts, slot])
7471

75-
if (disabled || !component || !visitingIdentity.identifier || isMinimalMode || location.pathname === '/')
72+
if (
73+
disabled ||
74+
!component ||
75+
!visitingIdentity.identifier ||
76+
isMinimalMode ||
77+
(location.hostname === EnhanceableSite.Mirror && location.pathname === '/') // exclude hostname like vitalik.mirror.xyz
78+
)
7679
return null
7780

7881
return (

packages/plugins/Tips/src/SiteAdaptor/components/TipsRealmContent/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
import { Trans } from '@lingui/react/macro'
12
import { Plugin } from '@masknet/plugin-infra'
23
import { useLastRecognizedIdentity } from '@masknet/plugin-infra/content-script'
34
import { PluginGuide } from '@masknet/shared'
45
import { Sniffings, type EnhanceableSite } from '@masknet/shared-base'
56
import { makeStyles } from '@masknet/theme'
67
import { Stack } from '@mui/material'
8+
import { TipsButton } from '../../../components/index.js'
79
import { useTipsUserGuide } from '../../../storage/index.js'
8-
import { TipButton } from '../../../components/index.js'
9-
import { Trans } from '@lingui/react/macro'
1010

1111
const useStyles = makeStyles<{ buttonSize: number }, 'postTipsButton'>()((theme, { buttonSize }, refs) => ({
1212
postButtonWrapper: {
@@ -84,7 +84,7 @@ export function TipsRealmContent({
8484
}
8585

8686
const button = (
87-
<TipButton
87+
<TipsButton
8888
accounts={accounts}
8989
className={buttonClassMap[slot]}
9090
iconSize={iconSize}

packages/plugins/Tips/src/components/RecipientSection/RecipientSelect.tsx

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { memo, useRef } from 'react'
1+
import { memo, useMemo, useRef } from 'react'
22
import { Icons } from '@masknet/icons'
33
import { makeStyles } from '@masknet/theme'
44
import { AccountIcons, ReversedAddress } from '@masknet/shared'
55
import { Link, MenuItem, Select, Typography } from '@mui/material'
6-
import { useDefaultChainId, useWeb3Utils } from '@masknet/web3-hooks-base'
6+
import { useDefaultChainId, useReverseAddresses, useWeb3Utils } from '@masknet/web3-hooks-base'
77
import { isSameAddress } from '@masknet/web3-shared-base'
88
import type { Web3Helper } from '@masknet/web3-helpers'
99
import { NetworkPluginID, type SocialAccount } from '@masknet/shared-base'
@@ -17,14 +17,23 @@ const useStyles = makeStyles<void, 'icon' | 'pluginIcon' | 'text'>()((theme, _,
1717
flexGrow: 1,
1818
},
1919
menuItem: {
20-
height: 32,
20+
minHeight: 32,
2121
color: theme.palette.maskColor.main,
2222
borderRadius: theme.spacing(1),
23-
padding: theme.spacing(0, 0.5),
23+
padding: 6,
24+
gap: theme.spacing(1),
2425
'&:not(:first-of-type)': {
2526
marginTop: theme.spacing(1),
2627
},
2728
},
29+
account: {},
30+
address: {
31+
fontSize: 14,
32+
fontWeight: 400,
33+
lineHeight: '18px',
34+
display: 'flex',
35+
alignItems: 'center',
36+
},
2837
text: {
2938
fontWeight: 700,
3039
marginLeft: theme.spacing(0.5),
@@ -76,7 +85,7 @@ const useStyles = makeStyles<void, 'icon' | 'pluginIcon' | 'text'>()((theme, _,
7685
}
7786
})
7887

79-
const PluginIcon = ({ pluginID }: { pluginID: NetworkPluginID }) => {
88+
const ChainRuntimeIcon = ({ runtime }: { runtime: NetworkPluginID }) => {
8089
const { classes } = useStyles()
8190
const mapping = {
8291
[NetworkPluginID.PLUGIN_EVM]: (
@@ -110,7 +119,7 @@ const PluginIcon = ({ pluginID }: { pluginID: NetworkPluginID }) => {
110119
/>
111120
),
112121
}
113-
return mapping[pluginID]
122+
return mapping[runtime]
114123
}
115124

116125
function ExternalLink({ account }: { account: SocialAccount<Web3Helper.ChainIdAll> }) {
@@ -141,6 +150,11 @@ export const RecipientSelect = memo(({ className }: Props) => {
141150
const selectRef = useRef(null)
142151
const { recipient, recipients, setRecipient } = useTip()
143152
const recipientAddress = recipient?.address
153+
const addresses = useMemo(() => {
154+
return recipients.map((x) => ({ address: x.address, pluginID: x.pluginID }))
155+
}, [recipients])
156+
157+
const queries = useReverseAddresses(addresses)
144158

145159
return (
146160
<Select
@@ -166,11 +180,11 @@ export const RecipientSelect = memo(({ className }: Props) => {
166180
BackdropProps: {
167181
invisible: true,
168182
},
169-
}}>
170-
{recipients.map((account) => (
171-
<MenuItem className={classes.menuItem} key={account.address} value={account.address}>
172-
<PluginIcon pluginID={account.pluginID} />
173-
{account.label ?
183+
}}
184+
renderValue={(value) => {
185+
const account = recipients.find((x) => isSameAddress(x.address, value))
186+
if (!account) return null
187+
return account.label ?
174188
<Typography component="span" className={classes.text}>
175189
{account.label}
176190
</Typography>
@@ -180,14 +194,33 @@ export const RecipientSelect = memo(({ className }: Props) => {
180194
component="span"
181195
className={classes.text}
182196
/>
183-
}
184-
<ExternalLink account={account} />
185-
<AccountIcons socialAccount={account} classes={{ icon: classes.icon }} />
186-
{isSameAddress(account.address, recipientAddress) ?
187-
<Icons.CheckCircle className={cx(classes.checkIcon, classes.icon)} />
188-
: null}
189-
</MenuItem>
190-
))}
197+
}}>
198+
{recipients.map((account, index) => {
199+
const selected = isSameAddress(account.address, recipientAddress)
200+
const domain = queries[index].data
201+
const label = account.label || domain
202+
203+
return (
204+
<MenuItem className={classes.menuItem} key={account.address} value={account.address}>
205+
<ChainRuntimeIcon runtime={account.pluginID} />
206+
<div className={classes.account}>
207+
{label ?
208+
<Typography component="span" className={classes.text}>
209+
{account.label}
210+
</Typography>
211+
: null}
212+
<Typography className={classes.address}>
213+
{account.address}
214+
<ExternalLink account={account} />
215+
</Typography>
216+
</div>
217+
<AccountIcons socialAccount={account} classes={{ icon: classes.icon }} />
218+
{selected ?
219+
<Icons.CheckCircle className={cx(classes.checkIcon, classes.icon)} />
220+
: null}
221+
</MenuItem>
222+
)
223+
})}
191224
</Select>
192225
)
193226
})

packages/plugins/Tips/src/components/TipsButton/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const useStyles = makeStyles()({
3636
},
3737
})
3838

39-
export function TipButton(props: Props) {
39+
export function TipsButton(props: Props) {
4040
const {
4141
className,
4242
accounts: receivingAccounts = EMPTY_LIST,

packages/shared/src/UI/components/ReversedAddress/index.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ export const ReversedAddress = memo<ReverseAddressProps>(({ address, pluginID, s
2929
const popperProps = useBoundedPopperProps()
3030

3131
useEffect(() => {
32-
if (showDomain) {
33-
onReverse?.(domain)
34-
}
32+
onReverse?.(domain ?? '')
3533
}, [showDomain, domain, onReverse])
3634

3735
return hasEllipsis ?
Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,46 @@
1-
import { skipToken, useQuery } from '@tanstack/react-query'
2-
import { NameServiceID, type NetworkPluginID } from '@masknet/shared-base'
3-
import { useWeb3State } from './useWeb3State.js'
4-
import { Lens } from '@masknet/web3-providers'
1+
import { NameServiceID, NetworkPluginID } from '@masknet/shared-base'
2+
import { useNetworkContext } from '@masknet/web3-hooks-base'
3+
import { getActivatedPluginWeb3State, Lens } from '@masknet/web3-providers'
4+
import { useQueries, useQuery } from '@tanstack/react-query'
55

66
export function useReverseAddress<T extends NetworkPluginID>(
7-
pluginID?: T,
7+
expectedPluginID?: T,
88
address?: string,
99
domainOnly?: boolean,
1010
preferredType?: NameServiceID,
1111
) {
12-
const { NameService } = useWeb3State(pluginID)
13-
12+
const { pluginID } = useNetworkContext<T>(expectedPluginID)
1413
return useQuery({
15-
queryKey: ['reverse', address, domainOnly, preferredType],
16-
enabled: !!NameService?.reverse,
17-
queryFn:
18-
NameService ?
19-
async () => {
20-
if (!address) return null
21-
if (preferredType === NameServiceID.Lens) {
22-
const result = await Lens.reverse?.(address)
23-
if (result) return result
24-
}
25-
return (await NameService?.reverse?.(address, domainOnly)) || null
14+
queryKey: ['reverse', address, pluginID, domainOnly, preferredType],
15+
queryFn: async () => {
16+
const { NameService } = getActivatedPluginWeb3State(pluginID)
17+
if (!address || !NameService) return null
18+
if (preferredType === NameServiceID.Lens) {
19+
const result = await Lens.reverse?.(address)
20+
if (result) return result
21+
}
22+
return (await NameService?.reverse?.(address, domainOnly)) || null
23+
},
24+
})
25+
}
26+
27+
export function useReverseAddresses<T extends NetworkPluginID>(
28+
addresses: Array<{ address: string; pluginID: T }>,
29+
domainOnly?: boolean,
30+
preferredType?: NameServiceID,
31+
) {
32+
return useQueries({
33+
queries: addresses.map(({ address, pluginID }) => ({
34+
queryKey: ['reverse', address, pluginID, domainOnly, preferredType],
35+
queryFn: async () => {
36+
const { NameService } = getActivatedPluginWeb3State(pluginID)
37+
if (!address || !NameService) return null
38+
if (preferredType === NameServiceID.Lens) {
39+
const result = await Lens.reverse?.(address)
40+
if (result) return result
2641
}
27-
: skipToken,
42+
return (await NameService?.reverse?.(address, domainOnly)) || null
43+
},
44+
})),
2845
})
2946
}

0 commit comments

Comments
 (0)