Skip to content

Commit

Permalink
Fix broken image fallback (#12679)
Browse files Browse the repository at this point in the history
## Description 

Whenever browsing between pages/screens in Explorer and Wallet, the
fallback avatar sometime does not show. This addresses it by checking
for the URL string before rendering the image

Fixes this 
<img width="1477" alt="Screenshot 2023-06-25 at 6 54 00 PM"
src="https://github.com/MystenLabs/sui/assets/126525197/b8706f58-88d0-4277-8464-6983e2b6b193">
  • Loading branch information
Jibz-Mysten authored and ebmifa committed Jul 12, 2023
1 parent 715b44f commit b4f2218
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions apps/explorer/src/ui/ImageIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ export function ImageIcon({ src, label, alt = label, fallback, ...styleProps }:
const [error, setError] = useState(false);
return (
<div role="img" className={imageStyle(styleProps)} aria-label={label}>
{error ? (
{error || !src ? (
<FallBackAvatar fallback={fallback} />
) : (
<img
src={src || ''}
src={src}
alt={alt}
className="flex h-full w-full items-center justify-center object-contain"
onError={() => setError(true)}
Expand Down
4 changes: 2 additions & 2 deletions apps/wallet/src/ui/app/shared/image-icon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ export function ImageIcon({ src, label, alt = label, fallback, ...styleProps }:
const [error, setError] = useState(false);
return (
<div role="img" className={imageStyle(styleProps)} aria-label={label}>
{error ? (
{error || !src ? (
<FallBackAvatar str={fallback} />
) : (
<img
src={src || ''}
src={src}
alt={alt}
className="flex h-full w-full items-center justify-center object-cover"
onError={() => setError(true)}
Expand Down

0 comments on commit b4f2218

Please sign in to comment.