droplinked-web3-ui 0.0.10 โ†’ 0.0.12

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,75 +1,512 @@
1
- # React + TypeScript + Vite
2
-
3
- This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4
-
5
- Currently, two official plugins are available:
6
-
7
- - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
8
- - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
9
-
10
- ## React Compiler
11
-
12
- The React Compiler is enabled on this template. See [this documentation](https://react.dev/learn/react-compiler) for more information.
13
-
14
- Note: This will impact Vite dev & build performances.
15
-
16
- ## Expanding the ESLint configuration
17
-
18
- If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
19
-
20
- ```js
21
- export default defineConfig([
22
- globalIgnores(['dist']),
23
- {
24
- files: ['**/*.{ts,tsx}'],
25
- extends: [
26
- // Other configs...
27
-
28
- // Remove tseslint.configs.recommended and replace with this
29
- tseslint.configs.recommendedTypeChecked,
30
- // Alternatively, use this for stricter rules
31
- tseslint.configs.strictTypeChecked,
32
- // Optionally, add this for stylistic rules
33
- tseslint.configs.stylisticTypeChecked,
34
-
35
- // Other configs...
36
- ],
37
- languageOptions: {
38
- parserOptions: {
39
- project: ['./tsconfig.node.json', './tsconfig.app.json'],
40
- tsconfigRootDir: import.meta.dirname,
41
- },
42
- // other options...
43
- },
44
- },
45
- ])
46
- ```
47
-
48
- You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
49
-
50
- ```js
51
- // eslint.config.js
52
- import reactX from 'eslint-plugin-react-x'
53
- import reactDom from 'eslint-plugin-react-dom'
54
-
55
- export default defineConfig([
56
- globalIgnores(['dist']),
57
- {
58
- files: ['**/*.{ts,tsx}'],
59
- extends: [
60
- // Other configs...
61
- // Enable lint rules for React
62
- reactX.configs['recommended-typescript'],
63
- // Enable lint rules for React DOM
64
- reactDom.configs.recommended,
65
- ],
66
- languageOptions: {
67
- parserOptions: {
68
- project: ['./tsconfig.node.json', './tsconfig.app.json'],
69
- tsconfigRootDir: import.meta.dirname,
70
- },
71
- // other options...
72
- },
73
- },
74
- ])
1
+ # ๐Ÿ’Ž droplinked-web3-ui
2
+
3
+ A React library for Web3 payments and NFT claims on the Droplinked platform.
4
+
5
+ ![Version](https://img.shields.io/npm/v/droplinked-web3-ui)
6
+ ![License](https://img.shields.io/npm/l/droplinked-web3-ui)
7
+
8
+ ---
9
+
10
+ ## ๐Ÿ“ฆ Installation
11
+
12
+ ```bash
13
+ npm install droplinked-web3-ui
14
+ ```
15
+
16
+ ---
17
+
18
+ ## ๐Ÿš€ Main Dependencies
19
+
20
+ This project uses the following dependencies:
21
+
22
+ | Package | Version | Description |
23
+ |---------|---------|-------------|
24
+ | ๐ŸŒ `droplinked-web3-kit` | ^1.0.7 | Core Web3 library for blockchain interaction |
25
+ | ๐ŸŽจ `droplinked-ui-kit` | ^0.0.38 | Shared UI components |
26
+ | โšก `@chakra-ui/react` | ^3.32.0 | UI framework |
27
+ | ๐Ÿช `zustand` | ^5.0.11 | State management |
28
+ | ๐Ÿ”„ `react-query` | ^3.39.3 | API request management |
29
+ | ๐Ÿ“ก `axios` | ^1.13.5 | HTTP client |
30
+
31
+ ---
32
+
33
+ ## ๐Ÿ’ณ Component Usage
34
+
35
+ ### DroplinkedWeb3Ui - Unified Web3 Component ๐Ÿš€
36
+
37
+ Main component for all Web3 operations. Use the `action` prop to specify the operation type:
38
+
39
+ ```tsx
40
+ import { DroplinkedWeb3Ui, Actions } from 'droplinked-web3-ui';
41
+ ```
42
+
43
+ #### Available Actions
44
+
45
+ ```typescript
46
+ enum Actions {
47
+ Payment = 'payment', // ๐Ÿ’ณ Cryptocurrency payments
48
+ ClaimNFT = 'claimNFT', // ๐ŸŽจ NFT claims
49
+ }
50
+ ```
51
+
52
+ ---
53
+
54
+ ### 1๏ธโƒฃ Payment Action ๐Ÿ’ฐ
55
+
56
+ Process cryptocurrency payments:
57
+
58
+ ```tsx
59
+ import { DroplinkedWeb3Ui, Actions } from 'droplinked-web3-ui';
60
+
61
+ function PaymentPage() {
62
+ return (
63
+ <DroplinkedWeb3Ui
64
+ action={Actions.Payment}
65
+ inputs={{
66
+ cartId: "cart-id-here",
67
+ shopId: "shop-id-here",
68
+ price: 100,
69
+ priceInShopCurrency: 100,
70
+ abbreviation: "USD",
71
+ symbol: "$",
72
+ onError: (error) => console.error(error),
73
+ onSuccess: (orderId) => console.log('Success:', orderId),
74
+ }}
75
+ />
76
+ );
77
+ }
78
+ ```
79
+
80
+ #### ๐Ÿ“ Payment Inputs
81
+
82
+ | Prop | Type | Description |
83
+ |------|------|-------------|
84
+ | ๐Ÿ›’ `cartId` | `string` | Shopping cart ID |
85
+ | ๐Ÿช `shopId` | `string` | Shop ID |
86
+ | ๐Ÿ’ต `price` | `number` | Payment amount |
87
+ | ๐Ÿ’ฑ `priceInShopCurrency` | `number` | Amount in shop currency |
88
+ | ๐Ÿท๏ธ `abbreviation` | `string` | Currency symbol (e.g., USD) |
89
+ | ๐Ÿ’ฒ `symbol` | `string` | Display symbol (e.g., $) |
90
+ | โŒ `onError` | `(error: string) => void` | Error callback |
91
+ | โœ… `onSuccess` | `(orderId?: string) => void` | Success callback |
92
+
93
+ ---
94
+
95
+ ### 2๏ธโƒฃ ClaimNFT Action ๐ŸŽจ
96
+
97
+ Claim NFTs after payment:
98
+
99
+ ```tsx
100
+ import { DroplinkedWeb3Ui, Actions } from 'droplinked-web3-ui';
101
+
102
+ function ClaimPage() {
103
+ return (
104
+ <DroplinkedWeb3Ui
105
+ action={Actions.ClaimNFT}
106
+ inputs={{
107
+ orderId: "order-id-here",
108
+ skuId: "sku-id-here",
109
+ buttonText: "Claim NFT",
110
+ isButtonDisabled: false,
111
+ onError: (message) => console.error(message),
112
+ onSuccess: (txHash) => console.log('Claimed:', txHash),
113
+ }}
114
+ />
115
+ );
116
+ }
75
117
  ```
118
+
119
+ #### ๐Ÿ“ ClaimNFT Inputs
120
+
121
+ | Prop | Type | Description |
122
+ |------|------|-------------|
123
+ | ๐Ÿ“‹ `orderId` | `string` | Order ID |
124
+ | ๐Ÿท๏ธ `skuId` | `string` | SKU ID |
125
+ | ๐Ÿ”˜ `buttonText` | `string` | Button text |
126
+ | ๐Ÿšซ `isButtonDisabled` | `boolean` | Button disabled state |
127
+ | โŒ `onError` | `(message: string) => void` | Error callback |
128
+ | โœ… `onSuccess` | `(txHash: string) => void` | Success callback |
129
+
130
+ ---
131
+
132
+ ### Type Safety โœจ
133
+
134
+ The component uses TypeScript generics to provide type-safe inputs based on the action:
135
+
136
+ ```tsx
137
+ // โœ… TypeScript knows inputs should be PaymentInputs
138
+ <DroplinkedWeb3Ui
139
+ action={Actions.Payment}
140
+ inputs={{
141
+ cartId: "...", // Autocomplete works!
142
+ // skuId is NOT suggested here โŒ
143
+ }}
144
+ />
145
+
146
+ // โœ… TypeScript knows inputs should be ClaimNFTInputs
147
+ <DroplinkedWeb3Ui
148
+ action={Actions.ClaimNFT}
149
+ inputs={{
150
+ orderId: "...", // Autocomplete works!
151
+ // cartId is NOT suggested here โŒ
152
+ }}
153
+ />
154
+ ```
155
+
156
+ ---
157
+
158
+ ## ๐Ÿ› ๏ธ Development
159
+
160
+ ### ๐Ÿ“ Project Structure
161
+
162
+ ```
163
+ ๐Ÿ“ฆ src/
164
+ โ”œโ”€โ”€ ๐Ÿ“‚ components/
165
+ โ”‚ โ”œโ”€โ”€ ๐Ÿ“‚ modals/ # ๐ŸชŸ Modals
166
+ โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“‚ wallet-connection/ # ๐Ÿ”— Wallet connection modal
167
+ โ”‚ โ”œโ”€โ”€ ๐Ÿ“‚ pay-with-crypto-element/ # ๐Ÿ’ธ Crypto payment element
168
+ โ”‚ โ”œโ”€โ”€ ๐Ÿ“‚ claim-nft-element/ # ๐ŸŽจ NFT claim element
169
+ โ”‚ โ””โ”€โ”€ ๐Ÿ“‚ common/ # ๐Ÿ”ง Shared components
170
+ โ”œโ”€โ”€ ๐Ÿ“‚ context/
171
+ โ”‚ โ””โ”€โ”€ ๐Ÿ“‚ dropWeb3Context/ # ๐ŸŒ Web3 context
172
+ โ”œโ”€โ”€ ๐Ÿ“‚ hooks/ # โš“ Custom hooks
173
+ โ”œโ”€โ”€ ๐Ÿ“‚ stores/ # ๐Ÿช Zustand stores
174
+ โ”œโ”€โ”€ ๐Ÿ“‚ apis/ # ๐Ÿ”Œ API services
175
+ โ””โ”€โ”€ ๐Ÿ“‚ utils/ # ๐Ÿ› ๏ธ Utilities
176
+ ```
177
+
178
+ ---
179
+
180
+ ### ๐ŸชŸ Modals
181
+
182
+ Modals are located in `src/components/modals/` and managed using the `useModals` hook:
183
+
184
+ ```tsx
185
+ const {
186
+ activeModal,
187
+ openConnectModal, // ๐Ÿ”— Open wallet connection modal
188
+ openBrowseWallets, # ๐Ÿ“ฑ Open wallet list modal
189
+ openSelectNetworkModal, # ๐ŸŒ Open network selection modal
190
+ openWalletConnectionModal, # ๐Ÿ”Œ Open wallet connection modal
191
+ openManageWalletsModal, # ๐ŸŽ›๏ธ Open wallet management modal
192
+ openSelectTokenModal, # ๐Ÿช™ Open token selection modal
193
+ openPaymentProcessModal, # ๐Ÿ’ณ Open payment process modal
194
+ openClaimProcessModal, # ๐ŸŽ Open claim process modal
195
+ closeModal, # โŒ Close active modal
196
+ } = useModals();
197
+ ```
198
+
199
+ ---
200
+
201
+ ## ๐Ÿช Hooks
202
+
203
+ ### ๐ŸŽฏ useDropWeb3
204
+
205
+ Main hook to access the `droplinked-web3-kit` library instance:
206
+
207
+ ```tsx
208
+ import { useDropWeb3 } from '@/context/dropWeb3Context/useDropWeb3';
209
+
210
+ function MyComponent() {
211
+ const { web3, provider } = useDropWeb3();
212
+
213
+ // web3: instance of DropWeb3 class ๐Ÿš€
214
+ // provider: provider for wallet connections ๐Ÿ”—
215
+ }
216
+ ```
217
+
218
+ > โš ๏ธ **Note:** This hook must be used inside `DropWeb3Provider`.
219
+
220
+ ---
221
+
222
+ ### ๐Ÿ’ณ usePayWithCrypto
223
+
224
+ Hook for managing crypto payments:
225
+
226
+ ```tsx
227
+ import { usePayWithCrypto } from '@/hooks/usePayWithCrypto';
228
+
229
+ function MyComponent() {
230
+ const {
231
+ hasConnectedWallets, # โœ… boolean - Whether connected wallets exist
232
+ connectedWallets, # ๐Ÿ‘› IWallet[] - List of connected wallets
233
+ isLoading, # โณ boolean - Loading state
234
+ loadWallets, # ๐Ÿ”„ () => Promise<void> - Load wallets
235
+ } = usePayWithCrypto();
236
+ }
237
+ ```
238
+
239
+ ---
240
+
241
+ ### ๐Ÿช™ useTokenBalances
242
+
243
+ Hook for fetching token balances:
244
+
245
+ ```tsx
246
+ import { useTokenBalances } from '@/hooks/useTokenBalances';
247
+
248
+ function MyComponent() {
249
+ useTokenBalances(hasConnectedWallets); # ๐Ÿ”„ Updates token balances
250
+ }
251
+ ```
252
+
253
+ ---
254
+
255
+ ### ๐ŸชŸ useModals
256
+
257
+ Hook for managing modals (explained above).
258
+
259
+ ---
260
+
261
+ ### ๐Ÿ‘› useWallets
262
+
263
+ Hook for managing wallets.
264
+
265
+ ---
266
+
267
+ ### ๐Ÿ’ฐ useFormattedAmount
268
+
269
+ Hook for formatting financial amounts.
270
+
271
+ ---
272
+
273
+ ## ๐Ÿช Zustand Stores
274
+
275
+ ### ๐Ÿ’ณ paymentUiStore
276
+
277
+ Manages payment state:
278
+
279
+ ```tsx
280
+ import { usePaymentUiStore } from '@/stores/paymentUiStore';
281
+
282
+ const {
283
+ cartId, # ๐Ÿ›’
284
+ price, # ๐Ÿ’ต
285
+ abbreviation, # ๐Ÿท๏ธ
286
+ symbol, # ๐Ÿ’ฒ
287
+ onError, # โŒ
288
+ onMainProcessSuccess, # โœ…
289
+ setPaymentUiData, # ๐Ÿ“ (props) => set state
290
+ currentDescription, # ๐Ÿ“„ Current process description
291
+ currentError, # โš ๏ธ Current error
292
+ currentErrorDescription, # ๐Ÿ“‹ Error description
293
+ } = usePaymentUiStore();
294
+ ```
295
+
296
+ ---
297
+
298
+ ### ๐ŸŽจ claimNftStore
299
+
300
+ Manages NFT claim state:
301
+
302
+ ```tsx
303
+ import { useClaimNftStore } from '@/stores/claimNftStore';
304
+
305
+ const {
306
+ orderId, # ๐Ÿ“‹
307
+ skuId, # ๐Ÿท๏ธ
308
+ onError, # โŒ
309
+ onMainProcessSuccess, # โœ…
310
+ buttonText, # ๐Ÿ”˜
311
+ isButtonDisabled, # ๐Ÿšซ
312
+ setClaimNftData, # ๐Ÿ“ (data) => set state
313
+ currentDescription, # ๐Ÿ“„
314
+ currentError, # โš ๏ธ
315
+ currentErrorDescription, # ๐Ÿ“‹
316
+ } = useClaimNftStore();
317
+ ```
318
+
319
+ ---
320
+
321
+ ### ๐ŸชŸ modalStore
322
+
323
+ Manages modal state:
324
+
325
+ ```tsx
326
+ import { useModalStore } from '@/stores/modalStore';
327
+
328
+ const {
329
+ activeModal, # ๐ŸชŸ ModalType - Active modal
330
+ openModal, # ๐Ÿ“‚ (modal) => Open modal
331
+ closeModal, # โŒ () => Close modal
332
+ closeAndOpen, # ๐Ÿ”„ (current, next, data?) => Close and open
333
+ } = useModalStore();
334
+ ```
335
+
336
+ #### ๐Ÿ“‹ ModalType Values
337
+
338
+ | Modal | Description |
339
+ |-------|-------------|
340
+ | ๐Ÿ”— `'connectWallet'` | Connect wallet modal |
341
+ | ๐Ÿ“ฑ `'browseWallets'` | Browse wallets modal |
342
+ | ๐Ÿ“ฅ `'getWallet'` | Get wallet modal |
343
+ | ๐ŸŒ `'selectNetwork'` | Select network modal |
344
+ | ๐Ÿ”Œ `'walletConnection'` | Wallet connection modal |
345
+ | ๐ŸŽ›๏ธ `'manageWallets'` | Manage wallets modal |
346
+ | ๐Ÿช™ `'selectToken'` | Select token modal |
347
+ | ๐Ÿ’ณ `'paymentProcess'` | Payment process modal |
348
+ | ๐ŸŽ `'claimProcess'` | Claim process modal |
349
+
350
+ ---
351
+
352
+ ### ๐Ÿ‘› walletStore
353
+
354
+ Manages wallet state:
355
+
356
+ ```tsx
357
+ import { useWalletStore } from '@/stores/walletStore';
358
+
359
+ const {
360
+ allWallets, # ๐Ÿ“ฑ IWallet[] - All wallets
361
+ selectedWallet, # ๐Ÿ‘† IWallet \| null - Selected wallet
362
+ selectedConnectedWallet, # ๐Ÿ”— IWallet \| null - Selected connected wallet
363
+ setAllWallets, # ๐Ÿ“ (wallets) => set wallets
364
+ setSelectedWallet, # ๐Ÿ“ (wallet) => set selected
365
+ setSelectedConnectedWallet, # ๐Ÿ“
366
+ } = useWalletStore();
367
+ ```
368
+
369
+ ---
370
+
371
+ ### ๐Ÿช™ tokenStore
372
+
373
+ Manages token state:
374
+
375
+ ```tsx
376
+ import { useTokenStore } from '@/stores/tokenStore';
377
+
378
+ const {
379
+ selectedToken, # ๐Ÿช™ Selected token
380
+ setSelectedToken, # ๐Ÿ“ (token) => set token
381
+ } = useTokenStore();
382
+ ```
383
+
384
+ ---
385
+
386
+ ### ๐Ÿ“‹ orderStore
387
+
388
+ Manages order state.
389
+
390
+ ---
391
+
392
+ ## ๐Ÿงฉ Main Components
393
+
394
+ ### ๐ŸŒ DropWeb3Provider
395
+
396
+ Main provider for Web3 access:
397
+
398
+ ```tsx
399
+ import { DropWeb3Provider } from '@/context/dropWeb3Context/DropWeb3Context';
400
+
401
+ <DropWeb3Provider>
402
+ <YourComponents />
403
+ </DropWeb3Provider>
404
+ ```
405
+
406
+ > ๐Ÿ’ก This provider is automatically included in `DroplinkedWeb3Ui`.
407
+
408
+ ---
409
+
410
+ ### ๐Ÿ’ธ PayWithCrypto
411
+
412
+ Internal payment UI component used by `DroplinkedWeb3Ui` when `action={Actions.Payment}`. Includes:
413
+ - ๐Ÿ‘› Display of connected wallets
414
+ - ๐Ÿช™ Token selection
415
+ - ๐Ÿ’ณ Payment process
416
+
417
+ ---
418
+
419
+ ### ๐ŸŽจ ClaimNftUi
420
+
421
+ Internal NFT claim UI component used by `DroplinkedWeb3Ui` when `action={Actions.ClaimNFT}`.
422
+
423
+ ---
424
+
425
+ ## ๐Ÿ”Œ API Services
426
+
427
+ Services are located in `src/apis/`:
428
+
429
+ | Service | Path | Description |
430
+ |---------|------|-------------|
431
+ | ๐Ÿ’ณ Payment | `payment/services.ts` | Payment services |
432
+ | ๐Ÿ“‹ Orders | `orders/services.ts` | Order services |
433
+ | ๐ŸŒ Web3 | `web3/services.ts` | Web3 services |
434
+
435
+ ---
436
+
437
+ ## ๐Ÿš€ Publishing
438
+
439
+ To publish a new version:
440
+
441
+ ### 1๏ธโƒฃ Update the version
442
+
443
+ ```bash
444
+ npm version patch # ๐Ÿ”ง For small changes
445
+ npm version minor # โœจ For new features
446
+ npm version major # โš ๏ธ For breaking changes
447
+ ```
448
+
449
+ ### 2๏ธโƒฃ Commit and push
450
+
451
+ ```bash
452
+ git add .
453
+ git commit -m "chore: bump version to x.x.x"
454
+ git push origin main
455
+ ```
456
+
457
+ ### 3๏ธโƒฃ Automatic publish โœจ
458
+
459
+ When pushing to the `main` branch, GitHub Actions will automatically:
460
+ 1. ๐Ÿ”จ Build the project
461
+ 2. ๐Ÿ”„ Compare the version with npm
462
+ 3. ๐Ÿš€ Publish to npm if the version is new
463
+
464
+ > โš ๏ธ **Important notes:**
465
+ > - Only changes to `package.json` or workflow trigger the publish
466
+ > - For manual publish, use `workflow_dispatch` in GitHub Actions
467
+ > - Make sure `NPM_TOKEN` is set in repository secrets ๐Ÿ”
468
+
469
+ ---
470
+
471
+ ## ๐Ÿ”ง Environment Variables
472
+
473
+ This project uses the following variables (in `.env`):
474
+
475
+ ```env
476
+ # ๐Ÿงช Development
477
+ VITE_BASE_API_URL_DEV=https://apiv3dev.droplinked.com
478
+
479
+ # ๐Ÿš€ Production
480
+ VITE_BASE_API_URL_MAIN=https://apiv3.droplinked.com
481
+ ```
482
+
483
+ ---
484
+
485
+ ## ๐Ÿ’ป Development Notes
486
+
487
+ ### ๐ŸŽฏ Available Scripts
488
+
489
+ | Command | Description |
490
+ |---------|-------------|
491
+ | `npm run dev` | ๐Ÿš€ Start development server |
492
+ | `npm run build` | ๐Ÿ”จ Build for production |
493
+ | `npm run lint` | ๐Ÿ” Run linter |
494
+ | `npm run preview` | ๐Ÿ‘๏ธ Preview production build |
495
+
496
+ ### ๐Ÿ› Debug Mode
497
+
498
+ In `src/utils/variables.ts`, set `appDevelopment` to `true` to display logs ๐Ÿ“
499
+
500
+ ---
501
+
502
+ ## ๐Ÿ“„ License
503
+
504
+ MIT ยฉ Droplinked
505
+
506
+ ---
507
+
508
+ <div align="center">
509
+
510
+ Made with โค๏ธ by the Droplinked Team
511
+
512
+ </div>