export const handleUri = (uri: string | undefined): string => { if (!uri) { return ''; // return '' } return uri.replace('#', '%23'); }; export const getNonce = () => { const j = Date.now().toString() + Math.floor(Math.random() * 10000).toString(); return j; }; export const getPageNo = (url: string) => { const firstIndex = url.indexOf('?page='); const endIndex = url.indexOf('&'); return url.substring(firstIndex + 6, endIndex); }; export const fetcher = (api: string, args: any) => { return fetch(api, args) .then(res => res.json()) .then(value => { if (value && value.code === 10112) { console.log('Remove token'); console.log(value); localStorage.removeItem('token'); } return value; }) .catch(e => console.error(api, e, args)); }; export const shimmer = (w: number, h: number) => ` `; export const toBase64 = (str: string) => typeof window === 'undefined' ? Buffer.from(str).toString('base64') : window.btoa(str); export const getAssetProtocol = (type: number | undefined) => { switch (type) { case 0: return 'ERC-721'; case 1: return 'ERC-1155'; default: return 'ERC-721'; } };