diff --git a/packages/core-mobile/app/services/watchlist/watchListCacheClient.ts b/packages/core-mobile/app/services/watchlist/watchListCacheClient.ts index f02fd69a8d..f592deb315 100644 --- a/packages/core-mobile/app/services/watchlist/watchListCacheClient.ts +++ b/packages/core-mobile/app/services/watchlist/watchListCacheClient.ts @@ -1,6 +1,7 @@ +import axios from 'axios' import { Zodios } from '@zodios/core' import Config from 'react-native-config' -import { array, string } from 'zod' +import { array, string, z } from 'zod' import Logger from 'utils/Logger' import { SimplePriceResponseSchema, @@ -11,9 +12,15 @@ import { if (!Config.PROXY_URL) Logger.warn('PROXY_URL is missing in env file. Watchlist is disabled.') -const baseUrl = Config.PROXY_URL + '/watchlist' +const baseUrl = `${Config.PROXY_URL}/watchlist` -export const watchListCacheClient = new Zodios( +// Infer types from schemas for typings +export type SimplePriceResponse = z.infer +export type TopToken = z.infer +export type TrendingToken = z.infer + +// Dev (validated) and Prod (raw) clients +const devClient = new Zodios( baseUrl, [ { @@ -22,7 +29,6 @@ export const watchListCacheClient = new Zodios( alias: 'simplePrice', response: SimplePriceResponseSchema }, - // tokens endpoint is top 250 + additional markets { method: 'get', path: '/tokens', @@ -39,9 +45,53 @@ export const watchListCacheClient = new Zodios( ], { axiosConfig: { - headers: { - 'Content-Type': 'application/json' - } + headers: { 'Content-Type': 'application/json' } } } ) + +const prodClient = axios.create({ + baseURL: baseUrl, + headers: { 'Content-Type': 'application/json' } +}) + +// Force validation on/off +const useValidation = __DEV__ //in normal use + +export const watchListCacheClient = { + /** + * GET /price + */ + async simplePrice(): Promise { + if (useValidation) { + return devClient.simplePrice() + } + const { data } = await prodClient.get('/price') + return data + }, + + /** + * GET /tokens?currency=... + */ + async tokens(params: { queries: { currency: string } }): Promise { + if (useValidation) { + // Match Zodios’ expected input shape exactly + return devClient.tokens(params) + } + const { data } = await prodClient.get('/tokens', { + params: params.queries + }) + return data + }, + + /** + * GET /trending + */ + async trending(params?: Record): Promise { + if (useValidation) { + return devClient.trending(params) + } + const { data } = await prodClient.get('/trending') + return data + } +} diff --git a/packages/core-mobile/e2e/helpers/actions.ts b/packages/core-mobile/e2e/helpers/actions.ts index 8307ee24f7..aa4d7ee1a2 100644 --- a/packages/core-mobile/e2e/helpers/actions.ts +++ b/packages/core-mobile/e2e/helpers/actions.ts @@ -279,7 +279,6 @@ const swipe = async ( speed: Detox.Speed = 'slow', offset = 0.25, index = 0 - // eslint-disable-next-line max-params ) => { await element(item).atIndex(index).swipe(direction, speed, offset) } diff --git a/packages/core-mobile/polyfills/bigInt_to_string.js b/packages/core-mobile/polyfills/bigInt_to_string.js index 160eec58fe..e90c3e2d3b 100644 --- a/packages/core-mobile/polyfills/bigInt_to_string.js +++ b/packages/core-mobile/polyfills/bigInt_to_string.js @@ -1,4 +1,3 @@ -// eslint-disable-next-line no-undef BigInt.prototype.toJSON = function () { return this.toString() }