CryptoIcon: improve getIcon dynamic import

This commit is contained in:
Alex Gleason 2024-10-19 16:41:02 -05:00
parent f61fa18835
commit ef51d127b1
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 5 additions and 3 deletions

View File

@ -4,9 +4,11 @@ import genericIcon from 'soapbox/assets/cryptocurrency/generic.svg';
/** Get crypto icon URL by ticker symbol, or fall back to generic icon */ /** Get crypto icon URL by ticker symbol, or fall back to generic icon */
function getIcon(ticker: string): string { function getIcon(ticker: string): string {
const modules: Record<string, { default: string }> = import.meta.glob('../../../assets/cryptocurrency/*.svg', { eager: true }); try {
const key = `../../../assets/cryptocurrency/${ticker}.svg`; return new URL(`../../../assets/cryptocurrency/${ticker}.svg`, import.meta.url).href;
return modules[key]?.default || genericIcon; } catch {
return genericIcon;
}
} }
interface ICryptoIcon { interface ICryptoIcon {