Skip to content

Commit a6a0500

Browse files
authored
docs: added ts doc for wallet-widget hooks (#381)
1 parent 857eda7 commit a6a0500

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

packages/wallet-widget/src/hooks/useNavigation.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,46 @@ interface UseNavigation {
77
goBack: () => void
88
}
99

10+
/**
11+
* Hook for managing navigation state and history within the wallet widget.
12+
* Provides functions to navigate between views and maintain navigation history.
13+
* Automatically handles scrolling to the top of the view on navigation.
14+
*
15+
* @returns {UseNavigation} Navigation control object containing:
16+
* - `setNavigation`: Function to navigate to a new view. Automatically manages history:
17+
* - If navigating to 'home', clears history
18+
* - Otherwise, adds new location to history stack
19+
* - `history`: Current navigation history stack
20+
* - `setHistory`: Direct history manipulation (use setNavigation instead when possible)
21+
* - `goBack`: Function to navigate back to previous view
22+
*
23+
* @see {@link https://docs.sequence.xyz/sdk/web/hooks/useNavigation} for more detailed documentation.
24+
*
25+
* @example
26+
* function SendView() {
27+
* const { setNavigation, goBack } = useNavigation()
28+
*
29+
* const handleSend = () => {
30+
* // Navigate to confirmation view
31+
* setNavigation({
32+
* location: 'send-confirmation',
33+
* params: { amount, recipient }
34+
* })
35+
* }
36+
*
37+
* const handleCancel = () => {
38+
* // Go back to previous view
39+
* goBack()
40+
* }
41+
*
42+
* return (
43+
* <div>
44+
* <button onClick={handleSend}>Send</button>
45+
* <button onClick={handleCancel}>Cancel</button>
46+
* </div>
47+
* )
48+
* }
49+
*/
1050
export const useNavigation = (): UseNavigation => {
1151
const { setHistory, history } = useNavigationContext()
1252

packages/wallet-widget/src/hooks/useScrollbarWidth.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import { useEffect, useState } from 'react'
22

3+
/**
4+
* Hook that returns the browser's scrollbar width based on the user agent.
5+
* Specifically handles Chrome-based browsers differently from others.
6+
*
7+
* @returns {string} The scrollbar width as a CSS pixel value:
8+
* - Returns '13px' for Chrome-based browsers (Chrome, Chromium, Chrome iOS)
9+
* - Returns '0px' for all other browsers
10+
*/
311
export const useScrollbarWidth = () => {
412
const [scrollbarWidth, setScrollbarWidth] = useState<string>('0px')
513

packages/wallet-widget/src/hooks/useSettings.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,46 @@ interface Settings {
1717

1818
type SettingsItems = Pick<Settings, 'hideCollectibles' | 'hideUnlistedTokens' | 'fiatCurrency' | 'selectedNetworks'>
1919

20+
/**
21+
* Hook to manage wallet settings with persistent storage.
22+
* Provides access to and control over user preferences for the wallet interface.
23+
* Settings are stored in localStorage and persist across sessions.
24+
*
25+
* @returns {Settings} Object containing current settings and setter functions:
26+
* - `hideCollectibles`: Whether to hide NFT collectibles in the wallet view
27+
* - `hideUnlistedTokens`: Whether to hide unverified tokens
28+
* - `fiatCurrency`: Selected fiat currency for value display (e.g., USD, EUR)
29+
* - `selectedNetworks`: Array of chain IDs for networks to display
30+
* - `setFiatCurrency`: Function to update fiat currency preference
31+
* - `setHideCollectibles`: Function to toggle collectibles visibility
32+
* - `setHideUnlistedTokens`: Function to toggle unlisted tokens visibility
33+
* - `setSelectedNetworks`: Function to update selected networks
34+
*
35+
* @see {@link https://docs.sequence.xyz/sdk/web/hooks/useSettings} for more detailed documentation.
36+
*
37+
* @example
38+
* ```tsx
39+
* // Basic usage in a component
40+
* function WalletView() {
41+
* const {
42+
* hideCollectibles,
43+
* fiatCurrency,
44+
* selectedNetworks,
45+
* setHideCollectibles
46+
* } = useSettings()
47+
*
48+
* return (
49+
* <div>
50+
* <Toggle
51+
* checked={hideCollectibles}
52+
* onChange={setHideCollectibles}
53+
* label="Hide NFTs"
54+
* />
55+
* <Text>Currency: {fiatCurrency.symbol}</Text>
56+
* </div>
57+
* )
58+
* } *
59+
*/
2060
export const useSettings = (): Settings => {
2161
const { readOnlyNetworks, displayedAssets } = useWalletSettings()
2262
const { chains } = useConfig()

0 commit comments

Comments
 (0)