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: syntax error in demo GA script & hydration warning #1333

Merged
merged 2 commits into from
Feb 7, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const GoogleAnalytics: FC = () => (
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', ${GA_ID});`,
gtag('config', '${GA_ID}');`,
}}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,30 @@ const SUB_COLORS = ["#37BCFA", "#6D37FA"];

const UserAvatar = ({ address, primaryColor }: UserAvatarProps) => {
const avatarColors = useMemo(() => {
return shuffleColors([primaryColor, ...SUB_COLORS]);
}, [primaryColor]);
return shuffleColorsDeterministically(
[primaryColor, ...SUB_COLORS],
address
);
}, [address, primaryColor]);

return (
<Avatar
size={40}
name={address}
variant="marble"
colors={avatarColors.length > 0 ? avatarColors : [primaryColor]}
/>
<Avatar size={40} name={address} variant="marble" colors={avatarColors} />
);
};

const shuffleColors = (colors: string[]) => {
return colors.sort(() => Math.random() - 0.5);
// Always returns the same colors for the same seed, so
// that rendering on the server and client will match.
const shuffleColorsDeterministically = (colors: string[], seed: string) => {
if (colors.length === 1) {
return colors;
}
const hash = Array.from(seed).reduce(
(acc, char) => acc + char.charCodeAt(0),
0
);
return [...colors].sort(
(a, b) => (hash % a.charCodeAt(0)) - (hash % b.charCodeAt(0))
);
};

export { UserAvatar };