-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathqueryParams.ts
More file actions
47 lines (42 loc) · 1.35 KB
/
queryParams.ts
File metadata and controls
47 lines (42 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { useQueryState, parseAsString, parseAsInteger } from 'nuqs'
/**
* Centralized query param configuration for the swap page
* This follows nuqs best practices for organization and type safety
*/
export const swapQueryParams = {
// Token selection (using token symbols/identifiers)
useFromTokenState: () => useQueryState(
'from',
parseAsString.withDefault('').withOptions({
shallow: false, // Trigger server re-render if needed
history: 'replace' // Don't create history entries for token changes
})
),
useToTokenState: () => useQueryState(
'to',
parseAsString.withDefault('').withOptions({
shallow: false,
history: 'replace'
})
),
// Future swap parameters (can be added as needed)
useAmountState: () => useQueryState(
'amount',
parseAsString.withDefault('').withOptions({
shallow: false,
history: 'replace'
})
),
useSlippageState: () => useQueryState(
'slippage',
parseAsInteger.withDefault(10).withOptions({
shallow: false,
history: 'replace'
})
),
}
// Export individual hooks for convenience
export const useFromTokenState = swapQueryParams.useFromTokenState
export const useToTokenState = swapQueryParams.useToTokenState
export const useAmountState = swapQueryParams.useAmountState
export const useSlippageState = swapQueryParams.useSlippageState