UNPKG

@yoroi/swap

Version:
36 lines (35 loc) 1.32 kB
"use strict"; import { Api, Swap } from '@yoroi/types'; import { TokenIdSchema } from '@yoroi/portfolio'; import { fetchData, getApiError, isLeft } from '@yoroi/common'; import { freeze } from 'immer'; import { z } from 'zod'; const initialDeps = freeze({ request: fetchData }, true); export const getSwapConfigApiMaker = ({ request } = initialDeps) => async () => { const response = await request({ url: 'https://daehx1qv45z7c.cloudfront.net/swapConfig.json' }); if (isLeft(response)) throw getApiError(response.error); const parsedResponse = SwapConfigResponseSchema.safeParse(response.value.data); if (!parsedResponse.success) { throw new Api.Errors.ResponseMalformed('Invalid swap config response: ' + JSON.stringify(response.value.data)); } return parsedResponse.data; }; const SwapConfigResponseSchema = z.object({ initialPair: z.object({ tokenIn: TokenIdSchema.refine(_ => true), tokenOut: TokenIdSchema.refine(_ => true) }).optional(), verifiedTokens: z.array(TokenIdSchema.refine(_ => true)).optional(), excludedTokens: z.array(TokenIdSchema.refine(_ => true)).optional(), partners: z.object({ [Swap.Aggregator.Dexhunter]: z.string().optional(), [Swap.Aggregator.Muesliswap]: z.string().optional() }).optional() }); //# sourceMappingURL=getSwapConfig.js.map