Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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<typeof SimplePriceResponseSchema>
export type TopToken = z.infer<typeof TopTokenSchema>
export type TrendingToken = z.infer<typeof TrendingTokenSchema>

// Dev (validated) and Prod (raw) clients
const devClient = new Zodios(
baseUrl,
[
{
Expand All @@ -22,7 +29,6 @@ export const watchListCacheClient = new Zodios(
alias: 'simplePrice',
response: SimplePriceResponseSchema
},
// tokens endpoint is top 250 + additional markets
{
method: 'get',
path: '/tokens',
Expand All @@ -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<SimplePriceResponse> {
if (useValidation) {
return devClient.simplePrice()
}
const { data } = await prodClient.get<SimplePriceResponse>('/price')
return data
},

/**
* GET /tokens?currency=...
*/
async tokens(params: { queries: { currency: string } }): Promise<TopToken[]> {
if (useValidation) {
// Match Zodios’ expected input shape exactly
return devClient.tokens(params)
}
const { data } = await prodClient.get<TopToken[]>('/tokens', {
params: params.queries
})
return data
},

/**
* GET /trending
*/
async trending(params?: Record<string, never>): Promise<TrendingToken[]> {
if (useValidation) {
return devClient.trending(params)
}
const { data } = await prodClient.get<TrendingToken[]>('/trending')
return data
}
}
1 change: 0 additions & 1 deletion packages/core-mobile/e2e/helpers/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
1 change: 0 additions & 1 deletion packages/core-mobile/polyfills/bigInt_to_string.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// eslint-disable-next-line no-undef
BigInt.prototype.toJSON = function () {
return this.toString()
}
Loading