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 */
|
/** 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 {
|
||||||
|
|
Loading…
Reference in New Issue