Skip to content

Commit

Permalink
Fix token icon not updating properly
Browse files Browse the repository at this point in the history
Fixes DefiLlama#1450

Update the token icon URL handling and validation in `components/RPCList/index.js`.

* **Add icon URL validation**: Add a function `isValidIconUrl` to check if the icon URL is valid before displaying it.
* **Set icon URL**: Define the icon URL using `chain.chainSlug`.
* **State management**: Add state `validIconUrl` to manage the validity of the icon URL.
* **Effect hook**: Use `useEffect` to validate the icon URL and update the state accordingly.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/DefiLlama/chainlist/issues/1450?shareId=XXXX-XXXX-XXXX-XXXX).
  • Loading branch information
Setland34 committed Jan 16, 2025
1 parent a5e5ae3 commit 0c2266f
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions components/RPCList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,25 @@ const Row = ({ values, chain, privacy, lang, className }) => {

const { mutate: addToNetwork } = useAddToNetwork();

const isValidIconUrl = (url) => {
const img = new Image();
img.src = url;
return new Promise((resolve) => {
img.onload = () => resolve(true);
img.onerror = () => resolve(false);
});
};

const iconUrl = `https://icons.llamao.fi/icons/chains/rsz_${chain.chainSlug}.jpg`;

const [validIconUrl, setValidIconUrl] = useState(false);

useEffect(() => {
isValidIconUrl(iconUrl).then((isValid) => {
setValidIconUrl(isValid);
});
}, [iconUrl]);

return (
<tr className={className}>
<td className="border px-3 py-1 max-w-[40ch]">
Expand Down

0 comments on commit 0c2266f

Please sign in to comment.