tek-wallet 0.0.807 → 0.0.809

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 (2) hide show
  1. package/README.md +225 -13
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -19,7 +19,7 @@
19
19
 
20
20
  ```jsx
21
21
  import "swiper/css";
22
- import { TekWalletProvider } from "tek-wallet";
22
+ import { TekWalletProvider, ThemeModes } from "tek-wallet";
23
23
 
24
24
  // Cấu hình cơ bản
25
25
  <TekWalletProvider
@@ -30,14 +30,74 @@ import { TekWalletProvider } from "tek-wallet";
30
30
  </TekWalletProvider>;
31
31
  ```
32
32
 
33
- ### 2. Environment Variables
33
+ **Cấu hình nâng cao:**
34
+
35
+ ```jsx
36
+ import { TekWalletProvider, ThemeModes } from "tek-wallet";
37
+
38
+ <TekWalletProvider
39
+ theme={theme} // Custom theme object
40
+ themeMode={ThemeModes.DARK} // Chế độ theme: DARK hoặc LIGHT
41
+ isSSO
42
+ accessToken={accessToken}
43
+ options={{
44
+ useDefaultToastMessage: true, // Sử dụng toast message mặc định
45
+ hideDefaultActivities: true, // Ẩn activities mặc định
46
+ hideActivitySectionInAssetView: true, // Ẩn section activities trong AssetView
47
+ useBasicAmountGroupInAssetView: true, // Sử dụng basic amount group trong AssetView
48
+ hideBackButtons: {
49
+ // Ẩn nút back trong các view cụ thể
50
+ activity: true,
51
+ },
52
+ }}
53
+ topOffset={viewportStatusBarHeight || 0} // Offset từ top (thường dùng cho mobile)
54
+ onLogout={handleLogout} // Callback khi logout
55
+ overrideQRScanMethod={isMobileApp ? scanQRCode : undefined} // Override QR scan method
56
+ >
57
+ {children}
58
+ </TekWalletProvider>;
59
+ ```
60
+
61
+ ### 2. TekWalletProvider Props
62
+
63
+ **Props cơ bản:**
64
+
65
+ | Prop | Type | Required | Mô tả |
66
+ | ------------- | --------- | -------- | ----------------------------- |
67
+ | `isSSO` | `boolean` | ✅ | Bật chế độ SSO authentication |
68
+ | `accessToken` | `string` | ✅ | Token xác thực từ SSO |
69
+
70
+ **Props nâng cao:**
71
+
72
+ | Prop | Type | Required | Mô tả |
73
+ | ---------------------- | ------------ | -------- | ---------------------------------------------------- |
74
+ | `theme` | `object` | ❌ | Custom theme object |
75
+ | `themeMode` | `ThemeModes` | ❌ | Chế độ theme: `DARK` hoặc `LIGHT` |
76
+ | `topOffset` | `number` | ❌ | Offset từ top (thường dùng cho mobile status bar) |
77
+ | `onLogout` | `function` | ❌ | Callback function khi user logout |
78
+ | `overrideQRScanMethod` | `function` | ❌ | Override QR scan method (thường dùng cho mobile app) |
79
+
80
+ **Options object:**
81
+
82
+ | Option | Type | Default | Mô tả |
83
+ | -------------------------------- | --------- | ------- | ------------------------------------------- |
84
+ | `useDefaultToastMessage` | `boolean` | `false` | Sử dụng toast message mặc định của hệ thống |
85
+ | `hideDefaultActivities` | `boolean` | `false` | Ẩn activities mặc định |
86
+ | `hideActivitySectionInAssetView` | `boolean` | `false` | Ẩn section activities trong AssetView |
87
+ | `useBasicAmountGroupInAssetView` | `boolean` | `false` | Sử dụng basic amount group trong AssetView |
88
+ | `hideBackButtons` | `object` | `{}` | Ẩn nút back trong các view cụ thể |
89
+
90
+ **hideBackButtons object:**
91
+
92
+ | Property | Type | Mô tả |
93
+ | ---------- | --------- | ------------------------------- |
94
+ | `activity` | `boolean` | Ẩn nút back trong activity view |
95
+
96
+ ### 3. Environment Variables
34
97
 
35
98
  Các biến môi trường cần thiết:
36
99
 
