@nexus-cross/crossx-sdk-react 1.0.2-beta.1 → 1.0.3
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/dist/hooks/useAuth.d.ts +1 -0
- package/dist/hooks/useAuth.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +75 -61
- package/package.json +2 -2
package/dist/hooks/useAuth.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export declare function useAuth(): {
|
|
|
10
10
|
isLoading: boolean;
|
|
11
11
|
error: string | null;
|
|
12
12
|
signIn: () => Promise<AuthResult>;
|
|
13
|
+
signInWithCreate: () => Promise<import('@nexus-cross/crossx-sdk-core').SignInWithCreateResult>;
|
|
13
14
|
signOut: () => Promise<void>;
|
|
14
15
|
};
|
|
15
16
|
//# sourceMappingURL=useAuth.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../../src/hooks/useAuth.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAE/D;;;;GAIG;AACH,wBAAgB,OAAO
|
|
1
|
+
{"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../../src/hooks/useAuth.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAE/D;;;;GAIG;AACH,wBAAgB,OAAO;;;;;;;EAoFtB"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("react/jsx-runtime"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("react/jsx-runtime"),r=require("react"),h=require("@nexus-cross/crossx-sdk-core"),w=r.createContext({sdk:null,isInitialized:!1,isAuthenticated:!1,walletAddress:null});function C(e){let i={isAuthenticated:e.isAuthenticated(),walletAddress:e.currentAddress};const n=new Set,a=e.on("authChanged",s=>{i={isAuthenticated:s.isAuthenticated,walletAddress:s.address},n.forEach(c=>c())}),u=e.on("addressChanged",s=>{i={...i,walletAddress:s.address},n.forEach(c=>c())});return{subscribe:s=>(n.add(s),()=>{n.delete(s),n.size===0&&(a(),u())}),getSnapshot:()=>i}}function y({config:e,children:i}){const[n]=r.useState(()=>h.createCROSSxSDK(e)),[a,u]=r.useState(!1),s=r.useMemo(()=>C(n),[n]),{isAuthenticated:c,walletAddress:d}=r.useSyncExternalStore(s.subscribe,s.getSnapshot);r.useEffect(()=>{(async()=>{try{await n.initialize(),u(!0)}catch(o){console.error("CROSSx SDK 초기화 실패:",o)}})()},[n]);const l=r.useMemo(()=>({sdk:n,isInitialized:a,isAuthenticated:c,walletAddress:d}),[n,a,c,d]);return g.jsx(w.Provider,{value:l,children:i})}function f(){const e=r.useContext(w);if(!e)throw new Error("useCROSSx must be used within CROSSxProvider");return e}function x(){const{sdk:e,isAuthenticated:i}=f(),[n,a]=r.useState(!1),[u,s]=r.useState(null),c=r.useCallback(async()=>{if(!e)throw new Error("SDK가 초기화되지 않았습니다");a(!0),s(null);try{const t=await e.signIn();return t.success||s(t.error||"로그인 실패"),t}catch(t){const o=t instanceof Error?t.message:"로그인 실패";throw s(o),t}finally{a(!1)}},[e]),d=r.useCallback(async()=>{if(!e)throw new Error("SDK가 초기화되지 않았습니다");a(!0),s(null);try{const t=await e.signInWithCreate();return t.success||s(t.error||"로그인 실패"),t}catch(t){const o=t instanceof Error?t.message:"로그인 실패";throw s(o),t}finally{a(!1)}},[e]),l=r.useCallback(async()=>{if(!e)throw new Error("SDK가 초기화되지 않았습니다");a(!0),s(null);try{await e.signOut()}catch(t){const o=t instanceof Error?t.message:"로그아웃 실패";throw s(o),t}finally{a(!1)}},[e]);return{isAuthenticated:i,isLoading:n,error:u,signIn:c,signInWithCreate:d,signOut:l}}function A(){const{sdk:e,walletAddress:i}=f(),[n,a]=r.useState(!1),[u,s]=r.useState(null),c=r.useCallback(async(l,t)=>{if(!e)throw new Error("SDK가 초기화되지 않았습니다");a(!0),s(null);try{return await e.signMessage(l,t)}catch(o){const S=o instanceof Error?o.message:"서명 실패";throw s(S),o}finally{a(!1)}},[e]),d=r.useCallback(async(l,t)=>{if(!e)throw new Error("SDK가 초기화되지 않았습니다");a(!0),s(null);try{return await e.sendTransaction(l,t)}catch(o){const S=o instanceof Error?o.message:"트랜잭션 전송 실패";throw s(S),o}finally{a(!1)}},[e]);return{address:i,isLoading:n,error:u,signMessage:c,sendTransaction:d}}Object.defineProperty(exports,"ChainId",{enumerable:!0,get:()=>h.ChainId});exports.CROSSxProvider=y;exports.useAuth=x;exports.useCROSSx=f;exports.useWallet=A;
|
package/dist/index.js
CHANGED
|
@@ -1,123 +1,137 @@
|
|
|
1
1
|
import { jsx as m } from "react/jsx-runtime";
|
|
2
|
-
import { createContext as
|
|
2
|
+
import { createContext as y, useState as d, useMemo as w, useSyncExternalStore as A, useEffect as E, useContext as x, useCallback as f } from "react";
|
|
3
3
|
import { createCROSSxSDK as C } from "@nexus-cross/crossx-sdk-core";
|
|
4
4
|
import { ChainId as v } from "@nexus-cross/crossx-sdk-core";
|
|
5
|
-
const
|
|
5
|
+
const S = y({
|
|
6
6
|
sdk: null,
|
|
7
7
|
isInitialized: !1,
|
|
8
8
|
isAuthenticated: !1,
|
|
9
9
|
walletAddress: null
|
|
10
10
|
});
|
|
11
|
-
function
|
|
12
|
-
let
|
|
11
|
+
function I(t) {
|
|
12
|
+
let o = {
|
|
13
13
|
isAuthenticated: t.isAuthenticated(),
|
|
14
14
|
walletAddress: t.currentAddress
|
|
15
15
|
};
|
|
16
|
-
const r = /* @__PURE__ */ new Set(), n = t.on("authChanged", (
|
|
17
|
-
|
|
18
|
-
isAuthenticated:
|
|
19
|
-
walletAddress:
|
|
20
|
-
}, r.forEach((
|
|
21
|
-
}),
|
|
22
|
-
|
|
16
|
+
const r = /* @__PURE__ */ new Set(), n = t.on("authChanged", (s) => {
|
|
17
|
+
o = {
|
|
18
|
+
isAuthenticated: s.isAuthenticated,
|
|
19
|
+
walletAddress: s.address
|
|
20
|
+
}, r.forEach((i) => i());
|
|
21
|
+
}), c = t.on("addressChanged", (s) => {
|
|
22
|
+
o = { ...o, walletAddress: s.address }, r.forEach((i) => i());
|
|
23
23
|
});
|
|
24
24
|
return {
|
|
25
|
-
subscribe: (
|
|
26
|
-
r.delete(
|
|
25
|
+
subscribe: (s) => (r.add(s), () => {
|
|
26
|
+
r.delete(s), r.size === 0 && (n(), c());
|
|
27
27
|
}),
|
|
28
|
-
getSnapshot: () =>
|
|
28
|
+
getSnapshot: () => o
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
|
-
function
|
|
32
|
-
const [r] = d(() => C(t)), [n,
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
function O({ config: t, children: o }) {
|
|
32
|
+
const [r] = d(() => C(t)), [n, c] = d(!1), s = w(() => I(r), [r]), { isAuthenticated: i, walletAddress: l } = A(
|
|
33
|
+
s.subscribe,
|
|
34
|
+
s.getSnapshot
|
|
35
35
|
);
|
|
36
|
-
|
|
36
|
+
E(() => {
|
|
37
37
|
(async () => {
|
|
38
38
|
try {
|
|
39
|
-
await r.initialize(),
|
|
40
|
-
} catch (
|
|
41
|
-
console.error("CROSSx SDK 초기화 실패:",
|
|
39
|
+
await r.initialize(), c(!0);
|
|
40
|
+
} catch (a) {
|
|
41
|
+
console.error("CROSSx SDK 초기화 실패:", a);
|
|
42
42
|
}
|
|
43
43
|
})();
|
|
44
44
|
}, [r]);
|
|
45
|
-
const
|
|
45
|
+
const u = w(
|
|
46
46
|
() => ({
|
|
47
47
|
sdk: r,
|
|
48
48
|
isInitialized: n,
|
|
49
|
-
isAuthenticated:
|
|
49
|
+
isAuthenticated: i,
|
|
50
50
|
walletAddress: l
|
|
51
51
|
}),
|
|
52
|
-
[r, n,
|
|
52
|
+
[r, n, i, l]
|
|
53
53
|
);
|
|
54
|
-
return /* @__PURE__ */ m(
|
|
54
|
+
return /* @__PURE__ */ m(S.Provider, { value: u, children: o });
|
|
55
55
|
}
|
|
56
56
|
function g() {
|
|
57
|
-
const t =
|
|
57
|
+
const t = x(S);
|
|
58
58
|
if (!t)
|
|
59
59
|
throw new Error("useCROSSx must be used within CROSSxProvider");
|
|
60
60
|
return t;
|
|
61
61
|
}
|
|
62
|
-
function
|
|
63
|
-
const { sdk: t, isAuthenticated:
|
|
62
|
+
function p() {
|
|
63
|
+
const { sdk: t, isAuthenticated: o } = g(), [r, n] = d(!1), [c, s] = d(null), i = f(async () => {
|
|
64
64
|
if (!t)
|
|
65
65
|
throw new Error("SDK가 초기화되지 않았습니다");
|
|
66
|
-
n(!0),
|
|
66
|
+
n(!0), s(null);
|
|
67
67
|
try {
|
|
68
|
-
const
|
|
69
|
-
return
|
|
70
|
-
} catch (
|
|
71
|
-
const
|
|
72
|
-
throw
|
|
68
|
+
const e = await t.signIn();
|
|
69
|
+
return e.success || s(e.error || "로그인 실패"), e;
|
|
70
|
+
} catch (e) {
|
|
71
|
+
const a = e instanceof Error ? e.message : "로그인 실패";
|
|
72
|
+
throw s(a), e;
|
|
73
73
|
} finally {
|
|
74
74
|
n(!1);
|
|
75
75
|
}
|
|
76
76
|
}, [t]), l = f(async () => {
|
|
77
77
|
if (!t)
|
|
78
78
|
throw new Error("SDK가 초기화되지 않았습니다");
|
|
79
|
-
n(!0),
|
|
79
|
+
n(!0), s(null);
|
|
80
|
+
try {
|
|
81
|
+
const e = await t.signInWithCreate();
|
|
82
|
+
return e.success || s(e.error || "로그인 실패"), e;
|
|
83
|
+
} catch (e) {
|
|
84
|
+
const a = e instanceof Error ? e.message : "로그인 실패";
|
|
85
|
+
throw s(a), e;
|
|
86
|
+
} finally {
|
|
87
|
+
n(!1);
|
|
88
|
+
}
|
|
89
|
+
}, [t]), u = f(async () => {
|
|
90
|
+
if (!t)
|
|
91
|
+
throw new Error("SDK가 초기화되지 않았습니다");
|
|
92
|
+
n(!0), s(null);
|
|
80
93
|
try {
|
|
81
94
|
await t.signOut();
|
|
82
|
-
} catch (
|
|
83
|
-
const
|
|
84
|
-
throw
|
|
95
|
+
} catch (e) {
|
|
96
|
+
const a = e instanceof Error ? e.message : "로그아웃 실패";
|
|
97
|
+
throw s(a), e;
|
|
85
98
|
} finally {
|
|
86
99
|
n(!1);
|
|
87
100
|
}
|
|
88
101
|
}, [t]);
|
|
89
102
|
return {
|
|
90
|
-
isAuthenticated:
|
|
103
|
+
isAuthenticated: o,
|
|
91
104
|
isLoading: r,
|
|
92
|
-
error:
|
|
93
|
-
signIn:
|
|
94
|
-
|
|
105
|
+
error: c,
|
|
106
|
+
signIn: i,
|
|
107
|
+
signInWithCreate: l,
|
|
108
|
+
signOut: u
|
|
95
109
|
};
|
|
96
110
|
}
|
|
97
111
|
function R() {
|
|
98
|
-
const { sdk: t, walletAddress:
|
|
99
|
-
async (
|
|
112
|
+
const { sdk: t, walletAddress: o } = g(), [r, n] = d(!1), [c, s] = d(null), i = f(
|
|
113
|
+
async (u, e) => {
|
|
100
114
|
if (!t) throw new Error("SDK가 초기화되지 않았습니다");
|
|
101
|
-
n(!0),
|
|
115
|
+
n(!0), s(null);
|
|
102
116
|
try {
|
|
103
|
-
return await t.signMessage(
|
|
104
|
-
} catch (
|
|
105
|
-
const h =
|
|
106
|
-
throw
|
|
117
|
+
return await t.signMessage(u, e);
|
|
118
|
+
} catch (a) {
|
|
119
|
+
const h = a instanceof Error ? a.message : "서명 실패";
|
|
120
|
+
throw s(h), a;
|
|
107
121
|
} finally {
|
|
108
122
|
n(!1);
|
|
109
123
|
}
|
|
110
124
|
},
|
|
111
125
|
[t]
|
|
112
126
|
), l = f(
|
|
113
|
-
async (
|
|
127
|
+
async (u, e) => {
|
|
114
128
|
if (!t) throw new Error("SDK가 초기화되지 않았습니다");
|
|
115
|
-
n(!0),
|
|
129
|
+
n(!0), s(null);
|
|
116
130
|
try {
|
|
117
|
-
return await t.sendTransaction(
|
|
118
|
-
} catch (
|
|
119
|
-
const h =
|
|
120
|
-
throw
|
|
131
|
+
return await t.sendTransaction(u, e);
|
|
132
|
+
} catch (a) {
|
|
133
|
+
const h = a instanceof Error ? a.message : "트랜잭션 전송 실패";
|
|
134
|
+
throw s(h), a;
|
|
121
135
|
} finally {
|
|
122
136
|
n(!1);
|
|
123
137
|
}
|
|
@@ -125,17 +139,17 @@ function R() {
|
|
|
125
139
|
[t]
|
|
126
140
|
);
|
|
127
141
|
return {
|
|
128
|
-
address:
|
|
142
|
+
address: o,
|
|
129
143
|
isLoading: r,
|
|
130
|
-
error:
|
|
131
|
-
signMessage:
|
|
144
|
+
error: c,
|
|
145
|
+
signMessage: i,
|
|
132
146
|
sendTransaction: l
|
|
133
147
|
};
|
|
134
148
|
}
|
|
135
149
|
export {
|
|
136
|
-
|
|
150
|
+
O as CROSSxProvider,
|
|
137
151
|
v as ChainId,
|
|
138
|
-
|
|
152
|
+
p as useAuth,
|
|
139
153
|
g as useCROSSx,
|
|
140
154
|
R as useWallet
|
|
141
155
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexus-cross/crossx-sdk-react",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "CROSSx React SDK - React Hooks and Components for Embedded Wallet",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"react": "^18.0.0"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@nexus-cross/crossx-sdk-core": "1.0.
|
|
36
|
+
"@nexus-cross/crossx-sdk-core": "1.0.3"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/react": "^18.2.48",
|