import React from 'react';
import type { NetworkExplorer as TNetworkExplorer } from 'types/networks';
import config from 'configs/app';
import { Image } from '@luxfi/ui/image';
import { Link } from 'toolkit/next/link';
import { stripTrailingSlash } from 'toolkit/utils/url';
import IconSvg from 'ui/shared/IconSvg';
import VerifyWith from 'ui/shared/VerifyWith';
interface Props {
className?: string;
type: keyof TNetworkExplorer['paths'];
pathParam: string;
}
const NetworkExplorers = ({ className, type, pathParam }: Props) => {
const explorersLinks = React.useMemo(() => {
return config.UI.explorers.items
.filter((explorer) => typeof explorer.paths[type] === 'string')
.map((explorer) => {
const path = explorer.paths[type] || '';
let pathWithParam;
if (path.includes(':id_lowercase')) {
pathWithParam = path.replace(':id_lowercase', pathParam.toLowerCase());
} else if (path.includes(':id')) {
pathWithParam = path.replace(':id', pathParam);
} else {
pathWithParam = stripTrailingSlash(path) + '/' + pathParam.toLowerCase();
}
const url = new URL(pathWithParam, explorer.baseUrl);
return (
{ explorer.logo ?
:
}
{ explorer.title }
);
});
}, [ pathParam, type ]);
if (explorersLinks.length === 0) {
return null;
}
return (
1 ? 's' : '' }` }
shortText={ explorersLinks.length.toString() }
/>
);
};
export default React.memo(NetworkExplorers);