-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Feat: emoji identicons Add experimental toggle * Fix tests * Fix build * Adjust settings style * Disable emojis for small avatars * Extract static fn part * Fix z-index
- Loading branch information
Showing
18 changed files
with
182 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,3 +51,4 @@ yalc.lock | |
/public/sw.js.map | ||
/public/workbox-*.js | ||
/public/workbox-*.js.map | ||
/public/fallback* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { type ReactElement, memo } from 'react' | ||
import { useAppSelector } from '@/store' | ||
import { selectSettings } from '@/store/settingsSlice' | ||
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], | ||
] | ||
|
||
// Calculate the total number of emojis | ||
let totalEmojis = 0 | ||
for (let range of unicodeRanges) { | ||
totalEmojis += range[1] - range[0] + 1 | ||
} | ||
|
||
function ethereumAddressToEmoji(address: string): string { | ||
// Convert the Ethereum address from hexadecimal to decimal | ||
const decimal = BigInt(address.slice(0, 6)) | ||
|
||
// Calculate the index by taking the modulo of the decimal by the number of emojis | ||
let index = Number(decimal % BigInt(totalEmojis)) | ||
|
||
// Find the corresponding emoji | ||
for (let range of unicodeRanges) { | ||
if (index < range[1] - range[0] + 1) { | ||
return String.fromCodePoint(range[0] + index) | ||
} else { | ||
index -= range[1] - range[0] + 1 | ||
} | ||
} | ||
|
||
return '' | ||
} | ||
|
||
type EmojiProps = { | ||
address: string | ||
size?: number | ||
} | ||
|
||
export const Emoji = memo(function Emoji({ address, size = 40 }: EmojiProps): ReactElement { | ||
return ( | ||
<div className={css.emojiWrapper} style={{ fontSize: `${size * 0.7}px`, width: `${size}px`, height: `${size}px` }}> | ||
{ethereumAddressToEmoji(address)} | ||
</div> | ||
) | ||
}) | ||
|
||
const AddressEmoji = (props: EmojiProps): ReactElement | null => { | ||
const { addressEmojis } = useAppSelector(selectSettings) | ||
return addressEmojis ? <Emoji {...props} /> : null | ||
} | ||
|
||
export default AddressEmoji |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,19 @@ | ||
.container { | ||
display: flex; | ||
align-items: center; | ||
gap: 0.5em; | ||
line-height: 1.4; | ||
} | ||
|
||
.avatar { | ||
flex-shrink: 0; | ||
position: relative; | ||
} | ||
|
||
.resizeAvatar, | ||
.resizeAvatar * { | ||
width: 2.3em !important; | ||
height: 2.3em !important; | ||
} | ||
|
||
.addressRow { | ||
.emojiWrapper { | ||
text-align: center; | ||
display: flex; | ||
align-items: center; | ||
gap: 0.25em; | ||
white-space: nowrap; | ||
} | ||
|
||
.nameRow { | ||
overflow: hidden; | ||
} | ||
|
||
.mobileAddress { | ||
display: none; | ||
} | ||
|
||
@media (max-width: 599.95px) { | ||
.mobileAddress { | ||
display: inline-block; | ||
} | ||
|
||
.desktopAddress { | ||
display: none; | ||
} | ||
flex-direction: column; | ||
justify-content: center; | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
border-radius: 100%; | ||
border: 2px solid var(--color-secondary-light); | ||
color: #000; | ||
background-color: rgba(255, 255, 255, 0.5); | ||
text-shadow: -1px 0 0 var(--color-secondary-light), 0 -1px 0 var(--color-secondary-light), | ||
1px 0 0 var(--color-secondary-light), 0 1px 0 var(--color-secondary-light); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Alert, Box, Chip, SvgIcon, Typography } from '@mui/material' | ||
import { ZERO_ADDRESS } from '@safe-global/safe-core-sdk/dist/src/utils/constants' | ||
import InfoIcon from '@/public/images/notifications/info.svg' | ||
import SafeIcon from '@/components/common/SafeIcon' | ||
|
||
const EmojiPreview = () => ( | ||
<> | ||
<Chip label="New" color="secondary" sx={{ fontWeight: 'bold', borderRadius: 2 }} /> | ||
|
||
<Alert severity="success" sx={{ marginTop: 2, borderColor: 'secondary.main' }} icon={<></>}> | ||
<SvgIcon component={InfoIcon} sx={{ marginRight: 1, verticalAlign: 'middle' }} color="secondary" /> | ||
|
||
<Typography component="span">Enable emojis for all Ethereum addresses and your Safe Accounts.</Typography> | ||
|
||
<Box mt={1} display="flex" alignItems="center" gap={1}> | ||
<SafeIcon address={ZERO_ADDRESS} /> | ||
<Typography variant="body2">{ZERO_ADDRESS}</Typography> | ||
</Box> | ||
</Alert> | ||
</> | ||
) | ||
|
||
export default EmojiPreview |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.