CryptoIcon: improve getIcon dynamic import
This commit is contained in:
parent
f61fa18835
commit
ef51d127b1
|
@ -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 */
|
||||
function getIcon(ticker: string): string {
|
||||
const modules: Record<string, { default: string }> = import.meta.glob('../../../assets/cryptocurrency/*.svg', { eager: true });
|
||||
const key = `../../../assets/cryptocurrency/${ticker}.svg`;
|
||||
return modules[key]?.default || genericIcon;
|
||||
try {
|
||||
return new URL(`../../../assets/cryptocurrency/${ticker}.svg`, import.meta.url).href;
|
||||
} catch {
|
||||
return genericIcon;
|
||||
}
|
||||
}
|
||||
|
||||
interface ICryptoIcon {
|
||||
|
|
Loading…
Reference in New Issue