import config from '../config/config'; export const request = async ( method: 'GET' | 'POST' | 'PUT', path: string, body?: unknown, baseUrl?: string, customHeaders?: { [key: string]: string } ) => { const url = new URL(path, baseUrl ? baseUrl : config.apiBaseUrl); let verifiedBody: BodyInit | null | undefined; const headers: HeadersInit = baseUrl ? { 'Content-Type': 'application/json', } : {}; if (body) { if (body instanceof FormData) { verifiedBody = body; delete headers['Content-Type']; } else { verifiedBody = body ? JSON.stringify(body) : undefined; } } const response = await fetch(url.toString(), { method, mode: 'cors', headers: { ...headers, ...(customHeaders || {}), }, ...(verifiedBody ? { body: verifiedBody } : {}), }); return response.json(); }; export const putSyncNft = async ( tokenAddress: string, chainId?: string ): Promise => { const chains = chainId ? [chainId] : config.availableWallets.map((wallet) => wallet.chainId); console.log('start nft', tokenAddress); await Promise.allSettled( chains.map(async (chainId) => { await request( 'PUT', `/api/v2/nft/${tokenAddress}/sync`, { chain: chainId }, config.moralisBaseUrl, { 'x-api-key': config.moralisApiKey, } ); }) ); };