import { useUtils } from './useUtils' import type { PortfolioData } from '@/data/portfolio' export const useAPI = (baseURL = API_URL, key = API_KEY) => { const { url } = useUtils() const normalizedURL = url.normalizePath(baseURL.trim()) const generateURL = (path: string) => { return normalizedURL + path } const getPortfolioData = async () => fetch(generateURL('/keyvalue?key=portfolio'), { headers: { authorization: `Bearer ` + key.trim(), }, }) .then((resp) => resp.json()) .then((data: { key: string; value: string }[]) => data.length > 0 && data[0] ? (JSON.parse(data[0].value) as PortfolioData) : undefined, ) .catch(() => undefined) return { getPortfolioData, } }