zigap-utils 0.0.2 → 0.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,11 +1,11 @@
1
1
  # zigap-utils
2
2
 
3
- It is a library that collects utils that help communicate between dapp and zigap.
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
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```
8
- npm i zigap-utils --save -D
8
+ npm i zigap-utils
9
9
  ```
10
10
 
11
11
  ## Usage
@@ -19,11 +19,18 @@ const App = () => {
19
19
  return (
20
20
  <div>
21
21
  <LoginQR
22
- validTime={10}
22
+ dapp='yourDappName'
23
+ url='http://sample.yours.com'
24
+ availableNetworks={['xphere']}
25
+ isShowLogo={false}
26
+ logoSize={25}
27
+ validSeconds={600}
23
28
  sigMessage="hello world"
24
- onReceive={({ isSuccess, address })=>{
29
+ expire={{ type: 'EXTEND', seconds: 3600 }}
30
+ icon="http://sample.icon-url.com"
31
+ onReceive={({ isSuccess }) => {
25
32
  if(isSuccess) {
26
- // something to do after login
33
+ // something to do after login (refresh page...)
27
34
  }
28
35
  }}
29
36
  />
@@ -38,26 +45,73 @@ const App = () => {
38
45
 
39
46
  ### `LoginQR` props
40
47
 
41
- | prop | required | type | default value | description |
42
- | ------------ | :------: | --------------- | ------------- | -------------------------------------------------- |
43
- | `sigMessage` | true | string | | Messages signed to verify the identity of the user |
44
- | `validTime` | true | number | | QR code valid time(minutes) |
45
- | `onReceive` | true | (value) => void | | Function called after login request |
46
- | `size` | false | number | 128 | canvas width |
47
- | `bgColor` | false | string | #fff | background color |
48
- | `fgColor` | false | string | #000 | foreground color |
49
- | `style` | false | CSSProperties | | custom css style |
48
+ | prop | type | description |
49
+ | --- | --- | --- |
50
+ | `dapp` | string | Name of the dapp to use |
51
+ | `url` | string | The url of dapp to connect |
52
+ | `availableNetworks` | string[] | List of connectable networks in dapp |
53
+ | `sigMessage` | string | Messages signed to verify the identity of the user |
54
+ | `validSeconds` | number | QR code valid time(minutes) |
55
+ | `onReceive` | (value) => void | Function called after login request |
56
+ | `expire` | {type: "NONE / FIX / EXTEND", seconds: number} | time and type for user login to expire |
57
+ | `icon` | string | Your dapp icon url to be displayed on zigap app |
50
58
 
51
59
  <br>
52
60
 
53
61
  ### `AddressProvideQR` props
54
62
 
55
- | prop | required | type | default value | description |
56
- | ------------ | :------: | --------------- | ------------- | -------------------------------------------------- |
57
- | `sigMessage` | true | string | | Messages signed to verify the identity of the user |
58
- | `validTime` | true | number | | QR code valid time(minutes) |
59
- | `onReceive` | true | (value) => void | | Function called after login request |
60
- | `size` | false | number | 128 | canvas width |
61
- | `bgColor` | false | string | #fff | background color |
62
- | `fgColor` | false | string | #000 | foreground color |
63
- | `style` | false | CSSProperties | | custom css style |
63
+ | prop type | type | description |
64
+ | ------------------- | --------------- | ----------------------------------------------- |
65
+ | `dapp` | string | Name of the dapp to use |
66
+ | `url` | string | The url of dapp to connect |
67
+ | `availableNetworks` | string[] | List of connectable networks in dapp |
68
+ | `validSeconds` | number | QR code valid time(seconds) |
69
+ | `onReceive` | (value) => void | Function called after login request |
70
+ | `icon` | string | Your dapp icon url to be displayed on zigap app |
71
+
72
+ <br>
73
+
74
+ ### `CommonStyle` props (optional)
75
+
76
+ | prop | type | default value | description |
77
+ | ------------ | ------------- | ------------- | --------------------------------------- |
78
+ | `size` | number | 128 | canvas width |
79
+ | `bgColor` | string | #fff | background color |
80
+ | `fgColor` | string | #000 | foreground color |
81
+ | `style` | CSSProperties | | custom css style |
82
+ | `isShowLogo` | boolean | false | Zigap logo in the middle of the QR code |
83
+ | `logoSize` | number | 30 | logo width & height |
84
+
85
+ <br>
86
+
87
+ ### `useZigap`
88
+
89
+ useZigap is a hook that fetches the information of the logged-in user in the zigap app and provides a logout function.
90
+
91
+ ```ts
92
+ import { useZigap } from 'zigap-utils';
93
+
94
+ ...
95
+
96
+ const Component = () => {
97
+ const { userInfo, logout } = useZigap();
98
+
99
+ const handleLogout = () => {
100
+ logout();
101
+ window.location.reload();
102
+ }
103
+
104
+ return (
105
+ <div>
106
+ <p>Address: {userInfo.address}</p>
107
+ <p>Network: {userInfo.network}</p>
108
+ <p>Nickname: {userInfo.nickName}</p>
109
+ <p>Token: {userInfo.token}</p>
110
+ <p>Issued DateTime: {userInfo.issuedDateTime}</p>
111
+ <p>Expire DateTime: {userInfo.expireDateTime}</p>
112
+
113
+ <button onClick={handleLogout}> LOGOUT </button>
114
+ </div>
115
+ );
116
+ }
117
+ ```
@@ -1,4 +1,4 @@
1
1
  import { AddressProvideQRProps } from './AddressProvideQR.types';
2
2
 
3
- declare const AddressProvideQR: ({ validTime, onReceive, ...props }: AddressProvideQRProps) => import("react/jsx-runtime").JSX.Element;
3
+ declare const AddressProvideQR: ({ availableNetworks, dapp, url, validSeconds, onReceive, isShowLogo, logoSize, icon, ...props }: AddressProvideQRProps) => import("react/jsx-runtime").JSX.Element;
4
4
  export default AddressProvideQR;
@@ -1,14 +1,18 @@
1
- import { CSSProperties } from 'react';
1
+ import { CommonStyleType } from 'src/components/LoginQR/LoginQR.types';
2
2
 
3
3
  export type AddressProvideResultType = {
4
4
  isSuccess: boolean;
5
5
  address?: string;
6
+ network?: string;
7
+ nickName?: string;
6
8
  };
7
9
  export type AddressProvideQRProps = {
8
- validTime: number;
9
- onReceive: (result: AddressProvideResultType) => void;
10
- size?: number;
11
- bgColor?: string;
12
- fgColor?: string;
13
- style?: CSSProperties;
14
- };
10
+ availableNetworks: string[];
11
+ dapp: string;
12
+ url: string;
13
+ validSeconds: number;
14
+ icon?: string;
15
+ onReceive: (res: {
16
+ isSuccess: boolean;
17
+ }) => void;
18
+ } & CommonStyleType;
@@ -1,4 +1,4 @@
1
1
  import { LoginQRProps } from './LoginQR.types';
2
2
 
3
- declare const LoginQR: ({ sigMessage, validTime, onReceive, ...props }: LoginQRProps) => import("react/jsx-runtime").JSX.Element;
3
+ declare const LoginQR: ({ availableNetworks, dapp, url, sigMessage, onReceive, validSeconds, isShowLogo, logoSize, expire, icon, ...props }: LoginQRProps) => import("react/jsx-runtime").JSX.Element;
4
4
  export default LoginQR;
@@ -1,15 +1,48 @@
1
1
  import { CSSProperties } from 'react';
2
2
 
3
- export type LoginResultType = {
4
- isSuccess: boolean;
5
- address?: string;
6
- };
7
- export type LoginQRProps = {
8
- sigMessage: string;
9
- validTime: number;
10
- onReceive: (result: LoginResultType) => void;
3
+ export type CommonStyleType = {
11
4
  size?: number;
12
5
  bgColor?: string;
13
6
  fgColor?: string;
14
7
  style?: CSSProperties;
8
+ isShowLogo?: boolean;
9
+ logoSize?: number;
10
+ };
11
+ export type PayloadType = {
12
+ publicKey: string;
13
+ message: string;
14
+ };
15
+ export type AccountType = {
16
+ address: string;
17
+ network: string;
18
+ nickName: string;
15
19
  };
20
+ export type NoneLoginExpire = {
21
+ type: 'NONE';
22
+ seconds?: never;
23
+ };
24
+ export type FixedOrExtensionLoginExpire = {
25
+ type: 'FIX' | 'EXTEND';
26
+ seconds: number;
27
+ };
28
+ export type LoginExpireType = FixedOrExtensionLoginExpire | NoneLoginExpire;
29
+ export type LoginResultType = {
30
+ address: string;
31
+ network: string;
32
+ nickName: string;
33
+ token: string;
34
+ issuedDateTime: string;
35
+ expire: LoginExpireType;
36
+ };
37
+ export type LoginQRProps = {
38
+ availableNetworks: string[];
39
+ dapp: string;
40
+ url: string;
41
+ sigMessage: string;
42
+ validSeconds: number;
43
+ onReceive?: (res: {
44
+ isSuccess: boolean;
45
+ }) => void;
46
+ expire: LoginExpireType;
47
+ icon?: string;
48
+ } & CommonStyleType;
@@ -0,0 +1 @@
1
+ export { default as useZigap } from './useZigap';
@@ -0,0 +1,14 @@
1
+ export declare const LOGIN_RES_KEY = "userInfo";
2
+ export declare const TIME_FORMAT = "YYYY-MM-DD HH:mm:ss";
3
+ declare const useZigap: () => {
4
+ userInfo: {
5
+ address: string | undefined;
6
+ network: string | undefined;
7
+ nickName: string | undefined;
8
+ token: string | undefined;
9
+ issuedDateTime: string | undefined;
10
+ expireDateTime: string | undefined;
11
+ };
12
+ logout: () => void;
13
+ };
14
+ export default useZigap;
package/dist/index.d.ts CHANGED
@@ -1 +1,4 @@
1
1
  export * from './components';
2
+ export * from './xphere';
3
+ export * from './zigap';
4
+ export * from './hooks';