UNPKG

@yoroi/exchange

Version:

The Exchange package of Yoroi SDK

42 lines 1.31 kB
import { fetchData, getApiError, isLeft } from '@yoroi/common'; import { freeze } from 'immer'; import { z } from 'zod'; import { getValidationError } from '../../helpers/get-validation-error'; const initialDeps = freeze({ request: fetchData }, true); export const encryptusApiGetBaseUrl = function (_ref) { let { isProduction } = _ref; let { request } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : initialDeps; return async fetcherConfig => { const config = { url: encryptusApiConfig[isProduction ? 'production' : 'sandbox'].getBaseUrl }; try { const response = await request(config, fetcherConfig); if (isLeft(response)) throw getApiError(response.error); const parsedResponse = EncryptusApiResponseSchema.parse(response.value.data); return parsedResponse.data.link; } catch (error) { throw getValidationError(error); } }; }; const EncryptusApiResponseSchema = z.object({ data: z.object({ link: z.string() }) }); export const encryptusApiConfig = freeze({ production: { getBaseUrl: 'https://api.yoroiwallet.com/api/v2/encryptus/payoutlink' }, sandbox: { getBaseUrl: 'https://preprod-backend.yoroiwallet.com/api/v2/encryptus/payoutlink' } }, true); //# sourceMappingURL=api.js.map