This repository has been archived by the owner on Sep 21, 2024. It is now read-only.
forked from pixelaw/web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
94 additions
and
5 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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
const colors = [ | ||
'#FC5C54', | ||
'#FFD95A', | ||
'#E95D72', | ||
'#6A87C8', | ||
'#5FD0F3', | ||
'#75C06B', | ||
'#FFDD86', | ||
'#5FC6D4', | ||
'#FF949A', | ||
'#FF8024', | ||
'#9BA1A4', | ||
'#EC66FF', | ||
'#FF8CBC', | ||
'#FF9A23', | ||
'#C5DADB', | ||
'#A8CE63', | ||
'#71ABFF', | ||
'#FFE279', | ||
'#B6B1B6', | ||
'#FF6780', | ||
'#A575FF', | ||
'#4D82FF', | ||
'#FFB35A', | ||
] as const; | ||
|
||
const avatars = [ | ||
{ color: colors[0], emoji: '🌶' }, | ||
{ color: colors[1], emoji: '🤑' }, | ||
{ color: colors[2], emoji: '🐙' }, | ||
{ color: colors[3], emoji: '🫐' }, | ||
{ color: colors[4], emoji: '🐳' }, | ||
{ color: colors[0], emoji: '🤶' }, | ||
{ color: colors[5], emoji: '🌲' }, | ||
{ color: colors[6], emoji: '🌞' }, | ||
{ color: colors[7], emoji: '🐒' }, | ||
{ color: colors[8], emoji: '🐵' }, | ||
{ color: colors[9], emoji: '🦊' }, | ||
{ color: colors[10], emoji: '🐼' }, | ||
{ color: colors[11], emoji: '🦄' }, | ||
{ color: colors[12], emoji: '🐷' }, | ||
{ color: colors[13], emoji: '🐧' }, | ||
{ color: colors[8], emoji: '🦩' }, | ||
{ color: colors[14], emoji: '👽' }, | ||
{ color: colors[0], emoji: '🎈' }, | ||
{ color: colors[8], emoji: '🍉' }, | ||
{ color: colors[1], emoji: '🎉' }, | ||
{ color: colors[15], emoji: '🐲' }, | ||
{ color: colors[16], emoji: '🌎' }, | ||
{ color: colors[17], emoji: '🍊' }, | ||
{ color: colors[18], emoji: '🐭' }, | ||
{ color: colors[19], emoji: '🍣' }, | ||
{ color: colors[1], emoji: '🐥' }, | ||
{ color: colors[20], emoji: '👾' }, | ||
{ color: colors[15], emoji: '🥦' }, | ||
{ color: colors[0], emoji: '👹' }, | ||
{ color: colors[17], emoji: '🙀' }, | ||
{ color: colors[4], emoji: '⛱' }, | ||
{ color: colors[21], emoji: '⛵️' }, | ||
{ color: colors[17], emoji: '🥳' }, | ||
{ color: colors[8], emoji: '🤯' }, | ||
{ color: colors[22], emoji: '🤠' }, | ||
] as const; | ||
|
||
function hashCode(text: string) { | ||
let hash = 0; | ||
if (text.length === 0) return hash; | ||
for (let i = 0; i < text.length; i++) { | ||
const chr = text.charCodeAt(i); | ||
hash = (hash << 5) - hash + chr; | ||
hash |= 0; | ||
} | ||
return hash; | ||
} | ||
|
||
export function emojiAvatarForAddress(address: string) { | ||
const resolvedAddress = typeof address === 'string' ? address : ''; | ||
const avatarIndex = Math.abs(hashCode(resolvedAddress.toLowerCase()) % avatars.length); | ||
return avatars[avatarIndex ?? 0]; | ||
} |
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