37
100
  ```env
38
- TEK_WALLET_API_KEY=your_api_key
39
- TEK_WALLET_AUTH_SECRET=your_auth_secret
40
- TEK_WALLET_REFRESH_TOKEN_URL=your_refresh_token_url
41
101
  NEXT_PUBLIC_TEK_WALLET_APP_SLUG=your_app_slug
42
102
  NEXT_PUBLIC_TEK_WALLET_SERVER_URL=your_server_url
43
103
  NEXT_PUBLIC_TEK_WALLET_ABLY_API_KEY=your_ably_api_key
@@ -63,14 +123,15 @@ const { tokens } = useWallet();
63
123
 
64
124
  ### Các Components Chính
65
125
 
66
- | Component | Mô tả |
67
- | --------------------- | ----------------------------------------- |
68
- | **LockToken** | Cho phép người dùng khóa token trong ví |
69
- | **SwapToken** | Hỗ trợ chức năng hoán đổi token |
70
- | **UpdateLockedToken** | Cho phép cập nhật thông tin token đã khóa |
71
- | **ReceiveFunction** | Xử lý chức năng nhận token |
72
- | **AssetView** | Hiển thị tài sản trong |
73
- | **WithdrawFunction** | Xử chức năng rút token |
126
+ | Component | Mô tả |
127
+ | --------------------- | ------------------------------------------ |
128
+ | **LockToken** | Cho phép người dùng khóa token trong ví |
129
+ | **SwapToken** | Hỗ trợ chức năng hoán đổi token |
130
+ | **UpdateLockedToken** | Cho phép cập nhật thông tin token đã khóa |
131
+ | **ReceiveFunction** | Xử lý chức năng nhận token |
132
+ | **ReceiveDirectly** | Component nhận token trực tiếp qua QR code |
133
+ | **AssetView** | Hiển thị tài sản trong |
134
+ | **WithdrawFunction** | Xử lý chức năng rút token |
74
135
 
75
136
  ### Components Xác nhận (Confirm)
76
137
 
@@ -125,6 +186,157 @@ Nếu phía trước có path: `<path>/tek-wallet/[[...pathname]]/page.tsx` thì
125
186
  </TekWalletProvider>
126
187
  ```
127
188
 
