@txnlab/use-wallet-ui-react 0.4.2 → 1.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,432 +1,400 @@
1
1
  # @txnlab/use-wallet-ui-react
2
2
 
3
- Ready-to-use UI components for Algorand wallet integration, built as a companion to [@txnlab/use-wallet](https://github.com/TxnLab/use-wallet).
3
+ Ready-to-use React UI components for Algorand wallet integration, built as a companion to [@txnlab/use-wallet-react](https://github.com/TxnLab/use-wallet).
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/@txnlab/use-wallet-ui-react.svg)](https://www.npmjs.com/package/@txnlab/use-wallet-ui-react)
6
+ [![CI](https://github.com/TxnLab/use-wallet-ui/actions/workflows/ci.yml/badge.svg)](https://github.com/TxnLab/use-wallet-ui/actions/workflows/ci.yml)
6
7
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
8
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.9-blue.svg)](https://www.typescriptlang.org/)
7
9
 
8
- ## Quick Start
10
+ ## Table of Contents
11
+
12
+ - [Installation](#installation)
13
+ - [Quick Start](#quick-start)
14
+ - [Styling](#styling)
15
+ - [Customization](#customization)
16
+ - [Theming](#theming)
17
+ - [Components](#components)
18
+ - [Hooks](#hooks)
19
+ - [Tanstack Query Integration](#tanstack-query-integration)
20
+ - [Migration from v0.x](#migration-from-v0x)
21
+ - [License](#license)
22
+
23
+ ## Installation
9
24
 
10
25
  ```bash
11
26
  npm install @txnlab/use-wallet-ui-react
27
+ # or
28
+ yarn add @txnlab/use-wallet-ui-react
29
+ # or
30
+ pnpm add @txnlab/use-wallet-ui-react
31
+ # or
32
+ bun add @txnlab/use-wallet-ui-react
12
33
  ```
13
34
 
14
- This package provides polished UI components that work on top of `@txnlab/use-wallet-react`. Choose the setup that matches your project:
35
+ ### Requirements
15
36
 
16
- ### If you're using Tailwind CSS
37
+ - `@txnlab/use-wallet-react` v4+
38
+ - `algosdk` v3+
39
+ - React 18 or 19
17
40
 
18
- ```jsx
19
- import {
20
- NetworkId,
21
- WalletId,
22
- WalletManager,
23
- WalletProvider,
24
- } from '@txnlab/use-wallet-react'
25
- import { WalletUIProvider, WalletButton } from '@txnlab/use-wallet-ui-react'
26
-
27
- // Configure the wallets you want to use
28
- const walletManager = new WalletManager({
29
- wallets: [
30
- WalletId.PERA,
31
- WalletId.DEFLY,
32
- WalletId.LUTE,
33
- // Add more wallets as needed
34
- ],
35
- defaultNetwork: NetworkId.MAINNET,
36
- })
37
-
38
- function App() {
39
- return (
40
- <WalletProvider manager={walletManager}>
41
- <WalletUIProvider>
42
- <div>
43
- <WalletButton />
44
- </div>
45
- </WalletUIProvider>
46
- </WalletProvider>
47
- )
48
- }
49
- ```
50
-
51
- ### If you're NOT using Tailwind CSS
41
+ ## Quick Start
52
42
 
53
43
  ```jsx
54
- import {
55
- NetworkId,
56
- WalletId,
57
- WalletManager,
58
- WalletProvider,
59
- } from '@txnlab/use-wallet-react'
44
+ import { NetworkId, WalletId, WalletManager, WalletProvider } from '@txnlab/use-wallet-react'
60
45
  import { WalletUIProvider, WalletButton } from '@txnlab/use-wallet-ui-react'
61
- // Import our pre-built styles
46
+
47
+ // Import styles if NOT using Tailwind CSS
62
48
  import '@txnlab/use-wallet-ui-react/dist/style.css'
63
49
 
64
- // Configure the wallets you want to use
65
50
  const walletManager = new WalletManager({
66
51
  wallets: [
67
52
  WalletId.PERA,
68
53
  WalletId.DEFLY,
69
54
  WalletId.LUTE,
70
- // Add more wallets as needed
55
+ WalletId.EXODUS,
56
+ {
57
+ id: WalletId.WALLETCONNECT,
58
+ options: { projectId: 'your-project-id' },
59
+ },
71
60
  ],
72
- defaultNetwork: NetworkId.MAINNET,
61
+ defaultNetwork: NetworkId.TESTNET,
73
62
  })
74
63
 
75
64
  function App() {
76
65
  return (
77
66
  <WalletProvider manager={walletManager}>
78
67
  <WalletUIProvider>
79
- {/* Add data-wallet-ui attribute when not using Tailwind */}
80
- <div data-wallet-ui>
81
- <WalletButton />
82
- </div>
68
+ <WalletButton />
83
69
  </WalletUIProvider>
84
70
  </WalletProvider>
85
71
  )
86
72
  }
87
73
  ```
88
74
 
89
- That's it! You now have a fully functional wallet connection system with:
90
-
91
- - Clean, accessible UI components
92
- - NFD integration
93
- - ALGO balance display
94
- - Account switching
95
- - Dark/light mode support
96
-
97
- > **Note:** This is the React implementation of the UI components. Future versions will support Vue and SolidJS to match all frameworks supported by the core `@txnlab/use-wallet` library.
75
+ The `WalletButton` handles everything:
98
76
 
99
- ---
77
+ - Shows "Connect Wallet" when disconnected
78
+ - Opens wallet selection dialog
79
+ - Displays wallet address/NFD name and avatar when connected
80
+ - Provides account switching and disconnect options
100
81
 
101
- ## Table of Contents
102
-
103
- - [Dependencies](#dependencies)
104
- - [Installation](#installation)
105
- - [Styling Options](#styling-options)
106
- - [Without Tailwind CSS](#without-tailwind-css)
107
- - [With Tailwind CSS](#with-tailwind-css)
108
- - [Theming](#theming)
109
- - [Basic Usage](#basic-usage)
110
- - [Component API](#component-api)
111
- - [NFD Integration](#nfd-integration)
112
- - [Account Information](#account-information)
113
- - [Advanced Customization](#advanced-customization)
114
- - [Integration with Tanstack Query](#integration-with-tanstack-query)
115
- - [How It Works](#how-it-works)
116
- - [License](#license)
117
-
118
- ---
119
-
120
- ## Dependencies
121
-
122
- ### Required
123
-
124
- - `@txnlab/use-wallet-react` v4
125
- - `algosdk` v3 (required for use-wallet v4)
126
- - React v18 or v19
127
-
128
- ### Optional & Integrated
129
-
130
- - **Tanstack Query**: Used internally for NFD lookups (built-in, but can integrate with your existing setup)
131
- - **Tailwind CSS**: Supported but not required (the library works with or without it)
132
-
133
- ## Installation
134
-
135
- ```bash
136
- # npm
137
- npm install @txnlab/use-wallet-ui-react
138
-
139
- # yarn
140
- yarn add @txnlab/use-wallet-ui-react
141
-
142
- # pnpm
143
- pnpm add @txnlab/use-wallet-ui-react
144
- ```
145
-
146
- ## Styling Options
82
+ ## Styling
147
83
 
148
84
  The library supports two styling approaches:
149
85
 
150
- ### Option 1: Using Tailwind CSS (Recommended)
151
-
152
- Using [Tailwind CSS](https://tailwindcss.com/) provides the richest customization experience:
86
+ ### With Tailwind CSS
153
87
 
154
- - Full access to Tailwind's utility classes for customization
155
- - Hover, focus, and active states with simple modifiers
156
- - Dark mode support with the `dark:` variant
157
- - Responsive design with breakpoint prefixes
158
- - Animation and transition utilities
159
- - Theme customization through your Tailwind config
88
+ Components use Tailwind utility classes. Configure Tailwind to scan our package:
160
89
 
161
- #### With Tailwind CSS v4
90
+ **Tailwind v4:**
162
91
 
163
92
  ```css
164
- /* In your CSS file */
165
93
  @import 'tailwindcss';
166
94
  @source "../node_modules/@txnlab/use-wallet-ui-react";
167
95
  ```
168
96
 
169
- This uses the `@source` directive to tell Tailwind to scan our library for classes. See the [Tailwind CSS v4 Installation Guide](https://tailwindcss.com/docs/installation) for setup instructions.
170
-
171
- #### With Tailwind CSS v3
97
+ **Tailwind v3:**
172
98
 
173
99
  ```js
174
100
  // tailwind.config.js
175
101
  module.exports = {
176
102
  content: [
177
103
  './src/**/*.{js,ts,jsx,tsx}',
178
- // Add this line to scan our components
179
104
  './node_modules/@txnlab/use-wallet-ui-react/dist/**/*.{js,ts,jsx,tsx}',
180
105
  ],
181
- // ...rest of your config
182
106
  }
183
107
  ```
184
108
 
185
- See the [Tailwind CSS v3 Installation Guide](https://v3.tailwindcss.com/docs/installation) for setup instructions.
186
-
187
- ### Option 2: Using the Pre-built CSS
109
+ ### Without Tailwind CSS
188
110
 
189
- For projects that don't use Tailwind, we provide a pre-built CSS file:
111
+ Import our pre-built CSS:
190
112
 
191
113
  ```jsx
192
- // 1. Import the pre-built CSS
193
114
  import '@txnlab/use-wallet-ui-react/dist/style.css'
115
+ ```
194
116
 
195
- function App() {
196
- return (
197
- // 2. Add the data-wallet-ui attribute to any container with wallet components
198
- <div data-wallet-ui>
199
- <WalletButton />
200
- </div>
201
- )
202
- }
117
+ ## Customization
118
+
119
+ v1.0 introduces a flexible customization system with multiple approaches.
120
+
121
+ ### Size Variants
122
+
123
+ ```jsx
124
+ <WalletButton size="sm" /> {/* Small */}
125
+ <WalletButton size="md" /> {/* Medium (default) */}
126
+ <WalletButton size="lg" /> {/* Large */}
203
127
  ```
204
128
 
205
- **Important:** Add the `data-wallet-ui` attribute to scope our styles and prevent conflicts with your application's existing styles.
129
+ ### CSS Variable Overrides
206
130
 
207
- While this approach offers less flexibility for customization compared to Tailwind, it provides a simple way to use the components with minimal setup.
131
+ Theme colors are CSS custom properties that can be overridden globally or per-instance.
208
132
 
209
- ## Theming
133
+ **Global override (in your CSS):**
210
134
 
211
- The library supports light and dark modes out of the box. You can control the theme using the `theme` prop on `WalletUIProvider`.
135
+ ```css
136
+ [data-wallet-theme] {
137
+ --wui-color-primary: #8b5cf6;
138
+ --wui-color-primary-hover: #7c3aed;
139
+ --wui-color-primary-text: #ffffff;
140
+ }
141
+ ```
212
142
 
213
- ### Theme Options
143
+ **Scoped override (on a wrapper):**
144
+
145
+ ```css
146
+ .my-purple-button {
147
+ --wui-color-primary: #8b5cf6;
148
+ --wui-color-primary-hover: #7c3aed;
149
+ }
150
+ ```
214
151
 
215
152
  ```jsx
216
- <WalletUIProvider theme="system"> {/* Default: follows OS/browser preference */}
217
- {/* ... */}
218
- </WalletUIProvider>
153
+ <div className="my-purple-button">
154
+ <WalletButton />
155
+ </div>
156
+ ```
219
157
 
220
- <WalletUIProvider theme="light"> {/* Always use light mode */}
221
- {/* ... */}
222
- </WalletUIProvider>
158
+ **Inline style override:**
223
159
 
224
- <WalletUIProvider theme="dark"> {/* Always use dark mode */}
225
- {/* ... */}
226
- </WalletUIProvider>
160
+ ```jsx
161
+ <WalletButton
162
+ style={{
163
+ '--wui-color-primary': '#10b981',
164
+ '--wui-color-primary-hover': '#059669',
165
+ } as React.CSSProperties}
166
+ />
227
167
  ```
228
168
 
229
- ### How Theming Works
169
+ ### Available CSS Variables
170
+
171
+ | Variable | Description |
172
+ |----------|-------------|
173
+ | `--wui-color-primary` | Primary button background |
174
+ | `--wui-color-primary-hover` | Primary button hover state |
175
+ | `--wui-color-primary-text` | Primary button text |
176
+ | `--wui-color-bg` | Panel/dialog background |
177
+ | `--wui-color-bg-secondary` | Secondary background |
178
+ | `--wui-color-bg-tertiary` | Tertiary background |
179
+ | `--wui-color-bg-hover` | Hover background |
180
+ | `--wui-color-text` | Primary text color |
181
+ | `--wui-color-text-secondary` | Secondary text color |
182
+ | `--wui-color-text-tertiary` | Tertiary text color |
183
+ | `--wui-color-border` | Border color |
184
+ | `--wui-color-link` | Link color |
185
+ | `--wui-color-link-hover` | Link hover color |
186
+ | `--wui-color-overlay` | Modal overlay color |
187
+ | `--wui-color-danger-bg` | Danger button background |
188
+ | `--wui-color-danger-bg-hover` | Danger button hover |
189
+ | `--wui-color-danger-text` | Danger button text |
190
+ | `--wui-color-avatar-bg` | Avatar placeholder background |
191
+ | `--wui-color-avatar-icon` | Avatar placeholder icon |
192
+
193
+ ### className Prop
194
+
195
+ Add custom classes (useful with Tailwind):
196
+
197
+ ```jsx
198
+ <WalletButton className="rounded-full shadow-lg" />
199
+ ```
230
200
 
231
- The library uses CSS custom properties for colors, which are automatically applied based on the theme setting:
201
+ ### Direct CSS Selectors
232
202
 
233
- 1. **`theme="system"` (default)**: The library respects the user's OS/browser preference via the `prefers-color-scheme` media query.
203
+ Target the button element directly:
234
204
 
235
- 2. **`theme="light"` or `theme="dark"`**: Explicitly sets the theme regardless of system preference.
205
+ ```css
206
+ .pill-button [data-wallet-button] {
207
+ border-radius: 9999px;
208
+ }
209
+ ```
236
210
 
237
- 3. **Tailwind `.dark` class**: The library also respects the `.dark` class on ancestor elements (common Tailwind convention). If a `.dark` class is present on an ancestor, dark mode will be used unless explicitly overridden with `theme="light"`.
211
+ ```jsx
212
+ <div className="pill-button">
213
+ <WalletButton />
214
+ </div>
215
+ ```
238
216
 
239
- ### Accessing Theme in Your App
217
+ ### Custom Trigger Button
240
218
 
241
- You can access the current theme state using the `useWalletUI` hook:
219
+ For complete control, use the Menu components with your own button:
242
220
 
243
221
  ```jsx
244
- import { useWalletUI } from '@txnlab/use-wallet-ui-react'
222
+ import { useWallet } from '@txnlab/use-wallet-react'
223
+ import { ConnectWalletMenu, ConnectedWalletMenu } from '@txnlab/use-wallet-ui-react'
245
224
 
246
- function MyComponent() {
247
- const { theme, resolvedTheme } = useWalletUI()
225
+ function CustomWalletButton() {
226
+ const { activeAddress } = useWallet()
248
227
 
249
- // theme: 'light' | 'dark' | 'system' (the prop value)
250
- // resolvedTheme: 'light' | 'dark' (the actual applied theme)
228
+ if (activeAddress) {
229
+ return (
230
+ <ConnectedWalletMenu>
231
+ <button className="my-connected-button">
232
+ {activeAddress.slice(0, 8)}...
233
+ </button>
234
+ </ConnectedWalletMenu>
235
+ )
236
+ }
251
237
 
252
- return <div>Current theme: {resolvedTheme}</div>
238
+ return (
239
+ <ConnectWalletMenu>
240
+ <button className="my-connect-button">Connect Wallet</button>
241
+ </ConnectWalletMenu>
242
+ )
253
243
  }
254
244
  ```
255
245
 
256
- ### Custom Theme Colors
246
+ The child element becomes the trigger - the library handles all the menu logic.
247
+
248
+ ### Theme-Aware Customization
257
249
 
258
- The library uses CSS custom properties that you can override in your own CSS to customize the color scheme:
250
+ Create different styles for light and dark modes:
259
251
 
260
252
  ```css
261
- /* Override theme colors */
262
- [data-wallet-ui] {
263
- --wui-color-primary: #your-primary-color;
264
- --wui-color-primary-hover: #your-primary-hover;
265
- --wui-color-primary-text: #your-primary-text;
266
- --wui-color-bg: #your-background;
267
- --wui-color-bg-secondary: #your-secondary-bg;
268
- --wui-color-bg-tertiary: #your-tertiary-bg;
269
- --wui-color-bg-hover: #your-hover-bg;
270
- --wui-color-text: #your-text-color;
271
- --wui-color-text-secondary: #your-secondary-text;
272
- --wui-color-text-tertiary: #your-tertiary-text;
273
- --wui-color-border: #your-border-color;
274
- --wui-color-link: #your-link-color;
275
- --wui-color-link-hover: #your-link-hover;
276
- --wui-color-overlay: rgba(0, 0, 0, 0.3);
253
+ .amber-theme {
254
+ --wui-color-primary: #f59e0b;
255
+ --wui-color-primary-hover: #d97706;
277
256
  }
278
257
 
279
- /* Override dark mode colors */
280
- [data-wallet-ui][data-theme='dark'] {
281
- --wui-color-primary: #your-dark-primary;
282
- /* ... other dark mode overrides */
258
+ .dark .amber-theme {
259
+ --wui-color-primary: rgba(245, 179, 71, 0.15);
260
+ --wui-color-primary-hover: rgba(245, 179, 71, 0.25);
283
261
  }
284
- ```
285
262
 
286
- ## Basic Usage
263
+ .dark .amber-theme [data-wallet-button] {
264
+ border: 1px solid rgba(245, 179, 71, 0.3);
265
+ }
266
+ ```
287
267
 
288
- This library builds on top of `@txnlab/use-wallet-react` to provide UI components for wallet connectivity. Here's the basic setup:
268
+ See the [react-custom example](../../examples/react-custom) for comprehensive demos.
289
269
 
290
- ### 1. Set up the Providers
270
+ ## Theming
291
271
 
292
- ```jsx
293
- import {
294
- NetworkId,
295
- WalletId,
296
- WalletManager,
297
- WalletProvider,
298
- } from '@txnlab/use-wallet-react'
299
- import { WalletUIProvider } from '@txnlab/use-wallet-ui-react'
272
+ The library supports automatic light/dark mode.
300
273
 
301
- // Create and configure the wallet manager
302
- const walletManager = new WalletManager({
303
- wallets: [
304
- // Add the wallets you want to support
305
- WalletId.PERA,
306
- WalletId.DEFLY,
307
- WalletId.LUTE,
308
- WalletId.EXODUS,
309
- // For WalletConnect, you'll need a project ID
310
- {
311
- id: WalletId.WALLETCONNECT,
312
- options: { projectId: 'your-project-id' },
313
- },
314
- ],
315
- defaultNetwork: NetworkId.TESTNET, // Or MAINNET for production
316
- })
274
+ ### Theme Options
317
275
 
318
- function App() {
319
- return (
320
- <WalletProvider manager={walletManager}>
321
- <WalletUIProvider>{/* Your app content */}</WalletUIProvider>
322
- </WalletProvider>
323
- )
324
- }
276
+ ```jsx
277
+ <WalletUIProvider theme="system"> {/* Default: follows OS preference */}
278
+ <WalletUIProvider theme="light"> {/* Always light */}
279
+ <WalletUIProvider theme="dark"> {/* Always dark */}
325
280
  ```
326
281
 
327
- The `WalletProvider` from `@txnlab/use-wallet-react` manages the wallet connections using the provided `WalletManager` configuration, while `WalletUIProvider` adds UI-specific features like NFD lookups and data prefetching.
282
+ ### How Theme Detection Works
283
+
284
+ The library checks these in order (first match wins):
328
285
 
329
- ### 2. Add the Wallet Button
286
+ 1. **`data-theme` attribute**: Set by the `theme` prop on `WalletUIProvider`
287
+ 2. **`.dark` class**: On any ancestor element (Tailwind convention)
288
+ 3. **`prefers-color-scheme`**: System/browser preference (when `theme="system"`)
330
289
 
331
- The simplest way to enable wallet connectivity is with the `WalletButton` component:
290
+ ### Accessing Theme State
332
291
 
333
292
  ```jsx
334
- import { WalletButton } from '@txnlab/use-wallet-ui-react'
293
+ import { useWalletUI } from '@txnlab/use-wallet-ui-react'
335
294
 
336
- function MyNav() {
337
- return (
338
- <nav>
339
- <WalletButton />
340
- </nav>
341
- )
295
+ function MyComponent() {
296
+ const { theme, resolvedTheme } = useWalletUI()
297
+ // theme: 'light' | 'dark' | 'system' (the prop value)
298
+ // resolvedTheme: 'light' | 'dark' (the actual theme in use)
342
299
  }
343
300
  ```
344
301
 
345
- The `WalletButton` is an all-in-one solution that:
346
-
347
- - Shows a connect button when disconnected
348
- - Opens the wallet selection dialog when clicked
349
- - Displays the connected wallet after connection
350
- - Shows NFD names and avatars when available
351
- - Provides access to account switching and disconnection
352
-
353
- ## Component API
354
-
355
- The library provides several components that can be used independently or together:
302
+ ## Components
356
303
 
357
304
  ### WalletUIProvider
358
305
 
359
- Required wrapper that enables NFD lookups, data prefetching, and theming:
306
+ Required wrapper that enables theming, NFD lookups, and data prefetching.
360
307
 
361
308
  ```jsx
362
309
  <WalletUIProvider
363
- // Optional configurations
364
- theme="system" // Theme setting: 'light' | 'dark' | 'system' (default: 'system')
365
- enablePrefetching={false} // Prefetch data for all accounts in a wallet (default: true)
366
- prefetchNfdView="brief" // Data view for NFD prefetching (default: 'thumbnail')
367
- queryClient={yourQueryClient} // Optional: integrate with existing Tanstack Query
310
+ theme="system" // 'light' | 'dark' | 'system'
311
+ enablePrefetching={true} // Prefetch data for all wallet accounts
312
+ prefetchNfdView="thumbnail" // NFD data view: 'tiny' | 'thumbnail' | 'brief' | 'full'
313
+ queryClient={queryClient} // Optional: your existing Tanstack Query client
368
314
  >
369
- {/* Your app content */}
315
+ {children}
370
316
  </WalletUIProvider>
371
317
  ```
372
318
 
373
319
  ### WalletButton
374
320
 
375
- All-in-one solution for wallet connectivity - combines the connect and connected states:
321
+ All-in-one wallet connection component.
376
322
 
377
323
  ```jsx
378
- <WalletButton />
324
+ <WalletButton
325
+ size="md" // 'sm' | 'md' | 'lg'
326
+ className="..." // Additional CSS classes
327
+ style={{...}} // Inline styles (supports CSS variable overrides)
328
+ />
379
329
  ```
380
330
 
381
- ### Connection Components
331
+ ### ConnectWalletMenu
382
332
 
383
- For more customization, use these component pairs:
384
-
385
- #### Connect State (when disconnected)
333
+ Dropdown menu for wallet selection (disconnected state).
386
334
 
387
335
  ```jsx
388
- import { ConnectWalletButton, ConnectWalletMenu } from '@txnlab/use-wallet-ui-react'
389
-
390
- // Just the menu with default button:
336
+ // With default button
391
337
  <ConnectWalletMenu />
392
338
 
393
- // Customized button:
339
+ // With customized button
394
340
  <ConnectWalletMenu>
395
- <ConnectWalletButton className="bg-blue-500">
396
- Connect Wallet
397
- </ConnectWalletButton>
341
+ <ConnectWalletButton size="lg">Connect</ConnectWalletButton>
398
342
  </ConnectWalletMenu>
399
343
 
400
- // Fully custom trigger:
344
+ // With custom trigger
401
345
  <ConnectWalletMenu>
402
- <button className="my-custom-button">Connect</button>
346
+ <button>My Custom Button</button>
403
347
  </ConnectWalletMenu>
404
348
  ```
405
349
 
406
- #### Connected State (when wallet is connected)
350
+ ### ConnectWalletButton
351
+
352
+ Styled button for the connect state.
407
353
 
408
354
  ```jsx
409
- import { ConnectedWalletButton, ConnectedWalletMenu } from '@txnlab/use-wallet-ui-react'
355
+ <ConnectWalletButton
356
+ size="md" // 'sm' | 'md' | 'lg'
357
+ className="..." // Additional classes
358
+ style={{...}} // Inline styles
359
+ >
360
+ Connect Wallet {/* Optional: custom text */}
361
+ </ConnectWalletButton>
362
+ ```
410
363
 
411
- // Just the menu with default button:
364
+ ### ConnectedWalletMenu
365
+
366
+ Dropdown menu for account management (connected state).
367
+
368
+ ```jsx
369
+ // With default button
412
370
  <ConnectedWalletMenu />
413
371
 
414
- // Customized button:
372
+ // With customized button
415
373
  <ConnectedWalletMenu>
416
- <ConnectedWalletButton className="border-2 border-green-500" />
374
+ <ConnectedWalletButton size="sm" />
417
375
  </ConnectedWalletMenu>
418
376
 
419
- // Fully custom trigger:
377
+ // With custom trigger
420
378
  <ConnectedWalletMenu>
421
- <div className="flex items-center gap-2">
422
- <span>My Wallet</span>
423
- </div>
379
+ <div className="my-wallet-display">Connected</div>
424
380
  </ConnectedWalletMenu>
425
381
  ```
426
382
 
383
+ ### ConnectedWalletButton
384
+
385
+ Styled button showing wallet address/NFD and avatar.
386
+
387
+ ```jsx
388
+ <ConnectedWalletButton
389
+ size="md" // 'sm' | 'md' | 'lg'
390
+ className="..." // Additional classes
391
+ style={{...}} // Inline styles
392
+ />
393
+ ```
394
+
427
395
  ### NfdAvatar
428
396
 
429
- Renders NFD avatars with automatic IPFS gateway handling:
397
+ Renders NFD avatar images with IPFS gateway handling.
430
398
 
431
399
  ```jsx
432
400
  import { useNfd, NfdAvatar } from '@txnlab/use-wallet-ui-react'
@@ -438,169 +406,95 @@ function Profile() {
438
406
  <NfdAvatar
439
407
  nfd={nfdQuery.data}
440
408
  size={48}
441
- className="rounded-full border-2"
442
- alt="User profile"
409
+ className="rounded-full"
410
+ alt="Profile"
443
411
  />
444
412
  )
445
413
  }
446
414
  ```
447
415
 
448
- ## NFD Integration
416
+ ### WalletList
417
+
418
+ Renders a list of available wallets (used internally by ConnectWalletMenu).
419
+
420
+ ```jsx
421
+ <WalletList onWalletSelected={() => closeMenu()} />
422
+ ```
423
+
424
+ ## Hooks
449
425
 
450
- This library includes built-in support for [NFD (Non-Fungible Domains)](https://app.nf.domains/) - Algorand's naming service that provides human-readable identities for wallet addresses.
426
+ ### useNfd
451
427
 
452
- ### The useNfd Hook
428
+ Fetch NFD data for the active address.
453
429
 
454
430
  ```jsx
455
431
  import { useNfd } from '@txnlab/use-wallet-ui-react'
456
432
 
457
433
  function Profile() {
458
- // Gets NFD data for the currently connected address
459
- const nfdQuery = useNfd()
434
+ const nfdQuery = useNfd({
435
+ enabled: true, // Enable/disable the query
436
+ view: 'thumbnail' // 'tiny' | 'thumbnail' | 'brief' | 'full'
437
+ })
460
438
 
461
439
  if (nfdQuery.isLoading) return <div>Loading...</div>
462
440
 
463
- // Access NFD properties
464
- const name = nfdQuery.data?.name
465
- const userProperties = nfdQuery.data?.properties?.userDefined
466
-
467
- return (
468
- <div>
469
- <h2>{name || 'No NFD found'}</h2>
470
- <p>{userProperties?.bio || 'No bio'}</p>
471
- </div>
472
- )
441
+ return <div>{nfdQuery.data?.name || 'No NFD'}</div>
473
442
  }
474
443
  ```
475
444
 
476
- ### NFD Features
477
-
478
- - Automatic lookup for the active wallet address
479
- - Support for different data views: 'tiny', 'thumbnail', 'brief', 'full'
480
- - Efficient caching via Tanstack Query
481
- - Works with both MainNet and TestNet
482
-
483
- ```jsx
484
- // Customizing the NFD lookup
485
- const nfdQuery = useNfd({
486
- enabled: true, // Whether to enable the lookup
487
- view: 'brief', // Data view to request (default: 'thumbnail')
488
- })
489
- ```
490
-
491
- ## Account Information
445
+ ### useAccountInfo
492
446
 
493
- Get account data like ALGO balance and asset holdings using the `useAccountInfo` hook:
447
+ Fetch account information (balance, assets) for the active address.
494
448
 
495
449
  ```jsx
496
450
  import { useAccountInfo } from '@txnlab/use-wallet-ui-react'
497
451
 
498
452
  function Balance() {
499
- // Gets account data for the connected address
500
453
  const accountQuery = useAccountInfo()
501
454
 
502
455
  if (accountQuery.isLoading) return <div>Loading...</div>
503
- if (!accountQuery.data) return <div>No account data</div>
456
+ if (!accountQuery.data) return null
504
457
 
505
- // Convert microAlgos to Algos (1 ALGO = 1,000,000 microAlgos)
506
458
  const algoBalance = Number(accountQuery.data.amount) / 1_000_000
507
459
 
508
- // Available balance (total minus minimum required)
509
- const minBalance = Number(accountQuery.data.minBalance) / 1_000_000
510
- const availableBalance = Math.max(0, algoBalance - minBalance)
511
-
512
- return (
513
- <div>
514
- <div>Total: {algoBalance.toFixed(2)} ALGO</div>
515
- <div>Available: {availableBalance.toFixed(2)} ALGO</div>
516
- </div>
517
- )
460
+ return <div>{algoBalance.toFixed(2)} ALGO</div>
518
461
  }
519
462
  ```
520
463
 
521
- ## Advanced Customization
522
-
523
- ### Styling Without Tailwind
524
-
525
- When not using Tailwind, you have two options for customizing components:
526
-
527
- #### 1. Using the `style` prop
528
-
529
- ```jsx
530
- <ConnectWalletButton
531
- style={{
532
- backgroundColor: '#3366FF',
533
- color: 'white',
534
- fontWeight: 'bold',
535
- }}
536
- >
537
- Connect
538
- </ConnectWalletButton>
539
- ```
540
-
541
- #### 2. Using CSS selectors
464
+ ### useWalletUI
542
465
 
543
- First, add a custom class to the button:
466
+ Access the WalletUI context.
544
467
 
545
468
  ```jsx
546
- <ConnectWalletButton className="connect-button">Connect</ConnectWalletButton>
547
- ```
548
-
549
- Then target it in your CSS:
550
-
551
- ```css
552
- /* In your CSS */
553
- [data-wallet-ui] .connect-button {
554
- font-family: 'Your Custom Font', sans-serif;
555
- background-color: #3366ff;
556
- color: white;
557
- padding: 8px 16px;
558
- border-radius: 4px;
559
- transition: background-color 0.2s;
560
- }
469
+ import { useWalletUI } from '@txnlab/use-wallet-ui-react'
561
470
 
562
- [data-wallet-ui] .connect-button:hover {
563
- background-color: #2952cc;
471
+ function MyComponent() {
472
+ const { theme, resolvedTheme, queryClient } = useWalletUI()
564
473
  }
565
474
  ```
566
475
 
567
- ### Building Custom Wallet UI
476
+ ### useResolvedTheme
568
477
 
569
- For complete control, use the menu components with your own UI elements:
478
+ Get the resolved theme value (handles 'system' preference detection).
570
479
 
571
480
  ```jsx
572
- import { useWallet } from '@txnlab/use-wallet-react'
573
- import {
574
- ConnectWalletMenu,
575
- ConnectedWalletMenu,
576
- } from '@txnlab/use-wallet-ui-react'
481
+ import { useResolvedTheme } from '@txnlab/use-wallet-ui-react'
577
482
 
578
- function CustomWalletButton() {
579
- const { activeAddress } = useWallet()
580
-
581
- return activeAddress ? (
582
- <ConnectedWalletMenu>
583
- <YourCustomConnectedButton />
584
- </ConnectedWalletMenu>
585
- ) : (
586
- <ConnectWalletMenu>
587
- <YourCustomConnectButton />
588
- </ConnectWalletMenu>
589
- )
483
+ function MyComponent() {
484
+ const resolvedTheme = useResolvedTheme('system') // Returns 'light' or 'dark'
590
485
  }
591
486
  ```
592
487
 
593
- ## Integration with Tanstack Query
488
+ ## Tanstack Query Integration
594
489
 
595
- This library uses [Tanstack Query](https://tanstack.com/query/latest) internally for data fetching. If your application already uses Tanstack Query, you can integrate the two to avoid duplicate caches:
490
+ The library uses [Tanstack Query](https://tanstack.com/query) internally. If your app already uses it, share the QueryClient to avoid duplicate caches:
596
491
 
597
492
  ```jsx
598
493
  import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
599
- import { WalletManager, WalletProvider } from '@txnlab/use-wallet-react'
494
+ import { WalletProvider } from '@txnlab/use-wallet-react'
600
495
  import { WalletUIProvider } from '@txnlab/use-wallet-ui-react'
601
496
 
602
497
  const queryClient = new QueryClient()
603
- const walletManager = new WalletManager({...})
604
498
 
605
499
  function App() {
606
500
  return (
@@ -615,30 +509,47 @@ function App() {
615
509
  }
616
510
  ```
617
511
 
618
- By sharing the QueryClient, both your application and the wallet UI components will use the same query cache.
512
+ ## Migration from v0.x
513
+
514
+ v1.0 introduces a redesigned CSS architecture. Here's what changed:
515
+
516
+ ### Breaking Changes
517
+
518
+ 1. **CSS Variable Prefix**: Variables now use `--wui-` prefix (previously undocumented)
519
+ 2. **Theme Variables Location**: Defined on `[data-wallet-theme]` element (for CSS variable inheritance)
520
+ 3. **Button Data Attribute**: Buttons now have `data-wallet-button` attribute for targeting
521
+
522
+ ### New Features
523
+
524
+ 1. **Size Variants**: `WalletButton`, `ConnectWalletButton`, and `ConnectedWalletButton` now accept a `size` prop (`'sm' | 'md' | 'lg'`)
525
+
526
+ 2. **className/style Props**: All button components accept `className` and `style` props for customization
619
527
 
620
- ## How It Works
528
+ 3. **CSS Variable Overrides**: Override any theme color via CSS:
529
+ ```css
530
+ [data-wallet-theme] {
531
+ --wui-color-primary: #your-color;
532
+ }
533
+ ```
621
534
 
622
- The library follows a simple workflow:
535
+ 4. **Custom Triggers**: Pass any element as a child to `ConnectWalletMenu` or `ConnectedWalletMenu` for full control:
536
+ ```jsx
537
+ <ConnectWalletMenu>
538
+ <MyCustomButton />
539
+ </ConnectWalletMenu>
540
+ ```
623
541
 
624
- 1. **Disconnected State**: `WalletButton` shows a connect button
625
- 2. **Connection Dialog**: Clicking opens a dropdown with available Algorand wallets
626
- 3. **Connected State**: After connecting, it displays the wallet address/NFD and balance
627
- 4. **Account Management**: The dropdown provides options to switch accounts or disconnect
542
+ 5. **Theme Detection**: Now respects `.dark` class on ancestors (Tailwind convention) in addition to `data-theme` attribute and `prefers-color-scheme` media query
628
543
 
629
- Behind the scenes, `WalletUIProvider` handles:
544
+ ### Migration Steps
630
545
 
631
- - Prefetching NFD data for all accounts in the wallet
632
- - Converting IPFS URLs to HTTPS for avatars
633
- - Caching API responses for better performance
634
- - Handling network-specific behavior (MainNet/TestNet)
546
+ 1. Update any custom CSS targeting the library:
547
+ - Use `[data-wallet-theme]` for CSS variable overrides
548
+ - Use `[data-wallet-button]` for targeting button elements
635
549
 
636
- ## Related Resources
550
+ 2. If you were using workarounds for customization, you can likely simplify using the new APIs
637
551
 
638
- - [use-wallet Documentation](https://github.com/TxnLab/use-wallet)
639
- - [use-wallet-react NPM Package](https://www.npmjs.com/package/@txnlab/use-wallet-react)
640
- - [NFD (Non-Fungible Domains)](https://nf.domains/)
641
- - [Algorand Developer Portal](https://developer.algorand.org/)
552
+ 3. Test dark mode behavior - it should work more reliably with Tailwind's `.dark` class
642
553
 
643
554
  ## License
644
555