Skip to content

Commit 3ea013c

Browse files
authored
CP-12564: Migrate watchlist proxy api to the new token aggregator api (#3360)
1 parent e264126 commit 3ea013c

File tree

19 files changed

+323
-161492
lines changed

19 files changed

+323
-161492
lines changed

packages/core-mobile/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,7 @@ expo-env.d.ts
9797

9898
# Branch
9999
/ios/config.xcconfig
100+
101+
# generated api clients
102+
app/utils/network/generated/glacierApi.client.ts
103+
app/utils/network/generated/tokenAggregatorApi.client.ts

packages/core-mobile/app/consts/reactQueryKeys.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export enum ReactQueryKeys {
1414

1515
NETWORKS = 'networks',
1616
NETWORK_CONTRACT_TOKENS = 'networkContractTokens',
17-
WATCHLIST_TOKENS_AND_CHARTS = 'watchlistTokensAndCharts',
18-
WATCHLIST_TRENDING_TOKENS_AND_CHARTS = 'watchlistTrendingTokensAndCharts',
17+
WATCHLIST_TOP_TOKENS = 'watchlistTopTokens',
18+
WATCHLIST_TRENDING_TOKENS = 'watchlistTrendingTokens',
1919
WATCHLIST_PRICES = 'watchlistPrices',
2020
WATCHLIST_TOKEN_SEARCH = 'watchlistTokenSearch',
2121
LAST_TRANSACTED_ERC20_NETWORKS = 'lastTransactedErc20Networks',

packages/core-mobile/app/hooks/watchlist/useGetTrendingTokens.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ export const useGetTrendingTokens = <TData = TrendingToken[]>(
1818

1919
return useQuery({
2020
enabled: isFocused,
21-
queryKey: [
22-
ReactQueryKeys.WATCHLIST_TRENDING_TOKENS_AND_CHARTS,
23-
exchangeRate
24-
],
21+
queryKey: [ReactQueryKeys.WATCHLIST_TRENDING_TOKENS, exchangeRate],
2522
queryFn: async () => {
2623
const tokens = await runAfterInteractions(async () => {
2724
return WatchlistService.getTrendingTokens(exchangeRate)

packages/core-mobile/app/hooks/watchlist/useGetTokensAndCharts.ts renamed to packages/core-mobile/app/hooks/watchlist/useTopTokens.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,18 @@ import { selectSelectedCurrency } from 'store/settings/currency'
77
import { TokensAndCharts } from 'store/watchlist'
88
import { runAfterInteractions } from 'utils/runAfterInteractions'
99

10-
export const useGetTokensAndCharts = (): UseQueryResult<
11-
TokensAndCharts,
12-
Error
13-
> => {
10+
export const useTopTokens = (): UseQueryResult<TokensAndCharts, Error> => {
1411
const currency = useSelector(selectSelectedCurrency)
1512
const isFocused = useIsFocused()
1613

1714
return useQuery({
1815
enabled: isFocused,
19-
queryKey: [ReactQueryKeys.WATCHLIST_TOKENS_AND_CHARTS, currency],
16+
queryKey: [ReactQueryKeys.WATCHLIST_TOP_TOKENS, currency],
2017
queryFn: () => {
2118
return runAfterInteractions(async () => {
22-
return WatchlistService.getTokens(currency)
19+
return WatchlistService.getTopTokens(currency)
2320
})
2421
},
25-
refetchInterval: 60000 // 1 minute
22+
refetchInterval: 120000 // 2 minutes
2623
})
2724
}

packages/core-mobile/app/hooks/watchlist/useWatchlist.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { LocalTokenWithBalance } from 'store/balance/types'
1616
import { getCaip2ChainIdForToken } from 'utils/caip2ChainIds'
1717
import { isNetworkContractToken } from 'utils/isNetworkContractToken'
1818
import { useGetPrices } from './useGetPrices'
19-
import { useGetTokensAndCharts } from './useGetTokensAndCharts'
19+
import { useTopTokens } from './useTopTokens'
2020
import { useGetTrendingTokens } from './useGetTrendingTokens'
2121

2222
type UseWatchListReturnType = {
@@ -47,7 +47,7 @@ export const useWatchlist = (): UseWatchListReturnType => {
4747
isLoading: isLoadingTopTokens,
4848
refetch: refetchTopTokens,
4949
isRefetching: isRefetchingTopTokens
50-
} = useGetTokensAndCharts()
50+
} = useTopTokens()
5151
const {
5252
data: trendingTokensResponse,
5353
isLoading: isLoadingTrendingTokens,

packages/core-mobile/app/hooks/watchlist/useWatchlistListener.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const useWatchlistListener = (): void => {
1717
effect: async () => {
1818
await queryClient.invalidateQueries({
1919
queryKey: [
20-
ReactQueryKeys.WATCHLIST_TOKENS_AND_CHARTS,
20+
ReactQueryKeys.WATCHLIST_TOP_TOKENS,
2121
ReactQueryKeys.WATCHLIST_PRICES
2222
]
2323
})

packages/core-mobile/app/new/features/track/market/components/MarketScreen.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ const MarketScreen = ({
2828
isLoadingTopTokens,
2929
refetchTopTokens
3030
} = useWatchlist()
31-
3231
const { data, sort, view } = useTrackSortAndView(topTokens, prices)
3332
const listType = view.selected as MarketView
3433

packages/core-mobile/app/services/token/TokenService.test.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as sdk from '@avalabs/core-coingecko-sdk'
22
import { watchListCacheClient } from 'services/watchlist/watchListCacheClient'
33
import * as inMemoryCache from 'utils/InMemoryCache'
44
import TokenService from './TokenService'
5-
import TOP_MARKETS from './__mocks__/tokens.json'
65
import { coingeckoProxyClient as proxy } from './coingeckoProxyClient'
76
import WATCHLIST_PRICE from './__mocks__/watchlistPrice.json'
87
import MARKET_CHART from './__mocks__/marketChart.json'
@@ -21,31 +20,8 @@ jest.mock('@avalabs/core-coingecko-sdk', () => ({
2120

2221
const MOCK_429 = { status: 429, message: 'Too many requests' }
2322

24-
const watchlistMarketsMock = jest.spyOn(watchListCacheClient, 'tokens')
25-
26-
// @ts-ignore
27-
watchlistMarketsMock.mockImplementation(async () => {
28-
return TOP_MARKETS
29-
})
30-
3123
const inMemoryCacheMock = jest.spyOn(inMemoryCache, 'getCache')
3224

33-
describe('getMarketsFromWatchlistCache', () => {
34-
it('should return all cached markets', async () => {
35-
const result = await TokenService.getMarketsFromWatchlistCache({
36-
currency: sdk.VsCurrencyType.USD
37-
})
38-
expect(result.length).toEqual(1758)
39-
})
40-
it('should not have been called watchListCacheClient.markets', async () => {
41-
inMemoryCacheMock.mockImplementation(() => TOP_MARKETS)
42-
TokenService.getMarketsFromWatchlistCache({
43-
currency: sdk.VsCurrencyType.USD
44-
})
45-
expect(watchlistMarketsMock).not.toHaveBeenCalled()
46-
})
47-
})
48-
4925
describe('getTokenSearch', () => {
5026
const proxySearchCoinsMock = jest.spyOn(proxy, 'searchCoins')
5127
const { coinsSearch } = require('@avalabs/core-coingecko-sdk')

packages/core-mobile/app/services/token/TokenService.ts

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ import {
3232
CoinsSearchResponse,
3333
ContractMarketChartResponse,
3434
CoinsInfoResponse,
35-
TrendingToken,
36-
TopToken
35+
TrendingToken
3736
} from './types'
3837
import {
3938
coingeckoRetry,
@@ -99,31 +98,6 @@ export class TokenService {
9998
}
10099
}
101100

102-
/**
103-
* Get market data from cached watchlist
104-
* @param currency the currency to be used
105-
* @returns the cached markets
106-
*/
107-
async getMarketsFromWatchlistCache({
108-
currency = VsCurrencyType.USD
109-
}: GetMarketsParams): Promise<TopToken[]> {
110-
let data: TopToken[] | undefined
111-
112-
const cacheId = `getMarkets-${currency}`
113-
114-
data = getCache(cacheId)
115-
116-
if (data === undefined) {
117-
data = await watchListCacheClient.tokens({
118-
queries: { currency }
119-
})
120-
121-
setCache(cacheId, data)
122-
}
123-
124-
return data ?? []
125-
}
126-
127101
/**
128102
* Get token search results
129103
* @param query the search query

0 commit comments

Comments
 (0)