Skip to content

Commit 2957e8e

Browse files
authored
tsdoc for combined hooks (#373)
* chore: tsdocs for useGetSwapPrices * chore: useGetSwapQuotes tsdoc * chore: pacakge build * docs: modify link to docs
1 parent a6a0500 commit 2957e8e

File tree

3 files changed

+141
-33
lines changed

3 files changed

+141
-33
lines changed

packages/connect/src/styles.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,6 @@ export const styles = String.raw`
302302
.my-4 {
303303
margin-block: calc(var(--spacing) * 4);
304304
}
305-
.mt-0 {
306-
margin-top: calc(var(--spacing) * 0);
307-
}
308305
.mt-0\.5 {
309306
margin-top: calc(var(--spacing) * 0.5);
310307
}
@@ -386,9 +383,6 @@ export const styles = String.raw`
386383
.inline-flex {
387384
display: inline-flex;
388385
}
389-
.table {
390-
display: table;
391-
}
392386
.aspect-square {
393387
aspect-ratio: 1 / 1;
394388
}
@@ -482,9 +476,6 @@ export const styles = String.raw`
482476
.min-h-full {
483477
min-height: 100%;
484478
}
485-
.w-1 {
486-
width: calc(var(--spacing) * 1);
487-
}
488479
.w-1\/2 {
489480
width: calc(1/2 * 100%);
490481
}
@@ -560,9 +551,6 @@ export const styles = String.raw`
560551
.w-screen {
561552
width: 100vw;
562553
}
563-
.max-w-1 {
564-
max-width: calc(var(--spacing) * 1);
565-
}
566554
.max-w-1\/2 {
567555
max-width: calc(1/2 * 100%);
568556
}
@@ -587,21 +575,12 @@ export const styles = String.raw`
587575
.min-w-full {
588576
min-width: 100%;
589577
}
590-
.flex-shrink {
591-
flex-shrink: 1;
592-
}
593578
.shrink-0 {
594579
flex-shrink: 0;
595580
}
596-
.flex-grow {
597-
flex-grow: 1;
598-
}
599581
.grow {
600582
flex-grow: 1;
601583
}
602-
.border-collapse {
603-
border-collapse: collapse;
604-
}
605584
.origin-top {
606585
transform-origin: top;
607586
}
@@ -943,9 +922,6 @@ export const styles = String.raw`
943922
.pt-0 {
944923
padding-top: calc(var(--spacing) * 0);
945924
}
946-
.pt-1 {
947-
padding-top: calc(var(--spacing) * 1);
948-
}
949925
.pt-1\.5 {
950926
padding-top: calc(var(--spacing) * 1.5);
951927
}
@@ -1215,9 +1191,6 @@ export const styles = String.raw`
12151191
.ring-border-normal {
12161192
--tw-ring-color: var(--seq-color-border-normal);
12171193
}
1218-
.ring-white {
1219-
--tw-ring-color: var(--color-white);
1220-
}
12211194
.ring-white\/10 {
12221195
--tw-ring-color: color-mix(in oklab, var(--color-white) 10%, transparent);
12231196
}
@@ -1253,10 +1226,6 @@ export const styles = String.raw`
12531226
-webkit-backdrop-filter: var(--tw-backdrop-blur,) var(--tw-backdrop-brightness,) var(--tw-backdrop-contrast,) var(--tw-backdrop-grayscale,) var(--tw-backdrop-hue-rotate,) var(--tw-backdrop-invert,) var(--tw-backdrop-opacity,) var(--tw-backdrop-saturate,) var(--tw-backdrop-sepia,);
12541227
backdrop-filter: var(--tw-backdrop-blur,) var(--tw-backdrop-brightness,) var(--tw-backdrop-contrast,) var(--tw-backdrop-grayscale,) var(--tw-backdrop-hue-rotate,) var(--tw-backdrop-invert,) var(--tw-backdrop-opacity,) var(--tw-backdrop-saturate,) var(--tw-backdrop-sepia,);
12551228
}
1256-
.backdrop-filter {
1257-
-webkit-backdrop-filter: var(--tw-backdrop-blur,) var(--tw-backdrop-brightness,) var(--tw-backdrop-contrast,) var(--tw-backdrop-grayscale,) var(--tw-backdrop-hue-rotate,) var(--tw-backdrop-invert,) var(--tw-backdrop-opacity,) var(--tw-backdrop-saturate,) var(--tw-backdrop-sepia,);
1258-
backdrop-filter: var(--tw-backdrop-blur,) var(--tw-backdrop-brightness,) var(--tw-backdrop-contrast,) var(--tw-backdrop-grayscale,) var(--tw-backdrop-hue-rotate,) var(--tw-backdrop-invert,) var(--tw-backdrop-opacity,) var(--tw-backdrop-saturate,) var(--tw-backdrop-sepia,);
1259-
}
12601229
.transition {
12611230
transition-property: color, background-color, border-color, outline-color, text-decoration-color, fill, stroke, --tw-gradient-from, --tw-gradient-via, --tw-gradient-to, opacity, box-shadow, transform, translate, scale, rotate, filter, -webkit-backdrop-filter, backdrop-filter;
12621231
transition-timing-function: var(--tw-ease, var(--default-transition-timing-function));

packages/hooks/src/hooks/Combination/useGetSwapPrices.ts

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,28 @@ interface Balance {
1515
balance: string
1616
}
1717

18+
/**
19+
* Type representing a swap price with additional currency information
20+
*
21+
* @property price - The swap price information from the API
22+
* @property info - Contract information for the currency, including name, symbol, decimals, etc.
23+
* @property balance - The user's balance of this currency
24+
*/
1825
export type SwapPricesWithCurrencyInfo = {
1926
price: SwapPrice
2027
info: ContractInfo | undefined
2128
balance: Balance
2229
}
2330

31+
/**
32+
* Arguments for the useGetSwapPrices hook
33+
*
34+
* @property userAddress - The address of the user's wallet
35+
* @property buyCurrencyAddress - The address of the currency to buy
36+
* @property buyAmount - The amount of currency to buy (in base units)
37+
* @property chainId - The chain ID where the swap will occur
38+
* @property withContractInfo - Whether to fetch additional contract info for each currency
39+
*/
2440
export interface UseGetSwapPricesArgs {
2541
userAddress: string
2642
buyCurrencyAddress: string
@@ -138,7 +154,59 @@ const getSwapPrices = async (
138154
}
139155

140156
/**
141-
* @description Gets the Swap Prices for a given currency
157+
* Hook to fetch available swap prices for a given currency pair.
158+
*
159+
* This hook provides functionality to:
160+
* - Get swap prices for a specified currency and amount
161+
* - Fetch token information and balances for available swap options
162+
* - Support both native tokens and ERC20 tokens
163+
* - Handle currency conversions and price formatting
164+
*
165+
* The hook automatically handles:
166+
* - Native token address normalization (between 0x0 and 0xEEE...)
167+
* - Contract information fetching (name, symbol, decimals, etc.)
168+
* - Error handling for failed API calls or balance fetches
169+
*
170+
* @see {@link https://docs.sequence.xyz/sdk/web/hooks/useGetSwapPrices} for more detailed documentation.
171+
*
172+
* @param args - Configuration object for the swap prices query {@link UseGetSwapPricesArgs}
173+
* @param options - Optional configuration for the hook behavior {@link HooksOptions}
174+
*
175+
* @returns A React Query result object containing:
176+
* - data: Array of {@link SwapPricesWithCurrencyInfo} objects
177+
* - isLoading: Whether the query is in progress
178+
* - isError: Whether an error occurred
179+
* - error: Any error that occurred
180+
* - Other standard React Query properties
181+
*
182+
* @example
183+
* ```tsx
184+
* import { useGetSwapPrices } from '@0xsequence/hooks'
185+
*
186+
* function SwapComponent() {
187+
* const { data: swapPrices, isLoading } = useGetSwapPrices({
188+
* userAddress: '0x123...',
189+
* buyCurrencyAddress: '0x456...',
190+
* buyAmount: '1000000000000000000', // 1 token in base units
191+
* chainId: 1,
192+
* withContractInfo: true
193+
* })
194+
*
195+
* if (isLoading) return <div>Loading...</div>
196+
*
197+
* return (
198+
* <div>
199+
* {swapPrices?.map(swap => (
200+
* <div key={swap.info?.address}>
201+
* Token: {swap.info?.symbol}
202+
* Price: {swap.price.price}
203+
* Balance: {swap.balance.balance}
204+
* </div>
205+
* ))}
206+
* </div>
207+
* )
208+
* }
209+
* ```
142210
*/
143211
export const useGetSwapPrices = (args: UseGetSwapPricesArgs, options?: HooksOptions) => {
144212
const apiClient = useAPIClient()

packages/hooks/src/hooks/Combination/useGetSwapQuote.ts

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,78 @@ import { compareAddress } from '../../utils/helpers'
77
import { useAPIClient } from '../API/useAPIClient'
88

99
/**
10-
* @description Gets the swap quote for a given currency pair
10+
* Hook to fetch a swap quote for exchanging between two currencies.
11+
*
12+
* This hook provides functionality to:
13+
* - Get a quote for swapping between two currencies (native or ERC20)
14+
* - Fetch necessary approval data for ERC20 tokens
15+
* - Generate transaction data for executing the swap
16+
*
17+
* The hook automatically handles:
18+
* - Native token address normalization (between 0x0 and 0xEEE...)
19+
* - Approval data generation for ERC20 tokens when needed
20+
* - Transaction data generation for the swap
21+
* - Error handling for failed API calls
22+
*
23+
* Go to {@link https://docs.sequence.xyz/sdk/web/hooks/useGetSwapQuote} for more detailed documentation.
24+
*
25+
* @param getSwapQuoteArgs - Configuration object for the swap quote query:
26+
* - userAddress: The address of the user's wallet
27+
* - buyCurrencyAddress: The address of the currency to buy
28+
* - sellCurrencyAddress: The address of the currency to sell
29+
* - buyAmount: The amount of currency to buy (in base units)
30+
* - chainId: The chain ID where the swap will occur
31+
* - includeApprove: Whether to include approval data for ERC20 tokens
32+
*
33+
* @param options - Optional configuration for the hook behavior:
34+
* - disabled: Whether to disable the query
35+
* - retry: Whether to retry failed queries
36+
* - Other standard React Query options
37+
*
38+
* @returns A React Query result object containing:
39+
* - data: The swap quote data including:
40+
* - currencyAddress: The address of the currency being swapped
41+
* - currencyBalance: The user's balance of the currency
42+
* - price: The price for the swap
43+
* - maxPrice: The maximum price (including slippage)
44+
* - to: The target contract address for the swap
45+
* - transactionData: The calldata for the swap transaction
46+
* - transactionValue: The value to send with the transaction (for native tokens)
47+
* - approveData: The approval transaction data (if needed)
48+
* - isLoading: Whether the query is in progress
49+
* - isError: Whether an error occurred
50+
* - error: Any error that occurred
51+
* - Other standard React Query properties
52+
*
53+
* @see {@link https://docs.sequence.xyz/sdk/web/hooks/useGetSwapQuote} for more detailed documentation.
54+
*
55+
* @example
56+
* ```tsx
57+
* import { useGetSwapQuote } from '@0xsequence/hooks'
58+
*
59+
* function SwapComponent() {
60+
* const { data: swapQuote, isLoading } = useGetSwapQuote({
61+
* userAddress: '0x123...',
62+
* buyCurrencyAddress: '0x456...',
63+
* sellCurrencyAddress: '0x789...',
64+
* buyAmount: '1000000000000000000', // 1 token in base units
65+
* chainId: 1,
66+
* includeApprove: true
67+
* })
68+
*
69+
* if (isLoading) return <div>Loading...</div>
70+
*
71+
* return (
72+
* <div>
73+
* <div>Price: {swapQuote?.price}</div>
74+
* <div>Max Price: {swapQuote?.maxPrice}</div>
75+
* <button onClick={() => executeSwap(swapQuote)}>
76+
* Swap Tokens
77+
* </button>
78+
* </div>
79+
* )
80+
* }
81+
* ```
1182
*/
1283
export const useGetSwapQuote = (getSwapQuoteArgs: GetSwapQuoteArgs, options?: HooksOptions) => {
1384
const apiClient = useAPIClient()

0 commit comments

Comments
 (0)