zigap-utils 2.0.3 → 2.0.5

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,276 +1,408 @@
1
1
  # zigap-utils
2
2
 
3
- It is a library that collects utils that help communicate between dapp and zigap.<br /> You can find out more at https://seoul-labs.gitbook.io/zigap-utils
3
+ <div align="center">
4
4
 
5
- <br />
6
- <br />
5
+ ![Zigap Utils](https://img.shields.io/badge/zigap--utils-v1.0.0-blue?style=for-the-badge) ![License](https://img.shields.io/badge/license-ISC-green?style=for-the-badge) ![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?style=for-the-badge&logo=typescript&logoColor=white)
7
6
 
8
- ## Installation
7
+ **A utility library that helps communicate between dapp and zigap**
9
8
 
9
+ [📖 Documentation](https://seoul-labs.gitbook.io/zigap-utils) • [🚀 Installation](#installation) • [💡 Usage](#usage)
10
+
11
+ </div>
12
+
13
+ ---
14
+
15
+ ## 📦 Installation
16
+
17
+ ```bash
18
+ npm install zigap-utils
10
19
  ```
11
- npm i zigap-utils
20
+
21
+ ```bash
22
+ yarn add zigap-utils
23
+ ```
24
+
25
+ ```bash
26
+ pnpm add zigap-utils
12
27
  ```
13
28
 
14
- <br />
15
- <br />
29
+ ---
16
30
 
17
- ## Usage
31
+ ## 🚀 Usage
18
32
 
19
- > \_ INDEX
20
- >
21
- > 1. <b>Login</b>
22
- > 2. <b>Signature</b>
23
- > 3. <b>SendTransaction</b>
24
- > 4. <b>useZigap Hook</b>
33
+ zigap-utils provides React components for seamless communication between dapp and zigap app.
25
34
 
26
- ### 1. Login
35
+ ### 📋 Table of Contents
27
36
 
28
- ```ts
29
- import { LoginQR } from 'zigap-utils';
30
- import type { LoginResultType } from 'zigap-utils/LoginQR/LoginQR.types'
37
+ - [🔐 LoginQR](#-loginqr)
38
+ - [✍️ SignatureQR](#️-signatureqr)
39
+ - [💸 SendTransactionQR](#-sendtransactionqr)
40
+
41
+ ---
42
+
43
+ ## 🔐 LoginQR
44
+
45
+ QR code component for user wallet login.
46
+
47
+ ### Basic Usage
48
+
49
+ ```tsx
50
+ import { LoginQR, LoginResultType } from 'zigap-utils';
31
51
 
32
52
  const App = () => {
33
53
  const [result, setResult] = useState<LoginResultType | null>(null);
34
- ...
35
54
 
36
55
  return (
37
56
  <div>
38
57
  <LoginQR
39
- dapp='your Dapp Name'
40
- url='http://sample.yours.com'
41
- availableNetworks={['v2xphere, v3xphere']}
42
- isShowLogo={false}
43
- logoSize={25}
58
+ dapp='My Awesome Dapp'
59
+ url='https://myapp.com'
60
+ availableNetworks={['v2xphere', 'v3xphere']}
61
+ sigMessage='Welcome to My Dapp!'
44
62
  validSeconds={600}
45
- sigMessage="hello world"
46
- expire={{ type: 'EXTEND', seconds: 3600 }}
47
- icon="http://sample.icon-url.com"
48
63
  onReceive={({ status, result }) => {
49
- if(status === 'SUCCESS') {
50
- // something to do after login (refresh page...)
51
- // status type: 'REQUEST' | 'ACCOUNT' | 'SUCCESS' | 'ERROR'
52
- // you can use result when status is 'SUCCESS'
64
+ if (status === 'SUCCESS') {
65
+ console.log('Login successful!', result);
53
66
  setResult(result as LoginResultType);
54
67
  }
55
68
  }}
56
69
  />
57
70
  </div>
58
71
  );
72
+ };
73
+ ```
74
+
75
+ ### Props
76
+
77
+ | Prop | Type | Required | Default | Description |
78
+ | --- | --- | --- | --- | --- |
79
+ | `dapp` | `string` | ✅ | - | dapp name |
80
+ | `url` | `string` | ✅ | - | dapp URL |
81
+ | `availableNetworks` | `('binance' \| 'ethereum' \| 'v2xphere' \| 'v3xphere')[]` | ✅ | - | supported networks |
82
+ | `sigMessage` | `string` | ✅ | - | signature message |
83
+ | `validSeconds` | `number` | ✅ | - | QR code valid time |
84
+ | `onReceive` | `(res) => void` | ❌ | - | login result callback |
85
+ | `expire` | `LoginExpireType` | ❌ | `{ type : 'NONE'}` | expiration settings |
86
+ | `icon` | `string` | ❌ | - | dapp icon URL |
87
+ | `processingMark` | `ProcessingMarkType` | ❌ | `{ type: 'DEFAULT' }` | processing display |
88
+ | `qrDomain` | `string` | ❌ | `https://zigap.io` | QR domain |
89
+
90
+ ### Supported Networks
91
+
92
+ - `'binance'` (bsc)
93
+ - `'ethereum'` (eth)
94
+ - `'v2xphere'` (xp)
95
+ - `'v3xphere'` (xpt)
96
+
97
+ ### Status Values
98
+
99
+ - `'SUCCESS'` - Login successful
100
+ - `'REQUEST'` - Request in progress
101
+ - `'ACCOUNT'` - Account selection in progress
102
+ - `'ERROR'` - Error occurred
103
+
104
+ ### LoginResultType
105
+
106
+ ```tsx
107
+ interface LoginResultType {
108
+ address: string;
109
+ network: string;
110
+ nickName: string;
111
+ token: string;
112
+ issuedDateTime: string;
113
+ expire: LoginExpireType;
114
+ isVerified: boolean;
59
115
  }
60
116
  ```
61
117
 
62
- <br />
118
+ ---
119
+
120
+ ## ✍️ SignatureQR
121
+
122
+ QR code component for message signing.
63
123
 
64
- ### 2. SignatureQR
124
+ ### Basic Usage
65
125
 
66
- ```ts
67
- import { SignatureQR } from 'zigap-utils';
68
- import type { SignatureResultType } from 'zigap-utils/SignatureQR/SignatureQR.types'
126
+ ```tsx
127
+ import { SignatureQR, SignatureResultType } from 'zigap-utils';
69
128
 
70
129
  const App = () => {
71
130
  const [result, setResult] = useState<SignatureResultType | null>(null);
72
131
 
73
- ...
74
-
75
132
  return (
76
133
  <div>
77
134
  <SignatureQR
78
- dapp='your Dapp Name'
79
- url='http://sample.yours.com'
80
- availableNetworks={['v2xphere, v3xphere']}
81
- isShowLogo={false}
82
- logoSize={25}
135
+ dapp='My Awesome Dapp'
136
+ url='https://myapp.com'
137
+ availableNetworks={['v2xphere', 'v3xphere']}
138
+ sigMessage='I agree to the terms and conditions'
83
139
  validSeconds={600}
84
- sigMessage="hello world"
85
- expire={{ type: 'EXTEND', seconds: 3600 }}
86
- icon="http://sample.icon-url.com"
87
140
  onReceive={({ status, result }) => {
88
- if(status === 'SUCCESS') {
89
- // it is same with LoginQR. But you can see another type in zigap signature history.
90
- // status type: 'REQUEST' | 'ACCOUNT' | 'SUCCESS' | 'ERROR'
91
- // you can use result when status is 'SUCCESS'
141
+ if (status === 'SUCCESS') {
142
+ console.log('Signature successful!', result);
92
143
  setResult(result as SignatureResultType);
93
144
  }
94
145
  }}
95
146
  />
96
- <div>
97
- )
147
+ </div>
148
+ );
149
+ };
150
+ ```
151
+
152
+ ### Props
153
+
154
+ | Prop | Type | Required | Default | Description |
155
+ | --- | --- | --- | --- | --- |
156
+ | `dapp` | `string` | ✅ | - | dapp name |
157
+ | `url` | `string` | ✅ | - | dapp URL |
158
+ | `availableNetworks` | `('binance' \| 'ethereum' \| 'v2xphere' \| 'v3xphere')[]` | ✅ | - | supported networks |
159
+ | `sigMessage` | `string` | ✅ | - | message to sign |
160
+ | `validSeconds` | `number` | ✅ | - | QR code valid time |
161
+ | `onReceive` | `(res) => void` | ❌ | - | signature result callback |
162
+ | `expire` | `SignatureLoginExpireType` | ❌ | `{ type : 'NONE'}` | expiration settings |
163
+ | `icon` | `string` | ❌ | - | dapp icon URL |
164
+ | `processingMark` | `SignatureProcessingMarkType` | ❌ | `{ type: 'DEFAULT' }` | processing display |
165
+ | `qrDomain` | `string` | ❌ | `https://zigap.io` | QR domain |
166
+
167
+ ### Supported Networks
168
+
169
+ - `'binance'` (bsc)
170
+ - `'ethereum'` (eth)
171
+ - `'v2xphere'` (xp)
172
+ - `'v3xphere'` (xpt)
173
+
174
+ ### Status Values
175
+
176
+ - `'SUCCESS'` - Signature successful
177
+ - `'REQUEST'` - Request in progress
178
+ - `'ACCOUNT'` - Account selection in progress
179
+ - `'ERROR'` - Error occurred
180
+
181
+ ### SignatureResultType
182
+
183
+ ```tsx
184
+ interface SignatureResultType {
185
+ address: string;
186
+ network: string;
187
+ nickName: string;
188
+ token: string;
189
+ issuedDateTime: string;
190
+ expire: SignatureLoginExpireType;
191
+ isVerified: boolean;
98
192
  }
99
193
  ```
100
194
 
101
- <br />
195
+ ---
196
+
197
+ ## 💸 SendTransactionQR
102
198
 
103
- ### 3. SendTransactionQR
199
+ QR code component for transaction sending.
104
200
 
105
- ```ts
106
- import { SendTransactionQR } from 'zigap-utils';
107
- import type { SendTransactionResultType } from 'zigap-utils/SendTransactionQR/SendTransactionQR.types'
201
+ ### Basic Usage
202
+
203
+ ```tsx
204
+ import { SendTransactionQR, SendTransactionResultType } from 'zigap-utils';
108
205
 
109
206
  const App = () => {
110
207
  const [result, setResult] = useState<SendTransactionResultType | null>(null);
111
208
 
112
- ...
113
-
114
209
  return (
115
210
  <div>
116
211
  <SendTransactionQR
117
- dapp='your Dapp Name'
118
- url='http://sample.yours.com'
119
- availableNetworks={'v2xphere'} // It is string not array
120
- isShowLogo={false}
121
- logoSize={25}
212
+ dapp='My Awesome Dapp'
213
+ url='https://myapp.com'
214
+ availableNetworks='v2xphere'
122
215
  validSeconds={600}
123
- sigMessage="hello world"
124
- expire={{ type: 'EXTEND', seconds: 3600 }}
125
- icon="http://sample.icon-url.com"
126
216
  transaction={{
127
217
  type: 0,
128
218
  to: '0x1234567890123456789012345678901234567890',
129
- value: '1000000000000000000',
219
+ value: '1000000000000000000', // 1 XP
130
220
  gasLimit: '21000',
131
221
  gasPrice: '1000000000',
132
222
  }}
133
223
  onReceive={({ status, result }) => {
134
- if(status === 'SUCCESS') {
135
- // status type: 'REQUEST' | 'ACCOUNT' | 'SUCCESS' | 'ERROR'
136
- // you can use result when status is 'SUCCESS'
224
+ if (status === 'SUCCESS') {
225
+ console.log('Transaction Complete!', result);
137
226
  setResult(result as SendTransactionResultType);
138
227
  }
139
228
  }}
140
229
  />
141
- <div>
142
- )
143
- }
230
+ </div>
231
+ );
232
+ };
144
233
  ```
145
234
 
146
- <br />
147
-
148
- ### 4. useZigap Hook
235
+ ### Props
236
+
237
+ | Prop | Type | Required | Default | Description |
238
+ | --- | --- | --- | --- | --- |
239
+ | `dapp` | `string` | ✅ | - | dapp name |
240
+ | `url` | `string` | ✅ | - | dapp URL |
241
+ | `availableNetworks` | `'binance' \| 'ethereum' \| 'v2xphere' \| 'v3xphere'` | ✅ | - | supported network (single value) |
242
+ | `validSeconds` | `number` | ✅ | - | QR code valid time |
243
+ | `transaction` | `TransactionType` | ✅ | - | transaction configuration |
244
+ | `onReceive` | `(res) => void` | ❌ | - | transaction result callback |
245
+ | `icon` | `string` | ❌ | - | dapp icon URL |
246
+ | `processingMark` | `ProcessingMarkType` | ❌ | `{ type: 'DEFAULT' }` | processing display |
247
+ | `qrDomain` | `string` | ❌ | `https://zigap.io` | QR domain |
248
+
249
+ ### Supported Networks
250
+
251
+ - `'binance'` (bsc)
252
+ - `'ethereum'` (eth)
253
+ - `'v2xphere'` (xp)
254
+ - `'v3xphere'` (xpt)
255
+
256
+ ### TransactionType
257
+
258
+ ```tsx
259
+ // Type 0: Legacy (pre-EIP-2718)
260
+ interface TransactionType0 {
261
+ type: 0 | '0x0';
262
+ to: string;
263
+ data?: string;
264
+ value: string;
265
+ gasLimit: string;
266
+ gasPrice: string;
267
+ chainId?: number;
268
+ }
149
269
 
150
- useZigap is a hook that fetches the information of the logged-in user in the zigap app and provides a logout function.
270
+ // Type 1: EIP-2930 (access list)
271
+ interface TransactionType1 {
272
+ type: 1 | '0x1';
273
+ to: string;
274
+ data?: string;
275
+ value: string;
276
+ gasLimit: string;
277
+ gasPrice: string;
278
+ accessList?: AccessList;
279
+ chainId?: number;
280
+ }
151
281
 
152
- ```ts
153
- import { useZigap } from 'zigap-utils';
282
+ // Type 2: EIP-1559 (dynamic fees)
283
+ interface TransactionType2 {
284
+ type: 2 | '0x2';
285
+ to: string;
286
+ data?: string;
287
+ value: string;
288
+ gasLimit: string;
289
+ maxFeePerGas: string;
290
+ maxPriorityFeePerGas: string;
291
+ chainId?: number;
292
+ }
154
293
 
155
- const Component = () => {
156
- const { userInfo, logout, isWindowLoaded } = useZigap();
294
+ type TransactionType = TransactionType0 | TransactionType1 | TransactionType2;
295
+ ```
157
296
 
158
- const handleLogout = () => {
159
- if(isWindowLoaded) {
160
- logout();
161
- window.location.reload();
162
- }
163
- }
297
+ ### SendTransactionResultType
164
298
 
165
- return (
166
- <div>
167
- <p>Address: {userInfo.address}</p>
168
- <p>Network: {userInfo.network}</p>
169
- <p>Nickname: {userInfo.nickName}</p>
170
- <p>Token: {userInfo.token}</p>
171
- <p>Issued DateTime: {userInfo.issuedDateTime}</p>
172
- <p>Expire DateTime: {userInfo.expireDateTime}</p>
173
-
174
- <button onClick={handleLogout}> LOGOUT </button>
175
- </div>
176
- );
299
+ ```tsx
300
+ interface SendTransactionResultType {
301
+ txHash: string;
302
+ status: 0 | 1; // 0 : fail , 1 : success
303
+ error: string;
177
304
  }
178
305
  ```
179
306
 
180
- <br />
307
+ ### Status Values
308
+
309
+ - `'SUCCESS'` - Transaction successful
310
+ - `'REQUEST'` - Request in progress
311
+ - `'ERROR'` - Error occurred
181
312
 
182
313
  ---
183
314
 
184
- <br />
185
-
186
- ### `LoginQR` props
187
-
188
- | prop | type | description |
189
- | --- | --- | --- |
190
- | `dapp` | string | Name of the dapp to use |
191
- | `url` | string | The url of dapp to connect |
192
- | `availableNetworks` | string[] | 'binance' \| 'ethereum' \| 'v2xphere' \| 'v3xphere' |
193
- | `sigMessage` | string | Messages signed to verify the identity of the user |
194
- | `validSeconds` | number | QR code valid time(seconds) |
195
- | `onReceive` | (res) => void | Function called after login request |
196
- | `expire` | {type: "NONE / FIX / EXTEND", seconds: number} | time and type for user login to expire |
197
- | `icon` | string | Your dapp icon url to be displayed on zigap app |
198
- | `processingMark` | {type: "DEFAULT" / "CUSTOM" / "NONE", component: React.ReactNode} | How to show the QR image when it's being processed |
199
-
200
- <br>
201
-
202
- ### `SignatureQR` props
203
-
204
- | prop | type | description |
205
- | --- | --- | --- |
206
- | `dapp` | string | Name of the dapp to use |
207
- | `url` | string | The url of dapp to connect |
208
- | `availableNetworks` | string[] | 'binance' \| 'ethereum' \| 'v2xphere' \| 'v3xphere' |
209
- | `sigMessage` | string | Messages signed to verify the identity of the user |
210
- | `validSeconds` | number | QR code valid time(seconds) |
211
- | `onReceive` | (res) => void | Function called after signature request |
212
- | `expire` | {type: "NONE / FIX / EXTEND", seconds: number} | time and type for signature to expire |
213
- | `icon` | string | Your dapp icon url to be displayed on zigap app |
214
- | `processingMark` | {type: "DEFAULT" / "CUSTOM" / "NONE", component: React.ReactNode} | How to show the QR image when it's being processed |
215
-
216
- <br>
217
-
218
- ### `SendTransactionQR` props
219
-
220
- | prop | type | description |
221
- | --- | --- | --- |
222
- | `dapp` | string | Name of the dapp to use |
223
- | `url` | string | The url of dapp to connect |
224
- | `availableNetworks` | string | 'binance' \| 'ethereum' \| 'v2xphere' \| 'v3xphere' |
225
- | `validSeconds` | number | QR code valid time(seconds) |
226
- | `onReceive` | (res) => void | Function called after transaction request |
227
- | `expire` | {type: "NONE / FIX / EXTEND", seconds: number} | time and type for transaction to expire |
228
- | `icon` | string | Your dapp icon url to be displayed on zigap app |
229
- | `transaction` | object | Transaction details (type, to, value, gasLimit, gasPrice) |
230
- | `processingMark` | {type: "DEFAULT" / "CUSTOM" / "NONE", component: React.ReactNode} | How to show the QR image when it's being processed |
231
-
232
- <br>
233
-
234
- The `onReceive` callback provides the following statuses:
235
-
236
- - `SUCCESS` : process was successful.
237
- - `REQUEST` : process has been requested and is in progress.
238
- - `ACCOUNT` : Account selection or preparation is in progress.
239
- - `ERROR` : An error occurred during payment.
240
-
241
- #### Processing Mark Options
242
-
243
- - `DEFAULT` : Displays a default "processing..." message during process.
244
- - `CUSTOM` : Allows you to pass a custom React component to display during processing.
245
- - `NONE` : No visual indicator is shown during processing.
246
-
247
- #### Example Usage of processingMark
248
-
249
- To use a custom component:
250
-
251
- ```js
252
- <SendTransactionQR
253
- ...
254
- processingMark={{
255
- type: 'CUSTOM',
256
- component: <div>Loading your payment...</div>,
257
- }}
258
- />
315
+ ## 🎨 Common Style Props
316
+
317
+ Common style options available for all QR components.
318
+
319
+ | Prop | Type | Default | Description |
320
+ | ------------ | --------------- | ------- | ---------------------------- |
321
+ | `size` | `number` | `128` | QR code canvas size |
322
+ | `bgColor` | `string` | `#fff` | background color |
323
+ | `fgColor` | `string` | `#000` | foreground color |
324
+ | `style` | `CSSProperties` | - | custom CSS style |
325
+ | `isShowLogo` | `boolean` | `false` | show Zigap logo in QR center |
326
+ | `logoSize` | `number` | `30` | logo size |
327
+
328
+ ### Example
329
+
330
+ ```tsx
331
+ <LoginQR
332
+ // ... other props
333
+ size={200}
334
+ bgColor='#ffffff'
335
+ fgColor='#000000'
336
+ isShowLogo={true}
337
+ logoSize={40}
338
+ style={{ borderRadius: '8px' }}
339
+ />
259
340
  ```
260
341
 
261
- <br>
342
+ ---
343
+
344
+ ## ⚙️ Processing Mark Options
345
+
346
+ Configure how to display during processing.
347
+
348
+ ### Options
349
+
350
+ - `'DEFAULT'` - Shows default "processing..." message
351
+ - `'CUSTOM'` - Allows custom React component
352
+ - `'NONE'` - No visual indicator
353
+
354
+ ### Custom Component Example
355
+
356
+ ```tsx
357
+ <SendTransactionQR
358
+ // ... other props
359
+ processingMark={{
360
+ type: 'CUSTOM',
361
+ component: (
362
+ <div
363
+ style={{
364
+ display: 'flex',
365
+ alignItems: 'center',
366
+ gap: '8px',
367
+ }}
368
+ >
369
+ <div className='spinner'></div>
370
+ <span>Processing payment...</span>
371
+ </div>
372
+ ),
373
+ }}
374
+ />
375
+ ```
376
+
377
+ ---
378
+
379
+ ## 📝 Expire Configuration
380
+
381
+ Configure expiration time and type.
382
+
383
+ ```tsx
384
+ // No expiration
385
+ expire={{ type: 'NONE' }}
386
+
387
+ // Fixed expiration time
388
+ expire={{ type: 'FIX', seconds: 3600 }}
389
+
390
+ // Extendable expiration time
391
+ expire={{ type: 'EXTEND', seconds: 3600 }}
392
+ ```
393
+
394
+ ---
395
+
396
+ ## 📄 License
397
+
398
+ ISC License
399
+
400
+ ---
262
401
 
263
- ### `CommonStyle` props (optional)
402
+ <div align="center">
264
403
 
265
- | prop | type | default value | description |
266
- | ------------ | ------------- | ------------- | --------------------------------------- |
267
- | `size` | number | 128 | canvas width |
268
- | `bgColor` | string | #fff | background color |
269
- | `fgColor` | string | #000 | foreground color |
270
- | `style` | CSSProperties | | custom css style |
271
- | `isShowLogo` | boolean | false | Zigap logo in the middle of the QR code |
272
- | `logoSize` | number | 30 | logo width & height |
404
+ **Made with by Seoul Labs**
273
405
 
274
- ## License
406
+ [📖 Documentation](https://seoul-labs.gitbook.io/zigap-utils)
275
407
 
276
- ISC
408
+ </div>
@@ -45,7 +45,7 @@ export type ProcessingMarkType = {
45
45
  };
46
46
  export type LoginQRProps = {
47
47
  qrDomain?: string;
48
- availableNetworks: string[];
48
+ availableNetworks: ('binance' | 'ethereum' | 'v2xphere' | 'v3xphere')[];
49
49
  dapp: string;
50
50
  url: string;
51
51
  sigMessage: string;
@@ -40,7 +40,7 @@ export type AccessList = {
40
40
  export type TransactionType = TransactionType0 | TransactionType1 | TransactionType2;
41
41
  export type SendTransactionResultType = {
42
42
  txHash: string;
43
- status: string;
43
+ status: 0 | 1;
44
44
  error: string;
45
45
  };
46
46
  export type SendTransactionQRProps = {
@@ -45,7 +45,7 @@ export type SignatureProcessingMarkType = {
45
45
  };
46
46
  export type SignatureQRProps = {
47
47
  qrDomain?: string;
48
- availableNetworks: string[];
48
+ availableNetworks: ('binance' | 'ethereum' | 'v2xphere' | 'v3xphere')[];
49
49
  dapp: string;
50
50
  url: string;
51
51
  sigMessage: string;