@nexus-cross/crossx-sdk-react 1.0.5 → 1.0.7
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/CROSSxProvider.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +90 -74
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CROSSxProvider.d.ts","sourceRoot":"","sources":["../src/CROSSxProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4E,MAAM,OAAO,CAAC;AAEjG,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAEzE,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,SAAS,GAAG,IAAI,CAAC;IACtB,aAAa,EAAE,OAAO,CAAC;IACvB,eAAe,EAAE,OAAO,CAAC;IACzB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAED,eAAO,MAAM,aAAa,mCAKxB,CAAC;AAEH,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,SAAS,CAAC;IAClB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;
|
|
1
|
+
{"version":3,"file":"CROSSxProvider.d.ts","sourceRoot":"","sources":["../src/CROSSxProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4E,MAAM,OAAO,CAAC;AAEjG,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAEzE,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,SAAS,GAAG,IAAI,CAAC;IACtB,aAAa,EAAE,OAAO,CAAC;IACvB,eAAe,EAAE,OAAO,CAAC;IACzB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAED,eAAO,MAAM,aAAa,mCAKxB,CAAC;AAEH,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,SAAS,CAAC;IAClB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAsED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,mBAAmB,2CAiDvE"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("react/jsx-runtime"),o=require("react"),f=require("@nexus-cross/crossx-sdk-core"),g=o.createContext({sdk:null,isInitialized:!1,isAuthenticated:!1,walletAddress:null});let A=0;function C(t){const c=++A;console.log(`[AuthStore#${c}] created, initial:`,{isAuthenticated:t.isAuthenticated(),walletAddress:t.currentAddress});let a={isAuthenticated:t.isAuthenticated(),walletAddress:t.currentAddress};const s=new Set;function u(){console.log(`[AuthStore#${c}] notify → listeners=${s.size}, snapshot=`,a),s.forEach(r=>r())}const n=t.on("authChanged",r=>{console.log(`[AuthStore#${c}] authChanged event:`,r),a={isAuthenticated:r.isAuthenticated,walletAddress:r.address},u()}),l=t.on("addressChanged",r=>{console.log(`[AuthStore#${c}] addressChanged event:`,r),a={...a,walletAddress:r.address},u()});return{subscribe:r=>(s.add(r),console.log(`[AuthStore#${c}] subscribe → listeners=${s.size}`),()=>{s.delete(r),console.log(`[AuthStore#${c}] unsubscribe → listeners=${s.size}`)}),getSnapshot:()=>a,destroy:()=>{console.log(`[AuthStore#${c}] destroy`),n(),l(),s.clear()}}}function y({config:t,children:c}){const[a]=o.useState(()=>f.createCROSSxSDK(t)),[s,u]=o.useState(!1),n=o.useMemo(()=>C(a),[a]),{isAuthenticated:l,walletAddress:r}=o.useSyncExternalStore(n.subscribe,n.getSnapshot);console.log("[CROSSxProvider] render:",{isInitialized:s,isAuthenticated:l,walletAddress:r}),o.useEffect(()=>{let e=!1;return console.log("[CROSSxProvider] useEffect mount"),(async()=>{try{await a.initialize(),console.log("[CROSSxProvider] sdk.initialize() done, cancelled=",e),e||u(!0)}catch(S){e||console.error("CROSSx SDK 초기화 실패:",S)}})(),()=>{console.log("[CROSSxProvider] useEffect cleanup"),e=!0}},[a]);const d=o.useMemo(()=>({sdk:a,isInitialized:s,isAuthenticated:l,walletAddress:r}),[a,s,l,r]);return w.jsx(g.Provider,{value:d,children:c})}function h(){const t=o.useContext(g);if(!t)throw new Error("useCROSSx must be used within CROSSxProvider");return t}function x(){const{sdk:t,isAuthenticated:c}=h(),[a,s]=o.useState(!1),[u,n]=o.useState(null),l=o.useCallback(async()=>{if(!t)throw new Error("SDK가 초기화되지 않았습니다");s(!0),n(null);try{const e=await t.signIn();return e.success||n(e.error||"로그인 실패"),e}catch(e){const i=e instanceof Error?e.message:"로그인 실패";throw n(i),e}finally{s(!1)}},[t]),r=o.useCallback(async()=>{if(!t)throw new Error("SDK가 초기화되지 않았습니다");s(!0),n(null);try{const e=await t.signInWithCreate();return e.success||n(e.error||"로그인 실패"),e}catch(e){const i=e instanceof Error?e.message:"로그인 실패";throw n(i),e}finally{s(!1)}},[t]),d=o.useCallback(async()=>{if(!t)throw new Error("SDK가 초기화되지 않았습니다");s(!0),n(null);try{await t.signOut()}catch(e){const i=e instanceof Error?e.message:"로그아웃 실패";throw n(i),e}finally{s(!1)}},[t]);return{isAuthenticated:c,isLoading:a,error:u,signIn:l,signInWithCreate:r,signOut:d}}function b(){const{sdk:t,walletAddress:c}=h(),[a,s]=o.useState(!1),[u,n]=o.useState(null),l=o.useCallback(async(d,e)=>{if(!t)throw new Error("SDK가 초기화되지 않았습니다");s(!0),n(null);try{return await t.signMessage(d,e)}catch(i){const S=i instanceof Error?i.message:"서명 실패";throw n(S),i}finally{s(!1)}},[t]),r=o.useCallback(async(d,e)=>{if(!t)throw new Error("SDK가 초기화되지 않았습니다");s(!0),n(null);try{return await t.sendTransaction(d,e)}catch(i){const S=i instanceof Error?i.message:"트랜잭션 전송 실패";throw n(S),i}finally{s(!1)}},[t]);return{address:c,isLoading:a,error:u,signMessage:l,sendTransaction:r}}Object.defineProperty(exports,"ChainId",{enumerable:!0,get:()=>f.ChainId});exports.CROSSxProvider=y;exports.useAuth=x;exports.useCROSSx=h;exports.useWallet=b;
|
package/dist/index.js
CHANGED
|
@@ -1,155 +1,171 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { createContext as y, useState as d, useMemo as
|
|
3
|
-
import { createCROSSxSDK as
|
|
4
|
-
import { ChainId as
|
|
5
|
-
const
|
|
1
|
+
import { jsx as A } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as y, useState as d, useMemo as S, useSyncExternalStore as C, useEffect as m, useContext as x, useCallback as f } from "react";
|
|
3
|
+
import { createCROSSxSDK as E } from "@nexus-cross/crossx-sdk-core";
|
|
4
|
+
import { ChainId as P } from "@nexus-cross/crossx-sdk-core";
|
|
5
|
+
const g = y({
|
|
6
6
|
sdk: null,
|
|
7
7
|
isInitialized: !1,
|
|
8
8
|
isAuthenticated: !1,
|
|
9
9
|
walletAddress: null
|
|
10
10
|
});
|
|
11
|
-
|
|
11
|
+
let I = 0;
|
|
12
|
+
function O(t) {
|
|
13
|
+
const i = ++I;
|
|
14
|
+
console.log(`[AuthStore#${i}] created, initial:`, {
|
|
15
|
+
isAuthenticated: t.isAuthenticated(),
|
|
16
|
+
walletAddress: t.currentAddress
|
|
17
|
+
});
|
|
12
18
|
let o = {
|
|
13
19
|
isAuthenticated: t.isAuthenticated(),
|
|
14
20
|
walletAddress: t.currentAddress
|
|
15
21
|
};
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
const s = /* @__PURE__ */ new Set();
|
|
23
|
+
function l() {
|
|
24
|
+
console.log(`[AuthStore#${i}] notify → listeners=${s.size}, snapshot=`, o), s.forEach((r) => r());
|
|
25
|
+
}
|
|
26
|
+
const n = t.on("authChanged", (r) => {
|
|
27
|
+
console.log(`[AuthStore#${i}] authChanged event:`, r), o = {
|
|
28
|
+
isAuthenticated: r.isAuthenticated,
|
|
29
|
+
walletAddress: r.address
|
|
30
|
+
}, l();
|
|
31
|
+
}), c = t.on("addressChanged", (r) => {
|
|
32
|
+
console.log(`[AuthStore#${i}] addressChanged event:`, r), o = { ...o, walletAddress: r.address }, l();
|
|
23
33
|
});
|
|
24
34
|
return {
|
|
25
|
-
subscribe: (
|
|
26
|
-
|
|
35
|
+
subscribe: (r) => (s.add(r), console.log(`[AuthStore#${i}] subscribe → listeners=${s.size}`), () => {
|
|
36
|
+
s.delete(r), console.log(`[AuthStore#${i}] unsubscribe → listeners=${s.size}`);
|
|
27
37
|
}),
|
|
28
|
-
getSnapshot: () => o
|
|
38
|
+
getSnapshot: () => o,
|
|
39
|
+
destroy: () => {
|
|
40
|
+
console.log(`[AuthStore#${i}] destroy`), n(), c(), s.clear();
|
|
41
|
+
}
|
|
29
42
|
};
|
|
30
43
|
}
|
|
31
|
-
function
|
|
32
|
-
const [
|
|
33
|
-
|
|
34
|
-
|
|
44
|
+
function $({ config: t, children: i }) {
|
|
45
|
+
const [o] = d(() => E(t)), [s, l] = d(!1), n = S(() => O(o), [o]), { isAuthenticated: c, walletAddress: r } = C(
|
|
46
|
+
n.subscribe,
|
|
47
|
+
n.getSnapshot
|
|
35
48
|
);
|
|
36
|
-
|
|
37
|
-
|
|
49
|
+
console.log("[CROSSxProvider] render:", { isInitialized: s, isAuthenticated: c, walletAddress: r }), m(() => {
|
|
50
|
+
let e = !1;
|
|
51
|
+
return console.log("[CROSSxProvider] useEffect mount"), (async () => {
|
|
38
52
|
try {
|
|
39
|
-
await
|
|
40
|
-
} catch (
|
|
41
|
-
console.error("CROSSx SDK 초기화 실패:",
|
|
53
|
+
await o.initialize(), console.log("[CROSSxProvider] sdk.initialize() done, cancelled=", e), e || l(!0);
|
|
54
|
+
} catch (h) {
|
|
55
|
+
e || console.error("CROSSx SDK 초기화 실패:", h);
|
|
42
56
|
}
|
|
43
|
-
})()
|
|
44
|
-
|
|
45
|
-
|
|
57
|
+
})(), () => {
|
|
58
|
+
console.log("[CROSSxProvider] useEffect cleanup"), e = !0;
|
|
59
|
+
};
|
|
60
|
+
}, [o]);
|
|
61
|
+
const u = S(
|
|
46
62
|
() => ({
|
|
47
|
-
sdk:
|
|
48
|
-
isInitialized:
|
|
49
|
-
isAuthenticated:
|
|
50
|
-
walletAddress:
|
|
63
|
+
sdk: o,
|
|
64
|
+
isInitialized: s,
|
|
65
|
+
isAuthenticated: c,
|
|
66
|
+
walletAddress: r
|
|
51
67
|
}),
|
|
52
|
-
[
|
|
68
|
+
[o, s, c, r]
|
|
53
69
|
);
|
|
54
|
-
return /* @__PURE__ */
|
|
70
|
+
return /* @__PURE__ */ A(g.Provider, { value: u, children: i });
|
|
55
71
|
}
|
|
56
|
-
function
|
|
57
|
-
const t = x(
|
|
72
|
+
function w() {
|
|
73
|
+
const t = x(g);
|
|
58
74
|
if (!t)
|
|
59
75
|
throw new Error("useCROSSx must be used within CROSSxProvider");
|
|
60
76
|
return t;
|
|
61
77
|
}
|
|
62
|
-
function
|
|
63
|
-
const { sdk: t, isAuthenticated:
|
|
78
|
+
function D() {
|
|
79
|
+
const { sdk: t, isAuthenticated: i } = w(), [o, s] = d(!1), [l, n] = d(null), c = f(async () => {
|
|
64
80
|
if (!t)
|
|
65
81
|
throw new Error("SDK가 초기화되지 않았습니다");
|
|
66
|
-
|
|
82
|
+
s(!0), n(null);
|
|
67
83
|
try {
|
|
68
84
|
const e = await t.signIn();
|
|
69
|
-
return e.success ||
|
|
85
|
+
return e.success || n(e.error || "로그인 실패"), e;
|
|
70
86
|
} catch (e) {
|
|
71
87
|
const a = e instanceof Error ? e.message : "로그인 실패";
|
|
72
|
-
throw
|
|
88
|
+
throw n(a), e;
|
|
73
89
|
} finally {
|
|
74
|
-
|
|
90
|
+
s(!1);
|
|
75
91
|
}
|
|
76
|
-
}, [t]),
|
|
92
|
+
}, [t]), r = f(async () => {
|
|
77
93
|
if (!t)
|
|
78
94
|
throw new Error("SDK가 초기화되지 않았습니다");
|
|
79
|
-
|
|
95
|
+
s(!0), n(null);
|
|
80
96
|
try {
|
|
81
97
|
const e = await t.signInWithCreate();
|
|
82
|
-
return e.success ||
|
|
98
|
+
return e.success || n(e.error || "로그인 실패"), e;
|
|
83
99
|
} catch (e) {
|
|
84
100
|
const a = e instanceof Error ? e.message : "로그인 실패";
|
|
85
|
-
throw
|
|
101
|
+
throw n(a), e;
|
|
86
102
|
} finally {
|
|
87
|
-
|
|
103
|
+
s(!1);
|
|
88
104
|
}
|
|
89
105
|
}, [t]), u = f(async () => {
|
|
90
106
|
if (!t)
|
|
91
107
|
throw new Error("SDK가 초기화되지 않았습니다");
|
|
92
|
-
|
|
108
|
+
s(!0), n(null);
|
|
93
109
|
try {
|
|
94
110
|
await t.signOut();
|
|
95
111
|
} catch (e) {
|
|
96
112
|
const a = e instanceof Error ? e.message : "로그아웃 실패";
|
|
97
|
-
throw
|
|
113
|
+
throw n(a), e;
|
|
98
114
|
} finally {
|
|
99
|
-
|
|
115
|
+
s(!1);
|
|
100
116
|
}
|
|
101
117
|
}, [t]);
|
|
102
118
|
return {
|
|
103
|
-
isAuthenticated:
|
|
104
|
-
isLoading:
|
|
105
|
-
error:
|
|
106
|
-
signIn:
|
|
107
|
-
signInWithCreate:
|
|
119
|
+
isAuthenticated: i,
|
|
120
|
+
isLoading: o,
|
|
121
|
+
error: l,
|
|
122
|
+
signIn: c,
|
|
123
|
+
signInWithCreate: r,
|
|
108
124
|
signOut: u
|
|
109
125
|
};
|
|
110
126
|
}
|
|
111
|
-
function
|
|
112
|
-
const { sdk: t, walletAddress:
|
|
127
|
+
function K() {
|
|
128
|
+
const { sdk: t, walletAddress: i } = w(), [o, s] = d(!1), [l, n] = d(null), c = f(
|
|
113
129
|
async (u, e) => {
|
|
114
130
|
if (!t) throw new Error("SDK가 초기화되지 않았습니다");
|
|
115
|
-
|
|
131
|
+
s(!0), n(null);
|
|
116
132
|
try {
|
|
117
133
|
return await t.signMessage(u, e);
|
|
118
134
|
} catch (a) {
|
|
119
135
|
const h = a instanceof Error ? a.message : "서명 실패";
|
|
120
|
-
throw
|
|
136
|
+
throw n(h), a;
|
|
121
137
|
} finally {
|
|
122
|
-
|
|
138
|
+
s(!1);
|
|
123
139
|
}
|
|
124
140
|
},
|
|
125
141
|
[t]
|
|
126
|
-
),
|
|
142
|
+
), r = f(
|
|
127
143
|
async (u, e) => {
|
|
128
144
|
if (!t) throw new Error("SDK가 초기화되지 않았습니다");
|
|
129
|
-
|
|
145
|
+
s(!0), n(null);
|
|
130
146
|
try {
|
|
131
147
|
return await t.sendTransaction(u, e);
|
|
132
148
|
} catch (a) {
|
|
133
149
|
const h = a instanceof Error ? a.message : "트랜잭션 전송 실패";
|
|
134
|
-
throw
|
|
150
|
+
throw n(h), a;
|
|
135
151
|
} finally {
|
|
136
|
-
|
|
152
|
+
s(!1);
|
|
137
153
|
}
|
|
138
154
|
},
|
|
139
155
|
[t]
|
|
140
156
|
);
|
|
141
157
|
return {
|
|
142
|
-
address:
|
|
143
|
-
isLoading:
|
|
144
|
-
error:
|
|
145
|
-
signMessage:
|
|
146
|
-
sendTransaction:
|
|
158
|
+
address: i,
|
|
159
|
+
isLoading: o,
|
|
160
|
+
error: l,
|
|
161
|
+
signMessage: c,
|
|
162
|
+
sendTransaction: r
|
|
147
163
|
};
|
|
148
164
|
}
|
|
149
165
|
export {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
166
|
+
$ as CROSSxProvider,
|
|
167
|
+
P as ChainId,
|
|
168
|
+
D as useAuth,
|
|
169
|
+
w as useCROSSx,
|
|
170
|
+
K as useWallet
|
|
155
171
|
};
|
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.7",
|
|
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.7"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/react": "^18.2.48",
|