@nexus-cross/crossx-sdk-react 1.0.6 → 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.
@@ -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;AA+CD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,mBAAmB,2CAsCvE"}
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 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;
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 m } from "react/jsx-runtime";
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
- import { createCROSSxSDK as C } from "@nexus-cross/crossx-sdk-core";
4
- import { ChainId as v } from "@nexus-cross/crossx-sdk-core";
5
- const S = y({
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
- function I(t) {
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 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());
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: (s) => (r.add(s), () => {
26
- r.delete(s), r.size === 0 && (n(), c());
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 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
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
- E(() => {
37
- (async () => {
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 r.initialize(), c(!0);
40
- } catch (a) {
41
- console.error("CROSSx SDK 초기화 실패:", a);
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
- }, [r]);
45
- const u = w(
57
+ })(), () => {
58
+ console.log("[CROSSxProvider] useEffect cleanup"), e = !0;
59
+ };
60
+ }, [o]);
61
+ const u = S(
46
62
  () => ({
47
- sdk: r,
48
- isInitialized: n,
49
- isAuthenticated: i,
50
- walletAddress: l
63
+ sdk: o,
64
+ isInitialized: s,
65
+ isAuthenticated: c,
66
+ walletAddress: r
51
67
  }),
52
- [r, n, i, l]
68
+ [o, s, c, r]
53
69
  );
54
- return /* @__PURE__ */ m(S.Provider, { value: u, children: o });
70
+ return /* @__PURE__ */ A(g.Provider, { value: u, children: i });
55
71
  }
56
- function g() {
57
- const t = x(S);
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 p() {
63
- const { sdk: t, isAuthenticated: o } = g(), [r, n] = d(!1), [c, s] = d(null), i = f(async () => {
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
- n(!0), s(null);
82
+ s(!0), n(null);
67
83
  try {
68
84
  const e = await t.signIn();
69
- return e.success || s(e.error || "로그인 실패"), e;
85
+ return e.success || n(e.error || "로그인 실패"), e;
70
86
  } catch (e) {
71
87
  const a = e instanceof Error ? e.message : "로그인 실패";
72
- throw s(a), e;
88
+ throw n(a), e;
73
89
  } finally {
74
- n(!1);
90
+ s(!1);
75
91
  }
76
- }, [t]), l = f(async () => {
92
+ }, [t]), r = f(async () => {
77
93
  if (!t)
78
94
  throw new Error("SDK가 초기화되지 않았습니다");
79
- n(!0), s(null);
95
+ s(!0), n(null);
80
96
  try {
81
97
  const e = await t.signInWithCreate();
82
- return e.success || s(e.error || "로그인 실패"), e;
98
+ return e.success || n(e.error || "로그인 실패"), e;
83
99
  } catch (e) {
84
100
  const a = e instanceof Error ? e.message : "로그인 실패";
85
- throw s(a), e;
101
+ throw n(a), e;
86
102
  } finally {
87
- n(!1);
103
+ s(!1);
88
104
  }
89
105
  }, [t]), u = f(async () => {
90
106
  if (!t)
91
107
  throw new Error("SDK가 초기화되지 않았습니다");
92
- n(!0), s(null);
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 s(a), e;
113
+ throw n(a), e;
98
114
  } finally {
99
- n(!1);
115
+ s(!1);
100
116
  }
101
117
  }, [t]);
102
118
  return {
103
- isAuthenticated: o,
104
- isLoading: r,
105
- error: c,
106
- signIn: i,
107
- signInWithCreate: l,
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 R() {
112
- const { sdk: t, walletAddress: o } = g(), [r, n] = d(!1), [c, s] = d(null), i = f(
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
- n(!0), s(null);
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 s(h), a;
136
+ throw n(h), a;
121
137
  } finally {
122
- n(!1);
138
+ s(!1);
123
139
  }
124
140
  },
125
141
  [t]
126
- ), l = f(
142
+ ), r = f(
127
143
  async (u, e) => {
128
144
  if (!t) throw new Error("SDK가 초기화되지 않았습니다");
129
- n(!0), s(null);
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 s(h), a;
150
+ throw n(h), a;
135
151
  } finally {
136
- n(!1);
152
+ s(!1);
137
153
  }
138
154
  },
139
155
  [t]
140
156
  );
141
157
  return {
142
- address: o,
143
- isLoading: r,
144
- error: c,
145
- signMessage: i,
146
- sendTransaction: l
158
+ address: i,
159
+ isLoading: o,
160
+ error: l,
161
+ signMessage: c,
162
+ sendTransaction: r
147
163
  };
148
164
  }
149
165
  export {
150
- O as CROSSxProvider,
151
- v as ChainId,
152
- p as useAuth,
153
- g as useCROSSx,
154
- R as useWallet
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.6",
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.6"
36
+ "@nexus-cross/crossx-sdk-core": "1.0.7"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/react": "^18.2.48",