Skip to content

Commit 1a8dda4

Browse files
committed
code review
1 parent 370cab4 commit 1a8dda4

File tree

5 files changed

+46
-7
lines changed

5 files changed

+46
-7
lines changed

packages/core-mobile/app/new/features/swapV2/consts.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Config from 'react-native-config'
12
import { Environment } from '@avalabs/unified-asset-transfer'
23
import { BuildTxParams } from "features/swap/services/ParaswapService"
34

@@ -100,7 +101,7 @@ export const MAX_SLIPPAGE_PERCENT = 50
100101
*/
101102
// TODO add to env variables once stable
102103
export const MARKR_API_URL =
103-
process.env.MARKR_API_URL ?? 'https://proxy-api.avax.network/proxy/markr-staging'
104+
Config.MARKR_API_URL ?? 'https://proxy-api.avax.network/proxy/markr-staging'
104105

105106
/**
106107
* Determines the Fusion SDK environment based on app settings

packages/core-mobile/app/new/features/swapV2/hooks/useSupportedChains.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { Network } from '@avalabs/core-chains-sdk'
44
import { ReactQueryKeys } from 'consts/reactQueryKeys'
55
import { useNetworks } from 'hooks/networks/useNetworks'
66
import Logger from 'utils/Logger'
7+
import { exponentialBackoff } from 'utils/reactQuery'
78
import { isAvalancheChainId } from 'services/network/utils/isAvalancheNetwork'
89
import FusionService from '../services/FusionService'
910

@@ -41,7 +42,8 @@ export function useSupportedChains(): {
4142
return FusionService.getSupportedChains()
4243
},
4344
staleTime: STALE_TIME,
44-
enabled: FusionService.isInitialized()
45+
retry: 3,
46+
retryDelay: exponentialBackoff(5000)
4547
})
4648

4749
// Convert CAIP-2 IDs to Network objects from enabled networks
@@ -53,8 +55,11 @@ export function useSupportedChains(): {
5355
.filter((network): network is Network => network !== undefined)
5456
.sort((a, b) => {
5557
// Avalanche C-Chain always first
56-
if (isAvalancheChainId(a.chainId)) return -1
57-
if (isAvalancheChainId(b.chainId)) return 1
58+
const aIsAvalanche = isAvalancheChainId(a.chainId)
59+
const bIsAvalanche = isAvalancheChainId(b.chainId)
60+
61+
if (aIsAvalanche && !bIsAvalanche) return -1
62+
if (!aIsAvalanche && bIsAvalanche) return 1
5863
return 0
5964
})
6065

packages/core-mobile/app/store/rpc/utils/assert.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ import { rpcErrors } from '@metamask/rpc-errors'
77
* @param value - The value to check
88
* @param message - Optional error message
99
* @throws RPC internal error if value is falsy
10+
* @example
11+
* const foo: string | null = getValue()
12+
* assert(foo, 'foo is required')
13+
* // foo is now typed as string (non-nullable)
1014
*/
11-
export function assert(
12-
value: unknown,
15+
export function assert<T>(
16+
value: T,
1317
message?: string
14-
): asserts value is NonNullable<unknown> {
18+
): asserts value is NonNullable<T> {
1519
if (!value) {
1620
throw rpcErrors.internal({
1721
data: { reason: message || 'Assertion failed' }

packages/core-mobile/app/utils/api/clients/profileApiClient.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import Config from 'react-native-config'
2+
import Logger from 'utils/Logger'
23
import { appCheckFetch } from '../common/appCheckFetch'
34
import { CORE_HEADERS } from '../constants'
45
import { createClient } from '../generated/profileApi.client/client'
56

7+
if (!Config.CORE_PROFILE_URL)
8+
Logger.warn(
9+
'CORE_PROFILE_URL is missing in env file. Profile API will not work properly.'
10+
)
11+
612
/**
713
* Profile API client configured with:
814
* - nitroFetch (via appCheckFetch) for better performance
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* React Query utility functions
3+
*/
4+
5+
/**
6+
* Exponential backoff with a maximum delay cap for React Query retries
7+
*
8+
* @param maxDelayMs - Maximum delay in milliseconds (default: 5000ms)
9+
* @returns Function compatible with React Query's retryDelay option
10+
*
11+
* @example
12+
* useQuery({
13+
* queryKey: ['data'],
14+
* queryFn: fetchData,
15+
* retry: 3,
16+
* retryDelay: exponentialBackoff(5000) // 1s, 2s, 4s
17+
* })
18+
*/
19+
export const exponentialBackoff = (maxDelayMs = 5000) => {
20+
return (attemptIndex: number): number => {
21+
return Math.min(1000 * 2 ** attemptIndex, maxDelayMs)
22+
}
23+
}

0 commit comments

Comments
 (0)