Skip to content

Commit

Permalink
try to fix icons
Browse files Browse the repository at this point in the history
  • Loading branch information
Ridel1e committed Jan 4, 2024
1 parent ceb9e81 commit d02c372
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/components/AssetIcon/AssetIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,20 @@ const AssetIcon: React.FC<TokenIconProps> = ({
const [errorState, setErrorState] = useState<ErrorState | undefined>(
undefined,
);
const [assetLogoUrl, setAssetLogoUrl] = useState(asset?.icon);
const [assetLogoAltUrl, setAssetLogoAltUrl] = useState(asset?.url);

useEffect(() => {
setAssetLogoUrl((prev) => {
return prev === asset?.icon ? prev : asset?.icon;
});
setAssetLogoAltUrl((prev) => {
return prev === asset?.url ? prev : asset?.url;
});
if (asset) {
setErrorState(undefined);
}
}, [asset]);
}, [asset?.id]);

const handleError = () => {
if (errorState === undefined && asset?.url) {
Expand Down Expand Up @@ -80,7 +88,7 @@ const AssetIcon: React.FC<TokenIconProps> = ({
<img
style={{ verticalAlign: 'initial' }}
alt="Token Icon"
src={asset?.url}
src={assetLogoAltUrl}
onError={handleError}
width={MAP_SIZE_TO_NUMBER[size]}
height={MAP_SIZE_TO_NUMBER[size]}
Expand All @@ -89,7 +97,7 @@ const AssetIcon: React.FC<TokenIconProps> = ({
<img
style={{ verticalAlign: 'initial' }}
alt="Token Icon"
src={asset?.icon}
src={assetLogoUrl}
onError={handleError}
width={MAP_SIZE_TO_NUMBER[size]}
height={MAP_SIZE_TO_NUMBER[size]}
Expand Down

0 comments on commit d02c372

Please sign in to comment.