Skip to content

Commit 751540f

Browse files
authored
feat: reverse address to domian (#5897)
* feat: reverse address to domian component * fix: add format ethereum address * fix: eslint * fix: support ens name on ins * fix: build error
1 parent 81aed98 commit 751540f

File tree

8 files changed

+32
-7
lines changed

8 files changed

+32
-7
lines changed

packages/mask/src/extension/options-page/DashboardComponents/CollectibleList/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
ChainId,
66
ERC721ContractDetailed,
77
ERC721TokenDetailed,
8-
formatEthereumAddress,
98
isSameAddress,
109
NonFungibleAssetProvider,
1110
SocketState,
@@ -22,6 +21,7 @@ import { WalletMessages } from '@masknet/plugin-wallet'
2221
import { CollectionIcon } from './CollectionIcon'
2322
import { uniqBy } from 'lodash-unified'
2423
import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown'
24+
import { ReverseAddress } from '@masknet/shared'
2525

2626
export const CollectibleContext = createContext<{
2727
collectiblesRetry: () => void
@@ -301,7 +301,7 @@ export function CollectionList({
301301
className={classes.button}
302302
variant="outlined"
303303
size="small">
304-
{formatEthereumAddress(addressName.label, 5)}
304+
<ReverseAddress address={addressName.resolvedAddress} addressSize={5} />
305305
<KeyboardArrowDownIcon />
306306
</Button>
307307
</Box>
@@ -330,7 +330,7 @@ export function CollectionList({
330330
</Stack>
331331
<Box display="flex" alignItems="center" justifyContent="flex-end" flexWrap="wrap">
332332
<Button onClick={onSelectAddress} className={classes.button} variant="outlined" size="small">
333-
{formatEthereumAddress(addressName.label, 5)}
333+
<ReverseAddress address={addressName.resolvedAddress} addressSize={5} />
334334
<KeyboardArrowDownIcon />
335335
</Button>
336336
</Box>

packages/mask/src/plugins/Avatar/SNSAdaptor/NFTAvatar.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { EthereumChainBoundary } from '../../../web3/UI/EthereumChainBoundary'
1717
import { AddNFT } from './AddNFT'
1818
import { NFTImage } from './NFTImage'
1919
import { useAccount, useWeb3State } from '@masknet/plugin-infra'
20+
import { ReverseAddress } from '@masknet/shared'
2021

2122
const useStyles = makeStyles()((theme) => ({
2223
root: {},
@@ -142,7 +143,7 @@ export function NFTAvatar(props: NFTAvatarProps) {
142143
</Typography>
143144
{account ? (
144145
<Typography variant="body1" color="textPrimary" className={classes.account}>
145-
{t('nft_wallet_label')}: {Utils?.formatAddress?.(account, 4) || account}
146+
{t('nft_wallet_label')}: <ReverseAddress address={account} addressSize={4} />
146147
{!hideWallet ? (
147148
<Button
148149
variant="text"

packages/mask/src/plugins/Collectible/SNSAdaptor/NFTPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { MenuItem } from '@mui/material'
44
import type { AddressName } from '@masknet/web3-shared-evm'
55
import { CollectionList } from '../../../extension/options-page/DashboardComponents/CollectibleList'
66
import { first, uniqBy } from 'lodash-unified'
7-
import { formatEthereumAddress } from '@masknet/web3-shared-evm'
7+
import { ReverseAddress } from '@masknet/shared'
88

99
const useStyles = makeStyles()((theme) => ({
1010
root: {
@@ -71,7 +71,7 @@ export function NFTPage(props: NFTPageProps) {
7171
{uniqBy(addressNames ?? [], (x) => x.resolvedAddress.toLowerCase()).map((x) => {
7272
return (
7373
<MenuItem key={x.resolvedAddress} value={x.resolvedAddress} onClick={() => onSelect(x)}>
74-
{formatEthereumAddress(x.label, 5)}
74+
<ReverseAddress address={x.resolvedAddress} addressSize={5} />
7575
</MenuItem>
7676
)
7777
})}

packages/shared/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"dependencies": {
66
"@dimensiondev/holoflows-kit": "^0.9.0-20210902104757-7c3d0d0",
77
"@masknet/icons": "workspace:*",
8+
"@masknet/plugin-infra": "workspace:*",
89
"@masknet/shared-base": "workspace:*",
910
"@masknet/theme": "workspace:*",
1011
"@masknet/web3-shared-base": "workspace:*",
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { memo } from 'react'
2+
import { NetworkPluginID, useReverseAddress, useWeb3State } from '@masknet/plugin-infra'
3+
4+
interface ReverseAddressProps {
5+
address: string
6+
pluginId?: NetworkPluginID
7+
domainSize?: number
8+
addressSize?: number
9+
}
10+
11+
export const ReverseAddress = memo<ReverseAddressProps>(({ address, pluginId, domainSize, addressSize }) => {
12+
const { value: domain } = useReverseAddress(address, pluginId)
13+
const { Utils } = useWeb3State(pluginId)
14+
15+
if (!domain || !Utils?.formatDomainName) return <>{Utils?.formatAddress?.(address, addressSize) ?? address}</>
16+
17+
return <>{Utils.formatDomainName(domain, domainSize)}</>
18+
})

packages/shared/src/UI/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ export * from './AddressViewer'
1212
export * from './I18NextProviderHMR'
1313
export * from './AssetPlayer'
1414
export * from './NFTCardStyledAssetPlayer'
15+
export * from './ReverseAddress'

packages/shared/tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
{ "path": "../web3-shared/evm" },
1111
{ "path": "../theme" },
1212
{ "path": "../shared-base" },
13-
{ "path": "../icons" }
13+
{ "path": "../shared-base-ui" },
14+
{ "path": "../icons" },
15+
{ "path": "../plugin-infra" }
1416
]
1517
}

pnpm-lock.yaml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)