@nexus-cross/crossx-sdk-react 1.0.9 → 1.1.1

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