From 606789ffc3999d9f9b33fb02056e761d7a74fe4f Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 10 Nov 2024 18:50:49 -0600 Subject: [PATCH] Add missing dogecoin icon, fix display of unknown cryptocurrency icons --- src/assets/cryptocurrency/doge.svg | 1 + src/features/crypto-donate/components/crypto-icon.tsx | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 src/assets/cryptocurrency/doge.svg diff --git a/src/assets/cryptocurrency/doge.svg b/src/assets/cryptocurrency/doge.svg new file mode 100644 index 000000000..c22bf09bd --- /dev/null +++ b/src/assets/cryptocurrency/doge.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/features/crypto-donate/components/crypto-icon.tsx b/src/features/crypto-donate/components/crypto-icon.tsx index c42327bbe..45b78e040 100644 --- a/src/features/crypto-donate/components/crypto-icon.tsx +++ b/src/features/crypto-donate/components/crypto-icon.tsx @@ -1,10 +1,14 @@ import genericIcon from 'soapbox/assets/cryptocurrency/generic.svg'; +const icons = import.meta.glob('../../../assets/cryptocurrency/*.svg', { eager: true }); + /** Get crypto icon URL by ticker symbol, or fall back to generic icon */ function getIcon(ticker: string): string { - try { - return new URL(`../../../assets/cryptocurrency/${ticker}.svg`, import.meta.url).href; - } catch { + const iconPath = `../../../assets/cryptocurrency/${ticker}.svg`; + + if (icons[iconPath]) { + return new URL(iconPath, import.meta.url).href; + } else { return genericIcon; } }