tek-wallet 0.0.807 → 0.0.808
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 +118 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -63,14 +63,15 @@ const { tokens } = useWallet();
|
|
|
63
63
|
|
|
64
64
|
### Các Components Chính
|
|
65
65
|
|
|
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
|
-
| **
|
|
73
|
-
| **
|
|
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
|
+
| **ReceiveDirectly** | Component nhận token trực tiếp qua QR code |
|
|
73
|
+
| **AssetView** | Hiển thị tài sản trong ví |
|
|
74
|
+
| **WithdrawFunction** | Xử lý chức năng rút token |
|
|
74
75
|
|
|
75
76
|
### Components Xác nhận (Confirm)
|
|
76
77
|
|
|
@@ -125,6 +126,115 @@ Nếu phía trước có path: `<path>/tek-wallet/[[...pathname]]/page.tsx` thì
|
|
|
125
126
|
</TekWalletProvider>
|
|
126
127
|
```
|
|
127
128
|
|
|
129
|
+
### ReceiveDirectly
|
|
130
|
+
|
|
131
|
+
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.
|
|
132
|
+
|
|
133
|
+
**Props:**
|
|
134
|
+
|
|
135
|
+
| Prop | Type | Required | Mô tả |
|
|
136
|
+
| ------------- | ----------------------- | -------- | ------------------------------------------------------------ |
|
|
137
|
+
| `tokenSlug` | `string` | ✅ | Slug của token muốn nhận |
|
|
138
|
+
| `method` | `ReceiveDirectlyMethod` | ✅ | Phương thức nhận: `RECEIVE_INTERNAL` hoặc `RECEIVE_EXTERNAL` |
|
|
139
|
+
| `networkSlug` | `string` | ❌ | Slug của network (bỏ qua nếu muốn cho user chọn network) |
|
|
140
|
+
| `amount` | `string \| number` | ❌ | Số lượng token muốn nhận (hiển thị trong QR code) |
|
|
141
|
+
| `userInfo` | `object` | ❌ | Thông tin người nhận để hiển thị |
|
|
142
|
+
|
|
143
|
+
**Ref Methods:**
|
|
144
|
+
|
|
145
|
+
| Method | Mô tả |
|
|
146
|
+
| ------- | ---------- |
|
|
147
|
+
| `open` | Mở modal |
|
|
148
|
+
| `close` | Đóng modal |
|
|
149
|
+
|
|
150
|
+
**Enum ReceiveDirectlyMethod:**
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
enum ReceiveDirectlyMethod {
|
|
154
|
+
RECEIVE_INTERNAL = "Internal Transfer", // Nhận token nội bộ
|
|
155
|
+
RECEIVE_EXTERNAL = "Blockchain Deposit", // Nhận token từ blockchain
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
**Ví dụ 1: Nhận token nội bộ (Internal Transfer)**
|
|
160
|
+
|
|
161
|
+
```jsx
|
|
162
|
+
import { ReceiveDirectly, ReceiveDirectlyMethod } from "tek-wallet";
|
|
163
|
+
import { useRef } from "react";
|
|
164
|
+
|
|
165
|
+
function MyComponent() {
|
|
166
|
+
const receiveRef = useRef(null);
|
|
167
|
+
|
|
168
|
+
return (
|
|
169
|
+
<>
|
|
170
|
+
<Button onClick={() => receiveRef.current?.open()}>Nhận USDT nội bộ</Button>
|
|
171
|
+
|
|
172
|
+
<ReceiveDirectly
|
|
173
|
+
ref={receiveRef}
|
|
174
|
+
tokenSlug="usdt"
|
|
175
|
+
method={ReceiveDirectlyMethod.RECEIVE_INTERNAL}
|
|
176
|
+
amount={100}
|
|
177
|
+
userInfo={{
|
|
178
|
+
nickname: "John Doe",
|
|
179
|
+
username: "@johndoe",
|
|
180
|
+
avatar: "https://example.com/avatar.jpg",
|
|
181
|
+
}}
|
|
182
|
+
/>
|
|
183
|
+
</>
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
**Ví dụ 2: Nhận token từ blockchain (Blockchain Deposit)**
|
|
189
|
+
|
|
190
|
+
```jsx
|
|
191
|
+
import { ReceiveDirectly, ReceiveDirectlyMethod } from "tek-wallet";
|
|
192
|
+
import { useRef } from "react";
|
|
193
|
+
|
|
194
|
+
function MyComponent() {
|
|
195
|
+
const receiveRef = useRef(null);
|
|
196
|
+
|
|
197
|
+
return (
|
|
198
|
+
<>
|
|
199
|
+
<Button onClick={() => receiveRef.current?.open()}>Nhận USDT từ blockchain</Button>
|
|
200
|
+
|
|
201
|
+
{/* Cách 1: Chỉ định network cụ thể */}
|
|
202
|
+
<ReceiveDirectly
|
|
203
|
+
ref={receiveRef}
|
|
204
|
+
tokenSlug="usdt"
|
|
205
|
+
method={ReceiveDirectlyMethod.RECEIVE_EXTERNAL}
|
|
206
|
+
networkSlug="trc20"
|
|
207
|
+
/>
|
|
208
|
+
|
|
209
|
+
{/* Cách 2: Cho phép user chọn network */}
|
|
210
|
+
<ReceiveDirectly
|
|
211
|
+
ref={receiveRef}
|
|
212
|
+
tokenSlug="usdt"
|
|
213
|
+
method={ReceiveDirectlyMethod.RECEIVE_EXTERNAL}
|
|
214
|
+
// Không truyền networkSlug - user sẽ chọn network
|
|
215
|
+
/>
|
|
216
|
+
</>
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
**Ví dụ 3: Sử dụng với trigger children**
|
|
222
|
+
|
|
223
|
+
```jsx
|
|
224
|
+
<ReceiveDirectly tokenSlug="usdt" method={ReceiveDirectlyMethod.RECEIVE_INTERNAL}>
|
|
225
|
+
<Button>Click để nhận USDT</Button>
|
|
226
|
+
</ReceiveDirectly>
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
**Lưu ý:**
|
|
230
|
+
|
|
231
|
+
- 🔸 Khi sử dụng `RECEIVE_INTERNAL`, không cần truyền `networkSlug`
|
|
232
|
+
- 🔸 Khi sử dụng `RECEIVE_EXTERNAL` mà không truyền `networkSlug`, user sẽ được yêu cầu chọn network
|
|
233
|
+
- 🔸 Component tự động validate token và network, hiển thị lỗi nếu không hợp lệ
|
|
234
|
+
- 🔸 QR code được tạo tự động dựa trên method và các thông tin được truyền vào
|
|
235
|
+
- 🔸 Với Internal Transfer, QR code chứa thông tin JSON để xử lý chuyển khoản nội bộ
|
|
236
|
+
- 🔸 Với Blockchain Deposit, QR code chứa địa chỉ blockchain wallet
|
|
237
|
+
|
|
128
238
|
---
|
|
129
239
|
|
|
130
240
|
## 📊 States
|