fix(trading): wrong team image showing (#6081)

This commit is contained in:
Matthew Russell 2024-03-22 13:35:29 +00:00 committed by GitHub
parent dc81334aec
commit 891e0d3d2f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 24 deletions

View File

@ -44,6 +44,7 @@ export const CompetitionsLeaderboard = ({
const avatar = (
<TeamAvatar
key={td.teamId}
teamId={td.teamId}
imgUrl={td.avatarUrl}
alt={td.name}

View File

@ -1,6 +1,4 @@
import { isValidUrl } from '@vegaprotocol/utils';
import classNames from 'classnames';
import { useEffect, useState } from 'react';
const NUM_AVATARS = 20;
const AVATAR_PATHNAME_PATTERN = '/team-avatars/{id}.png';
@ -13,26 +11,6 @@ export const getFallbackAvatar = (teamId: string) => {
return AVATAR_PATHNAME_PATTERN.replace('{id}', avatarId);
};
const useAvatar = (teamId: string, url: string) => {
const fallback = getFallbackAvatar(teamId);
const [avatar, setAvatar] = useState<string>(fallback);
useEffect(() => {
if (!isValidUrl(url)) return;
fetch(url, { cache: 'force-cache' })
.then((response) => {
if (response.ok) {
setAvatar(url);
}
})
.catch(() => {
/** noop */
});
});
return avatar;
};
export const TeamAvatar = ({
teamId,
imgUrl,
@ -44,11 +22,11 @@ export const TeamAvatar = ({
alt?: string;
size?: 'large' | 'small';
}) => {
const img = useAvatar(teamId, imgUrl);
// const img = useAvatar(teamId, imgUrl);
return (
// eslint-disable-next-line @next/next/no-img-element
<img
src={img}
src={imgUrl}
alt={alt || 'Team avatar'}
className={classNames(
'rounded-full bg-vega-clight-700 dark:bg-vega-cdark-700 shrink-0',
@ -58,6 +36,9 @@ export const TeamAvatar = ({
}
)}
referrerPolicy="no-referrer"
onError={(e) => {
e.currentTarget.src = getFallbackAvatar(teamId);
}}
/>
);
};