Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: extend the emoji set for eth addresses #2368

Merged
merged 1 commit into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/components/common/AddressEmoji/AddressEmoji.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { ethereumAddressToEmoji } from '.'

describe('ethereumAddressToEmoji', () => {
it('should return the correct emoji', () => {
const emoji = ethereumAddressToEmoji('0x0000000000000000000000000000000000000000')
expect(emoji).toBe('😀')
})

it('should return an emoji for the entire range of addresses', () => {
const hexChars = 4
for (let i = 0; i < 16 ** hexChars; i++) {
const address = `0x${i.toString(16).padStart(4, '0')}`
const emoji = ethereumAddressToEmoji(address)
//console.log(address, emoji)
expect(emoji).toBeDefined()
expect(emoji).not.toBe('')
}
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import css from './styles.module.css'

// Define the Unicode ranges for animal, fruit, and vegetable emojis
const unicodeRanges = [
[0x1f400, 0x1f43f],
[0x1f980, 0x1f994],
[0x1f345, 0x1f35f],
[0x1f950, 0x1f96b],
[0x1f600, 0x1f60e],
[0x1f638, 0x1f63d],
[0x1f680, 0x1f683],
[0x2614, 0x2615],
[0x1f330, 0x1f393],
[0x1f3a0, 0x1f3ca],
[0x1f400, 0x1f42a],
]

// Calculate the total number of emojis
Expand All @@ -17,7 +20,7 @@ for (let range of unicodeRanges) {
totalEmojis += range[1] - range[0] + 1
}

function ethereumAddressToEmoji(address: string): string {
export function ethereumAddressToEmoji(address: string): string {
// Convert the Ethereum address from hexadecimal to decimal
const decimal = BigInt(address.slice(0, 6))

Expand Down
2 changes: 1 addition & 1 deletion src/components/common/ConnectWallet/AccountCenter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import ChainSwitcher from '../ChainSwitcher'
import useAddressBook from '@/hooks/useAddressBook'
import { type ConnectedWallet } from '@/hooks/wallets/useOnboard'
import WalletInfo, { UNKNOWN_CHAIN_NAME } from '../WalletInfo'
import AddressEmoji from '../EthHashInfo/AddressEmoji'
import AddressEmoji from '../AddressEmoji'

const AccountCenter = ({ wallet }: { wallet: ConnectedWallet }) => {
const [anchorEl, setAnchorEl] = useState<HTMLButtonElement | null>(null)
Expand Down
8 changes: 4 additions & 4 deletions src/components/common/EthHashInfo/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { type ReactElement } from 'react'
import { Box } from '@mui/material'
import useAddressBook from '@/hooks/useAddressBook'
import useChainId from '@/hooks/useChainId'
import { useAppSelector } from '@/store'
import { selectSettings } from '@/store/settingsSlice'
import { selectChainById } from '@/store/chainsSlice'
import { getBlockExplorerLink } from '@/utils/chains'
import css from './styles.module.css'
import { Emoji } from './AddressEmoji'
import { Emoji } from '@/components/common/AddressEmoji'
import SrcEthHashInfo, { type EthHashInfoProps } from './SrcEthHashInfo'

const EthHashInfo = ({
Expand All @@ -23,7 +23,7 @@ const EthHashInfo = ({
const showEmoji = settings.addressEmojis && props.showAvatar !== false && !props.customAvatar && avatarSize >= 20

return (
<div className={css.container}>
<Box position="relative">
<SrcEthHashInfo
prefix={chain?.shortName}
showPrefix={settings.shortName.show}
Expand All @@ -37,7 +37,7 @@ const EthHashInfo = ({
{props.children}
</SrcEthHashInfo>
{showEmoji && <Emoji address={props.address} size={avatarSize} />}
</div>
</Box>
)
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/common/SafeIcon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Box } from '@mui/material'

import css from './styles.module.css'
import Identicon, { type IdenticonProps } from '../Identicon'
import AddressEmoji from '../EthHashInfo/AddressEmoji'
import AddressEmoji from '../AddressEmoji'

interface ThresholdProps {
threshold: number | string
Expand Down
Loading