import {useQuery, useMutation} from 'react-query'; import {AxiosResponse} from 'axios'; import { issuanceServiceInstance, cloudWalletServiceInstance, digiLockerAffinidiServiceInstance, } from '@services/Axios'; const get = async ( url: string, isCloudWallet = false, ): Promise< AxiosResponse | undefined | {error: string; data?: any} > => { try { const response = isCloudWallet ? await cloudWalletServiceInstance.get(url) : await issuanceServiceInstance.get(url); return response; } catch (error: any) { return {error: error?.message}; } }; const post = async ({ url, data, isCloudWallet = false, isDigiLocker = false, }: { url: string; data: unknown; isCloudWallet?: boolean; isDigiLocker?: boolean; }): Promise | undefined | {error: string}> => { try { const response = isCloudWallet ? await cloudWalletServiceInstance.post(url, data) : isDigiLocker ? await digiLockerAffinidiServiceInstance.post(url, data) : await issuanceServiceInstance.post(url, data); return response; } catch (error: any) { return {error: error?.message}; } }; export const usePost = () => useMutation(post); export const useGet = ( key: string, url: string, options: any, isCloudWallet?: boolean, ) => useQuery([key, url], () => get(url, isCloudWallet), options);