@maximedogawa/chia-wallet-connect-react 0.0.1

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.
Files changed (146) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +622 -0
  3. package/dist/api.d.ts +62 -0
  4. package/dist/api.d.ts.map +1 -0
  5. package/dist/api.js +170 -0
  6. package/dist/api.js.map +1 -0
  7. package/dist/components/shared/CopyButton.d.ts +11 -0
  8. package/dist/components/shared/CopyButton.d.ts.map +1 -0
  9. package/dist/components/shared/CopyButton.js +122 -0
  10. package/dist/components/shared/CopyButton.js.map +1 -0
  11. package/dist/components/shared/Modal.d.ts +11 -0
  12. package/dist/components/shared/Modal.d.ts.map +1 -0
  13. package/dist/components/shared/Modal.js +18 -0
  14. package/dist/components/shared/Modal.js.map +1 -0
  15. package/dist/components/shared/SafeImage.d.ts +15 -0
  16. package/dist/components/shared/SafeImage.d.ts.map +1 -0
  17. package/dist/components/shared/SafeImage.js +15 -0
  18. package/dist/components/shared/SafeImage.js.map +1 -0
  19. package/dist/components/shared/icons/ChevronUpDownIcon.d.ts +6 -0
  20. package/dist/components/shared/icons/ChevronUpDownIcon.d.ts.map +1 -0
  21. package/dist/components/shared/icons/ChevronUpDownIcon.js +8 -0
  22. package/dist/components/shared/icons/ChevronUpDownIcon.js.map +1 -0
  23. package/dist/components/shared/icons/CrossIcon.d.ts +8 -0
  24. package/dist/components/shared/icons/CrossIcon.d.ts.map +1 -0
  25. package/dist/components/shared/icons/CrossIcon.js +8 -0
  26. package/dist/components/shared/icons/CrossIcon.js.map +1 -0
  27. package/dist/components/shared/icons/PlusIcon.d.ts +6 -0
  28. package/dist/components/shared/icons/PlusIcon.d.ts.map +1 -0
  29. package/dist/components/shared/icons/PlusIcon.js +8 -0
  30. package/dist/components/shared/icons/PlusIcon.js.map +1 -0
  31. package/dist/components/shared/icons/WalletConnectIcon.d.ts +7 -0
  32. package/dist/components/shared/icons/WalletConnectIcon.d.ts.map +1 -0
  33. package/dist/components/shared/icons/WalletConnectIcon.js +17 -0
  34. package/dist/components/shared/icons/WalletConnectIcon.js.map +1 -0
  35. package/dist/components/shared/navbar/Navbar.d.ts +7 -0
  36. package/dist/components/shared/navbar/Navbar.d.ts.map +1 -0
  37. package/dist/components/shared/navbar/Navbar.js +13 -0
  38. package/dist/components/shared/navbar/Navbar.js.map +1 -0
  39. package/dist/components/shared/navbar/walletIntegration/AddAssetButton.d.ts +10 -0
  40. package/dist/components/shared/navbar/walletIntegration/AddAssetButton.d.ts.map +1 -0
  41. package/dist/components/shared/navbar/walletIntegration/AddAssetButton.js +36 -0
  42. package/dist/components/shared/navbar/walletIntegration/AddAssetButton.js.map +1 -0
  43. package/dist/components/shared/navbar/walletIntegration/ConnectButton.d.ts +25 -0
  44. package/dist/components/shared/navbar/walletIntegration/ConnectButton.d.ts.map +1 -0
  45. package/dist/components/shared/navbar/walletIntegration/ConnectButton.js +79 -0
  46. package/dist/components/shared/navbar/walletIntegration/ConnectButton.js.map +1 -0
  47. package/dist/components/shared/navbar/walletIntegration/ConnectWalletModal.d.ts +10 -0
  48. package/dist/components/shared/navbar/walletIntegration/ConnectWalletModal.d.ts.map +1 -0
  49. package/dist/components/shared/navbar/walletIntegration/ConnectWalletModal.js +129 -0
  50. package/dist/components/shared/navbar/walletIntegration/ConnectWalletModal.js.map +1 -0
  51. package/dist/components/shared/navbar/walletIntegration/CustomWalletConnectModal.d.ts +11 -0
  52. package/dist/components/shared/navbar/walletIntegration/CustomWalletConnectModal.d.ts.map +1 -0
  53. package/dist/components/shared/navbar/walletIntegration/CustomWalletConnectModal.js +38 -0
  54. package/dist/components/shared/navbar/walletIntegration/CustomWalletConnectModal.js.map +1 -0
  55. package/dist/components/shared/navbar/walletIntegration/FingerprintListbox.d.ts +8 -0
  56. package/dist/components/shared/navbar/walletIntegration/FingerprintListbox.d.ts.map +1 -0
  57. package/dist/components/shared/navbar/walletIntegration/FingerprintListbox.js +25 -0
  58. package/dist/components/shared/navbar/walletIntegration/FingerprintListbox.js.map +1 -0
  59. package/dist/components/shared/navbar/walletIntegration/WalletConnectQR.d.ts +8 -0
  60. package/dist/components/shared/navbar/walletIntegration/WalletConnectQR.d.ts.map +1 -0
  61. package/dist/components/shared/navbar/walletIntegration/WalletConnectQR.js +35 -0
  62. package/dist/components/shared/navbar/walletIntegration/WalletConnectQR.js.map +1 -0
  63. package/dist/components/shared/navbar/walletIntegration/WalletConnectSession.d.ts +8 -0
  64. package/dist/components/shared/navbar/walletIntegration/WalletConnectSession.d.ts.map +1 -0
  65. package/dist/components/shared/navbar/walletIntegration/WalletConnectSession.js +64 -0
  66. package/dist/components/shared/navbar/walletIntegration/WalletConnectSession.js.map +1 -0
  67. package/dist/constants/sage-methods.d.ts +41 -0
  68. package/dist/constants/sage-methods.d.ts.map +1 -0
  69. package/dist/constants/sage-methods.js +71 -0
  70. package/dist/constants/sage-methods.js.map +1 -0
  71. package/dist/constants/wallet-connect.d.ts +49 -0
  72. package/dist/constants/wallet-connect.d.ts.map +1 -0
  73. package/dist/constants/wallet-connect.js +127 -0
  74. package/dist/constants/wallet-connect.js.map +1 -0
  75. package/dist/hooks/useWalletConnectRestore.d.ts +35 -0
  76. package/dist/hooks/useWalletConnectRestore.d.ts.map +1 -0
  77. package/dist/hooks/useWalletConnectRestore.js +122 -0
  78. package/dist/hooks/useWalletConnectRestore.js.map +1 -0
  79. package/dist/hooks/useWalletConnectionState.d.ts +27 -0
  80. package/dist/hooks/useWalletConnectionState.d.ts.map +1 -0
  81. package/dist/hooks/useWalletConnectionState.js +49 -0
  82. package/dist/hooks/useWalletConnectionState.js.map +1 -0
  83. package/dist/hooks.d.ts +7 -0
  84. package/dist/hooks.d.ts.map +1 -0
  85. package/dist/hooks.js +7 -0
  86. package/dist/hooks.js.map +1 -0
  87. package/dist/index.d.ts +25 -0
  88. package/dist/index.d.ts.map +1 -0
  89. package/dist/index.js +65 -0
  90. package/dist/index.js.map +1 -0
  91. package/dist/package.json +16 -0
  92. package/dist/state/completeWithWalletSlice.d.ts +18 -0
  93. package/dist/state/completeWithWalletSlice.d.ts.map +1 -0
  94. package/dist/state/completeWithWalletSlice.js +31 -0
  95. package/dist/state/completeWithWalletSlice.js.map +1 -0
  96. package/dist/state/globalOnLoadDataSlice.d.ts +17 -0
  97. package/dist/state/globalOnLoadDataSlice.d.ts.map +1 -0
  98. package/dist/state/globalOnLoadDataSlice.js +44 -0
  99. package/dist/state/globalOnLoadDataSlice.js.map +1 -0
  100. package/dist/state/settingsModalSlice.d.ts +7 -0
  101. package/dist/state/settingsModalSlice.d.ts.map +1 -0
  102. package/dist/state/settingsModalSlice.js +21 -0
  103. package/dist/state/settingsModalSlice.js.map +1 -0
  104. package/dist/state/store.d.ts +21 -0
  105. package/dist/state/store.d.ts.map +1 -0
  106. package/dist/state/store.js +110 -0
  107. package/dist/state/store.js.map +1 -0
  108. package/dist/state/walletConnectSlice.d.ts +16 -0
  109. package/dist/state/walletConnectSlice.d.ts.map +1 -0
  110. package/dist/state/walletConnectSlice.js +71 -0
  111. package/dist/state/walletConnectSlice.js.map +1 -0
  112. package/dist/state/walletSlice.d.ts +12 -0
  113. package/dist/state/walletSlice.d.ts.map +1 -0
  114. package/dist/state/walletSlice.js +44 -0
  115. package/dist/state/walletSlice.js.map +1 -0
  116. package/dist/styles/globals.css +54 -0
  117. package/dist/utils/analyticsUtils.d.ts +5 -0
  118. package/dist/utils/analyticsUtils.d.ts.map +1 -0
  119. package/dist/utils/analyticsUtils.js +32 -0
  120. package/dist/utils/analyticsUtils.js.map +1 -0
  121. package/dist/utils/deviceDetection.d.ts +14 -0
  122. package/dist/utils/deviceDetection.d.ts.map +1 -0
  123. package/dist/utils/deviceDetection.js +81 -0
  124. package/dist/utils/deviceDetection.js.map +1 -0
  125. package/dist/utils/logger.d.ts +13 -0
  126. package/dist/utils/logger.d.ts.map +1 -0
  127. package/dist/utils/logger.js +68 -0
  128. package/dist/utils/logger.js.map +1 -0
  129. package/dist/utils/walletIntegration/restoreConnectionState.d.ts +7 -0
  130. package/dist/utils/walletIntegration/restoreConnectionState.d.ts.map +1 -0
  131. package/dist/utils/walletIntegration/restoreConnectionState.js +145 -0
  132. package/dist/utils/walletIntegration/restoreConnectionState.js.map +1 -0
  133. package/dist/utils/walletIntegration/walletIntegrationInterface.d.ts +35 -0
  134. package/dist/utils/walletIntegration/walletIntegrationInterface.d.ts.map +1 -0
  135. package/dist/utils/walletIntegration/walletIntegrationInterface.js +3 -0
  136. package/dist/utils/walletIntegration/walletIntegrationInterface.js.map +1 -0
  137. package/dist/utils/walletIntegration/walletManager.d.ts +18 -0
  138. package/dist/utils/walletIntegration/walletManager.d.ts.map +1 -0
  139. package/dist/utils/walletIntegration/walletManager.js +118 -0
  140. package/dist/utils/walletIntegration/walletManager.js.map +1 -0
  141. package/dist/utils/walletIntegration/wallets/walletConnect.d.ts +65 -0
  142. package/dist/utils/walletIntegration/wallets/walletConnect.d.ts.map +1 -0
  143. package/dist/utils/walletIntegration/wallets/walletConnect.js +891 -0
  144. package/dist/utils/walletIntegration/wallets/walletConnect.js.map +1 -0
  145. package/package.json +107 -0
  146. package/tailwind.config.js +27 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 MaximEdogawa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,622 @@