189
+ **Ví dụ cấu hình đầy đủ cho mobile app:**
190
+
191
+ ```jsx
192
+ import { TekWalletProvider, ThemeModes } from "tek-wallet";
193
+
194
+ function App() {
195
+ const handleLogout = () => {
196
+ // Xử lý logout logic
197
+ console.log("User logged out");
198
+ };
199
+
200
+ const scanQRCode = (callback) => {
201
+ // Custom QR scan implementation cho mobile
202
+ // Gọi native QR scanner
203
+ window.nativeQRScanner?.scan(callback);
204
+ };
205
+
206
+ return (
207
+ <TekWalletProvider
208
+ theme={customTheme}
209
+ themeMode={ThemeModes.DARK}
210
+ isSSO
211
+ accessToken={accessToken}
212
+ options={{
213
+ useDefaultToastMessage: true,
214
+ hideDefaultActivities: true,
215
+ hideActivitySectionInAssetView: true,
216
+ useBasicAmountGroupInAssetView: true,
217
+ hideBackButtons: {
218
+ activity: true,
219
+ },
220
+ }}
221
+ topOffset={viewportStatusBarHeight || 0}
222
+ onLogout={handleLogout}
223
+ overrideQRScanMethod={isMobileApp ? scanQRCode : undefined}
224
+ >
225
+ <YourApp />
226
+ </TekWalletProvider>
227
+ );
228
+ }
229
+ ```
230
+
231
+ ### ReceiveDirectly
232
+
233
+ Component cho phép hiển thị QR code và địa chỉ nhận token trực tiếp, hỗ trợ cả nhận nội bộ và nhận từ blockchain.
234
+
235
+ **Props:**
236
+
237
+ | Prop | Type | Required | Mô tả |
238
+ | ------------- | ----------------------- | -------- | ------------------------------------------------------------ |
239
+ | `tokenSlug` | `string` | ✅ | Slug của token muốn nhận |
240
+ | `method` | `ReceiveDirectlyMethod` | ✅ | Phương thức nhận: `RECEIVE_INTERNAL` hoặc `RECEIVE_EXTERNAL` |
241
+ | `networkSlug` | `string` | ❌ | Slug của network (bỏ qua nếu muốn cho user chọn network) |
242
+ | `amount` | `string \| number` | ❌ | Số lượng token muốn nhận (hiển thị trong QR code) |
243
+ | `userInfo` | `object` | ❌ | Thông tin người nhận để hiển thị |
244
+
245
+ **Ref Methods:**
246
+
247
+ | Method | Mô tả |
248
+ | ------- | ---------- |
249
+ | `open` | Mở modal |
250
+ | `close` | Đóng modal |
251
+
252
+ **Enum ReceiveDirectlyMethod:**
253
+
254
+ ```typescript
255
+ enum ReceiveDirectlyMethod {
256
+ RECEIVE_INTERNAL = "Internal Transfer", // Nhận token nội bộ
257
+ RECEIVE_EXTERNAL = "Blockchain Deposit", // Nhận token từ blockchain
258
+ }
259
+ ```
260
+
261
+ **Ví dụ 1: Nhận token nội bộ (Internal Transfer)**
262
+
263
+ ```jsx
264
+ import { ReceiveDirectly, ReceiveDirectlyMethod } from "tek-wallet";
265
+ import { useRef } from "react";
266
+
267
+ function MyComponent() {
268
+ const receiveRef = useRef(null);
269
+
270
+ return (
271
+ <>
272
+ <Button onClick={() => receiveRef.current?.open()}>Nhận USDT nội bộ</Button>
273
+
274
+ <ReceiveDirectly
275
+ ref={receiveRef}
276
+ tokenSlug="usdt"
277
+ method={ReceiveDirectlyMethod.RECEIVE_INTERNAL}
278
+ amount={100}
279
+ userInfo={{
280
+ nickname: "John Doe",
281
+ username: "@johndoe",
282
+ avatar: "https://example.com/avatar.jpg",
283
+ }}
284
+ />
285
+ </>
286
+ );
287
+ }
288
+ ```
289
+
290
+ **Ví dụ 2: Nhận token từ blockchain (Blockchain Deposit)**
291
+
292
+ ```jsx
293
+ import { ReceiveDirectly, ReceiveDirectlyMethod } from "tek-wallet";
294
+ import { useRef } from "react";
295
+
296
+ function MyComponent() {
297
+ const receiveRef = useRef(null);
298
+
299
+ return (
300
+ <>
301
+ <Button onClick={() => receiveRef.current?.open()}>Nhận USDT từ blockchain</Button>
302
+
303
+ {/* Cách 1: Chỉ định network cụ thể */}
304
+ <ReceiveDirectly
305
+ ref={receiveRef}
306
+ tokenSlug="usdt"
307
+ method={ReceiveDirectlyMethod.RECEIVE_EXTERNAL}
308
+ networkSlug="trc20"
309
+ />
310
+
311
+ {/* Cách 2: Cho phép user chọn network */}
312
+ <ReceiveDirectly
313
+ ref={receiveRef}
314
+ tokenSlug="usdt"
315
+ method={ReceiveDirectlyMethod.RECEIVE_EXTERNAL}
316
+ // Không truyền networkSlug - user sẽ chọn network
317
+ />
318
+ </>
319
+ );
320
+ }
321
+ ```
322
+
323
+ **Ví dụ 3: Sử dụng với trigger children**
324
+
325
+ ```jsx
326
+ <ReceiveDirectly tokenSlug="usdt" method={ReceiveDirectlyMethod.RECEIVE_INTERNAL}>
327
+ <Button>Click để nhận USDT</Button>
328
+ </ReceiveDirectly>
329
+ ```
330
+
331
+ **Lưu ý:**
332
+
333
+ - 🔸 Khi sử dụng `RECEIVE_INTERNAL`, không cần truyền `networkSlug`
334
+ - 🔸 Khi sử dụng `RECEIVE_EXTERNAL` mà không truyền `networkSlug`, user sẽ được yêu cầu chọn network
335
+ - 🔸 Component tự động validate token và network, hiển thị lỗi nếu không hợp lệ
336
+ - 🔸 QR code được tạo tự động dựa trên method và các thông tin được truyền vào
337
+ - 🔸 Với Internal Transfer, QR code chứa thông tin JSON để xử lý chuyển khoản nội bộ
338
+ - 🔸 Với Blockchain Deposit, QR code chứa địa chỉ blockchain wallet
339
+
128
340
  ---
129
341
 
130
342
  ## 📊 States
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tek-wallet",
3
- "version": "0.0.807",
3
+ "version": "0.0.809",
4
4
  "description": "A custom React provider with TypeScript support",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",