1
+ # Wallet Connect Plugin for Chia Network
2
+
3
+ A WalletConnect integration plugin for the Chia blockchain. This plugin provides a complete WalletConnect implementation that can be easily integrated into any Chia-based application.
4
+
5
+ ## Features
6
+
7
+ - **WalletConnect v2 Support**: Full integration with WalletConnect Sign Client
8
+ - **Session Management**: Connect, manage, and disconnect multiple wallet sessions
9
+ - **QR Code Pairing**: Display QR codes for easy wallet pairing
10
+ - **Manual URI Copy**: Copy pairing URIs manually for advanced users
11
+ - **Address Management**: Get and display wallet addresses
12
+ - **Asset Management**: Add CAT tokens to connected wallets
13
+ - **Offer Generation**: Generate offers for Chia transactions
14
+ - **Dark Mode Support**: Full dark/light mode support - all components automatically adapt to theme changes
15
+
16
+ ## Getting Started
17
+
18
+ ### Prerequisites
19
+
20
+ - Node.js 18+ or Bun 1.0+
21
+ - npm, yarn, pnpm, or bun
22
+
23
+ ### Installation
24
+
25
+ ```bash
26
+ npm install
27
+ # or
28
+ yarn install
29
+ # or
30
+ pnpm install
31
+ # or
32
+ bun install
33
+ ```
34
+
35
+ ### Build Package
36
+
37
+ Build the package for distribution (required before using in other projects):
38
+
39
+ ```bash
40
+ npm run build
41
+ # or
42
+ yarn build
43
+ # or
44
+ pnpm build
45
+ # or
46
+ bun run build
47
+ ```
48
+
49
+ This will:
50
+ - Compile TypeScript to JavaScript
51
+ - Generate type definitions (.d.ts files)
52
+ - Copy styles to the dist directory
53
+ - Prepare the package for publishing or local use
54
+
55
+ ### Environment Variables
56
+
57
+ Create a `.env.local` file in the root directory with the following variables:
58
+
59
+ ```env
60
+ NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID=your_project_id
61
+ NEXT_PUBLIC_WALLET_CONNECT_RELAY_URL=wss://relay.walletconnect.com
62
+ NEXT_PUBLIC_CHIA_NETWORK=testnet
63
+
64
+ # WalletConnect Metadata (optional)
65
+ NEXT_PUBLIC_WALLET_CONNECT_METADATA_NAME=Wallet Connect
66
+ NEXT_PUBLIC_WALLET_CONNECT_METADATA_DESCRIPTION=Wallet Connect for Chia blockchain
67
+ NEXT_PUBLIC_WALLET_CONNECT_METADATA_URL=https://example.com
68
+ NEXT_PUBLIC_WALLET_CONNECT_METADATA_ICONS=https://example.com/logo.jpg
69
+ ```
70
+
71
+ ### Development
72
+
73
+ Run the development server:
74
+
75
+ ```bash
76
+ npm run dev
77
+ # or
78
+ yarn dev
79
+ # or
80
+ pnpm dev
81
+ # or
82
+ bun run dev
83
+ ```
84
+
85
+ Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
86
+
87
+ ### Build Demo
88
+
89
+ Build the demo application for production:
90
+
91
+ ```bash
92
+ cd demo
93
+ npm run build
94
+ # or
95
+ yarn build
96
+ # or
97
+ pnpm build
98
+ # or
99
+ bun run build
100
+ ```
101
+
102
+ ### Start Production Server
103
+
104
+ ```bash
105
+ npm start
106
+ # or
107
+ yarn start
108
+ # or
109
+ pnpm start
110
+ # or
111
+ bun start
112
+ ```
113
+
114
+ ## Accessing Wallet Connection State
115
+
116
+ The package provides several ways to access and monitor the WalletConnect connection state in your application.
117
+
118
+ ### Using the `useWalletConnectionState` Hook (Recommended)
119
+
120
+ The easiest way to access connection state in your React components:
121
+
122
+ ```tsx
123
+ import { useWalletConnectionState } from '@maximedogawa/chia-wallet-connect-react';
124
+
125
+ function MyComponent() {
126
+ const {
127
+ isConnected,
128
+ connectedWallet,
129
+ address,
130
+ isWalletConnect,
131
+ walletConnectSession,
132
+ walletImage,
133
+ walletName,
134
+ cnsName,
135
+ } = useWalletConnectionState();
136
+
137
+ if (!isConnected) {
138
+ return <div>No wallet connected</div>;
139
+ }
140
+
141
+ return (
142
+ <div>
143
+ <p>Connected to: {connectedWallet}</p>
144
+ <p>Address: {address}</p>
145
+ {isWalletConnect && walletConnectSession && (
146
+ <p>Wallet: {walletConnectSession.peer.metadata.name}</p>
147
+ )}
148
+ </div>
149
+ );
150
+ }
151
+ ```
152
+
153
+ **Hook Return Values:**
154
+ - `isConnected: boolean` - Whether any wallet is connected
155
+ - `connectedWallet: string | null` - The name of the connected wallet (e.g., "WalletConnect") or null
156
+ - `address: string | null` - The wallet address or null
157
+ - `isWalletConnect: boolean` - Whether WalletConnect is the connected wallet
158
+ - `walletConnectSession: SessionTypes.Struct | null` - The active WalletConnect session or null
159
+ - `walletImage: string | null` - The wallet image/icon URL or null
160
+ - `walletName: string | null` - The wallet name or null
161
+ - `cnsName: string | null` - The CNS name (if available) or null
162
+
163
+ ### Using Redux Store Directly
164
+
165
+ You can also access the state directly from the Redux store:
166
+
167
+ ```tsx
168
+ import { store, useAppSelector } from '@maximedogawa/chia-wallet-connect-react';
169
+ import type { RootState } from '@maximedogawa/chia-wallet-connect-react';
170
+
171
+ function MyComponent() {
172
+ // Using useAppSelector hook
173
+ const connectedWallet = useAppSelector(
174
+ (state: RootState) => state.wallet.connectedWallet
175
+ );
176
+ const address = useAppSelector((state: RootState) => state.wallet.address);
177
+ const walletConnectSession = useAppSelector(
178
+ (state: RootState) => state.walletConnect.selectedSession
179
+ );
180
+ const walletConnectSessions = useAppSelector(
181
+ (state: RootState) => state.walletConnect.sessions
182
+ );
183
+
184
+ // Or access store directly (outside React components)
185
+ const state = store.getState();
186
+ const isConnected =
187
+ state.wallet.connectedWallet === "WalletConnect"
188
+ ? Boolean(state.walletConnect.selectedSession)
189
+ : Boolean(state.wallet.connectedWallet);
190
+
191
+ return (
192
+ <div>
193
+ <p>Wallet: {connectedWallet}</p>
194
+ <p>Address: {address}</p>
195
+ </div>
196
+ );
197
+ }
198
+ ```
199
+
200
+ **Redux State Structure:**
201
+
202
+ #### `state.wallet`
203
+ - `connectedWallet: string | null` - Connected wallet name
204
+ - `address: string | null` - Wallet address
205
+ - `image: string | null` - Wallet image URL
206
+ - `name: string | null` - Wallet name
207
+ - `CNSName: string | null` - CNS name
208
+
209
+ #### `state.walletConnect`
210
+ - `sessions: SessionTypes.Struct[]` - All WalletConnect sessions
211
+ - `selectedSession: SessionTypes.Struct | null` - Currently selected/active session
212
+ - `selectedFingerprint: { [topic: string]: number }` - Fingerprint for each session
213
+ - `pairingUri: string | null` - Current pairing URI (if pairing)
214
+
215
+ ### State Persistence
216
+
217
+ The connection state is automatically persisted to IndexedDB using `redux-persist`. This means:
218
+
219
+ - ✅ Connection state survives page refreshes
220
+ - ✅ State is automatically restored on app load
221
+ - ✅ No additional setup required
222
+
223
+ The following state is persisted:
224
+ - `wallet` slice (connectedWallet, address, image, name)
225
+ - `walletConnect` slice (sessions, selectedSession, selectedFingerprint)
226
+
227
+ ### Complete Example
228
+
229
+ ```tsx
230
+ import { useWalletConnectionState, ConnectButton } from '@maximedogawa/chia-wallet-connect-react';
231
+
232
+ function WalletStatus() {
233
+ const {
234
+ isConnected,
235
+ connectedWallet,
236
+ address,
237
+ isWalletConnect,
238
+ walletConnectSession,
239
+ walletImage,
240
+ } = useWalletConnectionState();
241
+
242
+ return (
243
+ <div>
244
+ <ConnectButton />
245
+
246
+ {isConnected && (
247
+ <div>
248
+ <h3>Wallet Status</h3>
249
+ <p>Connected: {connectedWallet}</p>
250
+ <p>Address: {address}</p>
251
+
252
+ {isWalletConnect && walletConnectSession && (
253
+ <div>
254
+ <p>Wallet: {walletConnectSession.peer.metadata.name}</p>
255
+ {walletImage && (
256
+ <img src={walletImage} alt="Wallet icon" />
257
+ )}
258
+ </div>
259
+ )}
260
+ </div>
261
+ )}
262
+ </div>
263
+ );
264
+ }
265
+ ```
266
+
267
+ ### Notes
268
+
269
+ - The `useWalletConnectionState` hook automatically updates when the connection state changes
270
+ - For WalletConnect, both `connectedWallet === "WalletConnect"` AND `selectedSession` must be truthy for the connection to be considered active
271
+ - The connection state is restored automatically after page refresh - no manual restoration needed
272
+ - Address may be `null` initially if it hasn't been fetched yet, but the connection is still valid
273
+
274
+ ## Usage as a Package/Plugin
275
+
276
+ ### Installation
277
+
278
+ Install the package in your project:
279
+
280
+ ```bash
281
+ npm install @maximedogawa/chia-wallet-connect-react
282
+ # or
283
+ yarn add @maximedogawa/chia-wallet-connect-react
284
+ # or
285
+ pnpm add @maximedogawa/chia-wallet-connect-react
286
+ # or
287
+ bun add @maximedogawa/chia-wallet-connect-react
288
+ ```
289
+
290
+ ### Setup
291
+
292
+ #### 1. Import Styles
293
+
294
+ **Important**: You must import the package styles in your app's main entry point:
295
+
296
+ ```tsx
297
+ // In your _app.tsx, layout.tsx, or main.tsx
298
+ import '@maximedogawa/chia-wallet-connect-react/styles';
299
+ ```
300
+
301
+ #### 2. Configure Tailwind CSS (if using Tailwind)
302
+
303
+ **Option A: Merge the package's Tailwind config (Recommended)**
304
+
305
+ Import and merge the package's Tailwind configuration to ensure all styles and theme extensions are included:
306
+
307
+ ```js
308
+ // tailwind.config.js
309
+ const packageConfig = require('@maximedogawa/chia-wallet-connect-react/tailwind.config');
310
+
311
+ module.exports = {
312
+ ...packageConfig,
313
+ content: [
314
+ './src/**/*.{js,ts,jsx,tsx}',
315
+ './pages/**/*.{js,ts,jsx,tsx}',
316
+ './app/**/*.{js,ts,jsx,tsx}',
317
+ './components/**/*.{js,ts,jsx,tsx}',
318
+ './node_modules/@maximedogawa/chia-wallet-connect-react/dist/**/*.{js,ts,jsx,tsx}', // Important: Add this
319
+ ],
320
+ // You can extend the theme further if needed
321
+ theme: {
322
+ ...packageConfig.theme,
323
+ extend: {
324
+ ...packageConfig.theme.extend,
325
+ // Your custom extensions
326
+ },
327
+ },
328
+ }
329
+ ```
330
+
331
+ **Option B: Manual configuration**
332
+
333
+ If you prefer not to merge the config, manually add the package to your Tailwind content paths and include the theme extensions:
334
+
335
+ ```js
336
+ // tailwind.config.js
337
+ module.exports = {
338
+ darkMode: 'class', // Required for dark mode support
339
+ content: [
340
+ './src/**/*.{js,ts,jsx,tsx}',
341
+ './pages/**/*.{js,ts,jsx,tsx}',
342
+ './app/**/*.{js,ts,jsx,tsx}',
343
+ './components/**/*.{js,ts,jsx,tsx}',
344
+ './node_modules/@maximedogawa/chia-wallet-connect-react/dist/**/*.{js,ts,jsx,tsx}', // Important: Add this
345
+ ],
346
+ theme: {
347
+ extend: {
348
+ colors: {
349
+ brandDark: '#526e78',
350
+ brandLight: '#EFF4F7',
351
+ },
352
+ keyframes: {
353
+ fadeIn: {
354
+ '0%': { opacity: 0 },
355
+ '100%': { opacity: 1 }
356
+ }
357
+ },
358
+ animation: {
359
+ fadeIn: 'fadeIn .3s ease-in-out',
360
+ },
361
+ },
362
+ },
363
+ plugins: [],
364
+ }
365
+ ```
366
+
367
+ **Important Notes:**
368
+ - The `content` array **must** include the package's dist files so Tailwind can scan for class names
369
+ - The `darkMode: 'class'` setting is required for proper dark mode support
370
+ - Make sure your PostCSS config includes Tailwind and Autoprefixer
371
+
372
+ #### 3. Dark Mode Support
373
+
374
+ The package includes full dark mode support out of the box. Components automatically adapt to dark mode when the `dark` class is present on the `<html>` or `<body>` element.
375
+
376
+ **Enable Dark Mode:**
377
+
378
+ ```tsx
379
+ // Toggle dark mode by adding/removing the 'dark' class
380
+ // Option 1: Manual toggle
381
+ const toggleDarkMode = () => {
382
+ document.documentElement.classList.toggle('dark');
383
+ localStorage.setItem('theme', document.documentElement.classList.contains('dark') ? 'dark' : 'light');
384
+ };
385
+
386
+ // Option 2: React hook example
387
+ import { useEffect, useState } from 'react';
388
+
389
+ function useDarkMode() {
390
+ const [isDark, setIsDark] = useState(false);
391
+
392
+ useEffect(() => {
393
+ // Check localStorage or system preference
394
+ const stored = localStorage.getItem('theme');
395
+ const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
396
+ const shouldBeDark = stored === 'dark' || (!stored && prefersDark);
397
+
398
+ setIsDark(shouldBeDark);
399
+ if (shouldBeDark) {
400
+ document.documentElement.classList.add('dark');
401
+ } else {
402
+ document.documentElement.classList.remove('dark');
403
+ }
404
+ }, []);
405
+
406
+ const toggle = () => {
407
+ const newValue = !isDark;
408
+ setIsDark(newValue);
409
+ if (newValue) {
410
+ document.documentElement.classList.add('dark');
411
+ localStorage.setItem('theme', 'dark');
412
+ } else {
413
+ document.documentElement.classList.remove('dark');
414
+ localStorage.setItem('theme', 'light');
415
+ }
416
+ };
417
+
418
+ return [isDark, toggle] as const;
419
+ }
420
+ ```
421
+
422
+ **All components automatically support dark mode:**
423
+ - `ConnectButton` - Adapts colors for dark/light themes
424
+ - `ConnectWalletModal` - Full dark mode styling
425
+ - `Modal` - Dark background and text colors
426
+ - `WalletConnectQR` - Dark mode compatible QR display
427
+ - All other components - Fully theme-aware
428
+
429
+ #### 4. Setup Redux Provider
430
+
431
+ Wrap your app with the Redux Provider:
432
+
433
+ ```tsx
434
+ import { Provider } from 'react-redux';
435
+ import { PersistGate } from 'redux-persist/integration/react';
436
+ import { store, persistor } from '@maximedogawa/chia-wallet-connect-react';
437
+
438
+ function App() {
439
+ return (
440
+ <Provider store={store}>
441
+ <PersistGate loading={null} persistor={persistor}>
442
+ {/* Your app */}
443
+ </PersistGate>
444
+ </Provider>
445
+ );
446
+ }
447
+ ```
448
+
449
+ ### Basic Usage
450
+
451
+ #### Use the Connect Button
452
+
453
+ ```tsx
454
+ import { ConnectButton } from '@maximedogawa/chia-wallet-connect-react';
455
+
456
+ function MyComponent() {
457
+ return (
458
+ <div>
459
+ {/* Default usage */}
460
+ <ConnectButton />
461
+
462
+ {/* Custom text */}
463
+ <ConnectButton connectText="Connect Wallet" />
464
+
465
+ {/* Custom text and styling */}
466
+ <ConnectButton
467
+ connectText="My Custom Text"
468
+ className="custom-button-class"
469
+ />
470
+ </div>
471
+ );
472
+ }
473
+ ```
474
+
475
+ **ConnectButton Props:**
476
+ - `connectText?: string` - Text to display when wallet is not connected (default: "Manage Wallet")
477
+ - `className?: string` - Additional CSS classes to apply to the button
478
+
479
+ #### 3. Use WalletManager Programmatically
480
+
481
+ ```tsx
482
+ import { WalletManager, useAppSelector } from '@maximedogawa/chia-wallet-connect-react';
483
+
484
+ function MyComponent() {
485
+ const walletManager = new WalletManager();
486
+ const connectedWallet = useAppSelector(state => state.wallet.connectedWallet);
487
+
488
+ const handleConnect = async () => {
489
+ await walletManager.connect('WalletConnect');
490
+ };
491
+
492
+ return (
493
+ <button onClick={handleConnect}>
494
+ {connectedWallet ? 'Connected' : 'Connect Wallet'}
495
+ </button>
496
+ );
497
+ }
498
+ ```
499
+
500
+ #### 4. Access Wallet State
501
+
502
+ ```tsx
503
+ import { useAppSelector } from '@maximedogawa/chia-wallet-connect-react';
504
+ import type { RootState } from '@maximedogawa/chia-wallet-connect-react';
505
+
506
+ function WalletInfo() {
507
+ const address = useAppSelector((state: RootState) => state.wallet.address);
508
+ const connectedWallet = useAppSelector((state: RootState) => state.wallet.connectedWallet);
509
+
510
+ return (
511
+ <div>
512
+ <p>Wallet: {connectedWallet}</p>
513
+ <p>Address: {address}</p>
514
+ </div>
515
+ );
516
+ }
517
+ ```
518
+
519
+ ### Available Exports
520
+
521
+ #### Components
522
+ - `ConnectButton` - Button component for connecting wallets (accepts `connectText` and `className` props)
523
+ - `ConnectButtonProps` - TypeScript type for ConnectButton props
524
+ - `ConnectWalletModal` - Modal for wallet connection UI
525
+ - `WalletConnectQR` - QR code display component
526
+ - `WalletConnectSession` - Session management component
527
+ - `AddAssetButton` - Button to add assets to wallet
528
+ - `FingerprintListbox` - Fingerprint selector component
529
+
530
+ #### Core Utilities
531
+ - `WalletManager` - Main wallet management class
532
+ - `WalletConnect` - WalletConnect implementation class
533
+
534
+ #### Redux Store
535
+ - `store` - Redux store instance
536
+ - `persistor` - Redux persist instance
537
+ - `useAppDispatch` - Typed dispatch hook
538
+ - `useAppSelector` - Typed selector hook
539
+ - `RootState` - TypeScript type for root state
540
+ - `AppDispatch` - TypeScript type for dispatch
541
+
542
+ #### Redux Actions
543
+ - `setConnectedWallet` - Set connected wallet
544
+ - `setAddress` - Set wallet address
545
+ - `setCNSName` - Set CNS name
546
+ - `connectSession` - Connect WalletConnect session
547
+ - `setPairingUri` - Set pairing URI
548
+ - `selectSession` - Select active session
549
+ - `setSessions` - Set all sessions
550
+ - And more...
551
+
552
+ ### Environment Variables
553
+
554
+ Make sure to set these environment variables in your project:
555
+
556
+ ```env
557
+ NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID=your_project_id
558
+ NEXT_PUBLIC_WALLET_CONNECT_RELAY_URL=wss://relay.walletconnect.com
559
+ NEXT_PUBLIC_CHIA_NETWORK=testnet
560
+ ```
561
+
562
+ ### Styling
563
+
564
+ #### Import Styles
565
+
566
+ Import the package styles in your app's main entry point:
567
+
568
+ ```tsx
569
+ // In your _app.tsx, layout.tsx, or main.tsx
570
+ import '@maximedogawa/chia-wallet-connect-react/styles';
571
+ ```
572
+
573
+ Or if using CSS modules:
574
+
575
+ ```css
576
+ @import '@maximedogawa/chia-wallet-connect-react/styles';
577
+ ```
578
+
579
+ #### Troubleshooting Styling Issues
580
+
581
+ If styles are not appearing correctly:
582
+
583
+ 1. **Verify CSS import**: Make sure you've imported the styles in your main entry point
584
+ 2. **Check Tailwind content paths**: Ensure your `tailwind.config.js` includes the package's dist files:
585
+ ```js
586
+ content: [
587
+ // ... your paths
588
+ './node_modules/@maximedogawa/chia-wallet-connect-react/dist/**/*.{js,ts,jsx,tsx}',
589
+ ]
590
+ ```
591
+ 3. **Verify PostCSS config**: Ensure your `postcss.config.js` includes Tailwind:
592
+ ```js
593
+ module.exports = {
594
+ plugins: {
595
+ tailwindcss: {},
596
+ autoprefixer: {},
597
+ },
598
+ }
599
+ ```
600
+ 4. **Rebuild Tailwind**: After updating your config, restart your dev server and rebuild
601
+ 5. **Check dark mode**: If using dark mode, ensure `darkMode: 'class'` is set in your Tailwind config and the `dark` class is on your `<html>` element
602
+ 6. **Merge package config**: Use Option A in the setup section to automatically include all required theme extensions
603
+
604
+ #### Dark Mode Troubleshooting
605
+
606
+ If dark mode isn't working:
607
+
608
+ 1. **Verify `dark` class**: Check that `document.documentElement.classList.contains('dark')` returns `true` when dark mode should be active
609
+ 2. **Check Tailwind config**: Ensure `darkMode: 'class'` is set in your Tailwind config (included when merging package config)
610
+ 3. **Inspect components**: Use browser dev tools to verify `dark:` classes are being applied
611
+ 4. **Clear cache**: Sometimes Tailwind needs a rebuild to recognize dark mode classes
612
+
613
+ ## Supported Wallets
614
+
615
+ - Sage Wallet
616
+ - Ozone Wallet
617
+ - Reference Wallet
618
+ - Any WalletConnect-compatible Chia wallet
619
+
620
+ ## License
621
+
622
+ See LICENSE file for details.
package/dist/api.d.ts ADDED
@@ -0,0 +1,62 @@
1
+ export interface Token {
2
+ asset_id: string;
3
+ hidden_puzzle_hash: string | null;
4
+ name: string;
5
+ short_name: string;
6
+ image_url: string;
7
+ verified: boolean;
8
+ }
9
+ export interface Pair {
10
+ pair_id: string;
11
+ asset_id: string;
12
+ asset_name: string;
13
+ asset_hidden_puzzle_hash: string | null;
14
+ asset_short_name: string;
15
+ asset_image_url: string;
16
+ asset_verified: boolean;
17
+ inverse_fee: number;
18
+ liquidity_asset_id: string;
19
+ xch_reserve: number;
20
+ token_reserve: number;
21
+ liquidity: number;
22
+ last_coin_id_on_chain: string;
23
+ }
24
+ export declare function pairToToken(pair: Pair): Token;
25
+ export declare enum ActionType {
26
+ SWAP = "SWAP",
27
+ ADD_LIQUIDITY = "ADD_LIQUIDITY",
28
+ REMOVE_LIQUIDITY = "REMOVE_LIQUIDITY"
29
+ }
30
+ export interface Quote {
31
+ amount_in: number;
32
+ amount_out: number;
33
+ price_warning: boolean;
34
+ fee: number;
35
+ asset_id: string;
36
+ input_reserve: number;
37
+ output_reserve: number;
38
+ }
39
+ export interface OfferResponse {
40
+ success: boolean;
41
+ message: string;
42
+ offer_id: string;
43
+ }
44
+ export interface CreatePairResponse {
45
+ success: boolean;
46
+ message: string;
47
+ coin_id: string;
48
+ }
49
+ export declare function getAllPairs(skip?: number, limit?: number): Promise<Pair[]>;
50
+ export declare function getAllTokens(): Promise<Token[]>;
51
+ export declare function getPairByLauncherId(launcherId: string): Promise<Pair>;
52
+ export declare function getQuoteForPair(pairId: string, amountIn?: number, amountOut?: number, xchIsInput?: boolean, estimateFee?: boolean): Promise<Quote>;
53
+ export declare function createOfferForPair(pairId: string, offer: string, action: ActionType, devFee: number): Promise<OfferResponse>;
54
+ export declare function createPair(assetId: string, hidden_puzzle_hash: string | null, inverse_fee: number, offer: string, xch_liquidity: number, token_liquidity: number, liquidity_destination_address: string): Promise<CreatePairResponse>;
55
+ export declare function refreshRouter(rcat: boolean): Promise<void>;
56
+ export declare function isCoinSpent(coinId: string): Promise<boolean>;
57
+ export declare function getInputPrice(input_amount: number, input_reserve: number, output_reserve: number, inverse_fee: number): number;
58
+ export declare function getOutputPrice(output_amount: number, input_reserve: number, output_reserve: number, inverse_fee: number): number;
59
+ export declare function getFastQuote(amountIn: number | undefined, amountOut: number | undefined, xchIsInput: boolean, xchReserve: number, tokenReserve: number, inverseFee: number): number;
60
+ export declare function getLiquidityQuote(knownIn: number, knownReserve: number, unknownReserve: number, checkUnknown: boolean): number;
61
+ export declare function getCNSNameApiCall(address: string): Promise<string | null>;
62
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.tsx"],"names":[],"mappings":"AAGA,MAAM,WAAW,KAAK;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;CACrB;AACD,MAAM,WAAW,IAAI;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAA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