@nexus-cross/crossx-sdk-react 0.0.0-beta.2 → 1.0.0-beta.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.
package/README.md CHANGED
@@ -263,7 +263,7 @@ themeTokens: {
263
263
 
264
264
  ### `useAuth()`
265
265
 
266
- 인증(로그인/로그아웃/탈퇴) 관련 상태와 액션을 제공합니다.
266
+ 인증(로그인/로그아웃) 관련 상태와 액션을 제공합니다.
267
267
 
268
268
  ```ts
269
269
  const {
@@ -272,7 +272,6 @@ const {
272
272
  error, // string | null — 마지막 에러 메시지
273
273
  signIn, // () => Promise<AuthResult> — OAuth 로그인
274
274
  signOut, // () => Promise<void> — 로그아웃
275
- withdraw, // () => Promise<void> — 계정 탈퇴 (데이터 삭제)
276
275
  } = useAuth();
277
276
  ```
278
277
 
@@ -355,7 +354,6 @@ const {
355
354
  | `sdk.rpcRequest(method, params, chainId)` | 범용 JSON-RPC 호출 |
356
355
  | `sdk.getProvider(chainId)` | EIP-1193 Provider 반환 |
357
356
  | `sdk.createWallet()` | 수동 지갑 생성 |
358
- | `sdk.withdraw()` | 계정 탈퇴 |
359
357
  | `sdk.setTheme('dark')` | 확인 모달 테마 런타임 전환 (`themeTokens` 오버라이드 유지) |
360
358
 
361
359
  ---
@@ -1 +1 @@
1
- {"version":3,"file":"CROSSxProvider.d.ts","sourceRoot":"","sources":["../src/CROSSxProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsD,MAAM,OAAO,CAAC;AAE3E,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;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,mBAAmB,2CAuCvE"}
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"}
@@ -2,6 +2,8 @@ import { AuthResult } from '@nexus-cross/crossx-sdk-core';
2
2
 
3
3
  /**
4
4
  * 인증 관련 기능을 제공하는 훅
5
+ *
6
+ * SDK의 authChanged 이벤트를 통해 isAuthenticated 상태가 자동 동기화됩니다.
5
7
  */
6
8
  export declare function useAuth(): {
7
9
  isAuthenticated: boolean;
@@ -9,6 +11,5 @@ export declare function useAuth(): {
9
11
  error: string | null;
10
12
  signIn: () => Promise<AuthResult>;
11
13
  signOut: () => Promise<void>;
12
- withdraw: () => Promise<void>;
13
14
  };
14
15
  //# 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;;GAEG;AACH,wBAAgB,OAAO;;;;;;;EAmFtB"}
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;;;;;;EAyDtB"}
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("react/jsx-runtime"),s=require("react"),w=require("@nexus-cross/crossx-sdk-core"),h=s.createContext({sdk:null,isInitialized:!1,isAuthenticated:!1,walletAddress:null});function y({config:t,children:u}){const[i]=s.useState(()=>w.createCROSSxSDK(t)),[n,d]=s.useState(!1),[r,S]=s.useState(!1),[l,c]=s.useState(null);s.useEffect(()=>{(async()=>{try{const o=await i.initialize();d(!0),o!=null&&o.success&&(S(!0),c(o.address??null))}catch(o){console.error("CROSSx SDK 초기화 실패:",o)}})()},[i]);const e=s.useMemo(()=>({sdk:i,isInitialized:n,isAuthenticated:r,walletAddress:l}),[i,n,r,l]);return g.jsx(h.Provider,{value:e,children:u})}function f(){const t=s.useContext(h);if(!t)throw new Error("useCROSSx must be used within CROSSxProvider");return t}function C(){const{sdk:t,isAuthenticated:u}=f(),[i,n]=s.useState(!1),[d,r]=s.useState(null),S=s.useCallback(async()=>{if(!t)throw new Error("SDK가 초기화되지 않았습니다");n(!0),r(null);try{const e=await t.signIn();return e.success?(window.location.reload(),e):(r(e.error||"로그인 실패"),e)}catch(e){const a=e instanceof Error?e.message:"로그인 실패";throw r(a),e}finally{n(!1)}},[t]),l=s.useCallback(async()=>{if(!t)throw new Error("SDK가 초기화되지 않았습니다");n(!0),r(null);try{await t.signOut(),window.location.reload()}catch(e){const a=e instanceof Error?e.message:"로그아웃 실패";throw r(a),e}finally{n(!1)}},[t]),c=s.useCallback(async()=>{if(!t)throw new Error("SDK가 초기화되지 않았습니다");n(!0),r(null);try{await t.withdraw(),window.location.reload()}catch(e){const a=e instanceof Error?e.message:"탈퇴 실패";throw r(a),e}finally{n(!1)}},[t]);return{isAuthenticated:u,isLoading:i,error:d,signIn:S,signOut:l,withdraw:c}}function x(){const{sdk:t,walletAddress:u}=f(),[i,n]=s.useState(!1),[d,r]=s.useState(null),S=s.useCallback(async(c,e)=>{if(!t)throw new Error("SDK가 초기화되지 않았습니다");n(!0),r(null);try{return await t.signMessage(c,e)}catch(a){const o=a instanceof Error?a.message:"서명 실패";throw r(o),a}finally{n(!1)}},[t]),l=s.useCallback(async(c,e)=>{if(!t)throw new Error("SDK가 초기화되지 않았습니다");n(!0),r(null);try{return await t.sendTransaction(c,e)}catch(a){const o=a instanceof Error?a.message:"트랜잭션 전송 실패";throw r(o),a}finally{n(!1)}},[t]);return{address:u,isLoading:i,error:d,signMessage:S,sendTransaction:l}}Object.defineProperty(exports,"ChainId",{enumerable:!0,get:()=>w.ChainId});exports.CROSSxProvider=y;exports.useAuth=C;exports.useCROSSx=f;exports.useWallet=x;
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 C(e){let o={isAuthenticated:e.isAuthenticated(),walletAddress:e.currentAddress};const r=new Set,a=e.on("authChanged",t=>{o={isAuthenticated:t.isAuthenticated,walletAddress:t.address},r.forEach(i=>i())}),l=e.on("addressChanged",t=>{o={...o,walletAddress:t.address},r.forEach(i=>i())});return{subscribe:t=>(r.add(t),()=>{r.delete(t),r.size===0&&(a(),l())}),getSnapshot:()=>o}}function x({config:e,children:o}){const[r]=n.useState(()=>h.createCROSSxSDK(e)),[a,l]=n.useState(!1),t=n.useMemo(()=>C(r),[r]),{isAuthenticated:i,walletAddress:d}=n.useSyncExternalStore(t.subscribe,t.getSnapshot);n.useEffect(()=>{(async()=>{try{await r.initialize(),l(!0)}catch(c){console.error("CROSSx SDK 초기화 실패:",c)}})()},[r]);const s=n.useMemo(()=>({sdk:r,isInitialized:a,isAuthenticated:i,walletAddress:d}),[r,a,i,d]);return g.jsx(w.Provider,{value:s,children:o})}function f(){const e=n.useContext(w);if(!e)throw new Error("useCROSSx must be used within CROSSxProvider");return e}function y(){const{sdk:e,isAuthenticated:o}=f(),[r,a]=n.useState(!1),[l,t]=n.useState(null),i=n.useCallback(async()=>{if(!e)throw new Error("SDK가 초기화되지 않았습니다");a(!0),t(null);try{const s=await e.signIn();return s.success||t(s.error||"로그인 실패"),s}catch(s){const u=s instanceof Error?s.message:"로그인 실패";throw t(u),s}finally{a(!1)}},[e]),d=n.useCallback(async()=>{if(!e)throw new Error("SDK가 초기화되지 않았습니다");a(!0),t(null);try{await e.signOut()}catch(s){const u=s instanceof Error?s.message:"로그아웃 실패";throw t(u),s}finally{a(!1)}},[e]);return{isAuthenticated:o,isLoading:r,error:l,signIn:i,signOut:d}}function A(){const{sdk:e,walletAddress:o}=f(),[r,a]=n.useState(!1),[l,t]=n.useState(null),i=n.useCallback(async(s,u)=>{if(!e)throw new Error("SDK가 초기화되지 않았습니다");a(!0),t(null);try{return await e.signMessage(s,u)}catch(c){const S=c instanceof Error?c.message:"서명 실패";throw t(S),c}finally{a(!1)}},[e]),d=n.useCallback(async(s,u)=>{if(!e)throw new Error("SDK가 초기화되지 않았습니다");a(!0),t(null);try{return await e.sendTransaction(s,u)}catch(c){const S=c instanceof Error?c.message:"트랜잭션 전송 실패";throw t(S),c}finally{a(!1)}},[e]);return{address:o,isLoading:r,error:l,signMessage:i,sendTransaction:d}}Object.defineProperty(exports,"ChainId",{enumerable:!0,get:()=>h.ChainId});exports.CROSSxProvider=x;exports.useAuth=y;exports.useCROSSx=f;exports.useWallet=A;
package/dist/index.js CHANGED
@@ -1,132 +1,141 @@
1
- import { jsx as g } from "react/jsx-runtime";
2
- import { createContext as m, useState as i, useEffect as y, useMemo as x, useContext as E, useCallback as w } from "react";
1
+ import { jsx as m } from "react/jsx-runtime";
2
+ import { createContext as A, useState as d, useMemo as S, useSyncExternalStore as x, useEffect as y, useContext as E, 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 h = m({
5
+ const w = A({
6
6
  sdk: null,
7
7
  isInitialized: !1,
8
8
  isAuthenticated: !1,
9
9
  walletAddress: null
10
10
  });
11
- function K({ config: e, children: u }) {
12
- const [a] = i(() => C(e)), [s, d] = i(!1), [r, f] = i(!1), [l, c] = i(null);
11
+ function b(t) {
12
+ let a = {
13
+ isAuthenticated: t.isAuthenticated(),
14
+ walletAddress: t.currentAddress
15
+ };
16
+ const r = /* @__PURE__ */ new Set(), n = t.on("authChanged", (e) => {
17
+ a = {
18
+ isAuthenticated: e.isAuthenticated,
19
+ walletAddress: e.address
20
+ }, r.forEach((o) => o());
21
+ }), u = t.on("addressChanged", (e) => {
22
+ a = { ...a, walletAddress: e.address }, r.forEach((o) => o());
23
+ });
24
+ return {
25
+ subscribe: (e) => (r.add(e), () => {
26
+ r.delete(e), r.size === 0 && (n(), u());
27
+ }),
28
+ getSnapshot: () => a
29
+ };
30
+ }
31
+ function D({ config: t, children: a }) {
32
+ const [r] = d(() => C(t)), [n, u] = d(!1), e = S(() => b(r), [r]), { isAuthenticated: o, walletAddress: l } = x(
33
+ e.subscribe,
34
+ e.getSnapshot
35
+ );
13
36
  y(() => {
14
37
  (async () => {
15
38
  try {
16
- const o = await a.initialize();
17
- d(!0), o != null && o.success && (f(!0), c(o.address ?? null));
18
- } catch (o) {
19
- console.error("CROSSx SDK 초기화 실패:", o);
39
+ await r.initialize(), u(!0);
40
+ } catch (i) {
41
+ console.error("CROSSx SDK 초기화 실패:", i);
20
42
  }
21
43
  })();
22
- }, [a]);
23
- const t = x(
44
+ }, [r]);
45
+ const s = S(
24
46
  () => ({
25
- sdk: a,
26
- isInitialized: s,
27
- isAuthenticated: r,
47
+ sdk: r,
48
+ isInitialized: n,
49
+ isAuthenticated: o,
28
50
  walletAddress: l
29
51
  }),
30
- [a, s, r, l]
52
+ [r, n, o, l]
31
53
  );
32
- return /* @__PURE__ */ g(h.Provider, { value: t, children: u });
54
+ return /* @__PURE__ */ m(w.Provider, { value: s, children: a });
33
55
  }
34
- function S() {
35
- const e = E(h);
36
- if (!e)
56
+ function g() {
57
+ const t = E(w);
58
+ if (!t)
37
59
  throw new Error("useCROSSx must be used within CROSSxProvider");
38
- return e;
60
+ return t;
39
61
  }
40
- function O() {
41
- const { sdk: e, isAuthenticated: u } = S(), [a, s] = i(!1), [d, r] = i(null), f = w(async () => {
42
- if (!e)
43
- throw new Error("SDK가 초기화되지 않았습니다");
44
- s(!0), r(null);
45
- try {
46
- const t = await e.signIn();
47
- return t.success ? (window.location.reload(), t) : (r(t.error || "로그인 실패"), t);
48
- } catch (t) {
49
- const n = t instanceof Error ? t.message : "로그인 실패";
50
- throw r(n), t;
51
- } finally {
52
- s(!1);
53
- }
54
- }, [e]), l = w(async () => {
55
- if (!e)
62
+ function K() {
63
+ const { sdk: t, isAuthenticated: a } = g(), [r, n] = d(!1), [u, e] = d(null), o = f(async () => {
64
+ if (!t)
56
65
  throw new Error("SDK가 초기화되지 않았습니다");
57
- s(!0), r(null);
66
+ n(!0), e(null);
58
67
  try {
59
- await e.signOut(), window.location.reload();
60
- } catch (t) {
61
- const n = t instanceof Error ? t.message : "로그아웃 실패";
62
- throw r(n), t;
68
+ const s = await t.signIn();
69
+ return s.success || e(s.error || "로그인 실패"), s;
70
+ } catch (s) {
71
+ const c = s instanceof Error ? s.message : "로그인 실패";
72
+ throw e(c), s;
63
73
  } finally {
64
- s(!1);
74
+ n(!1);
65
75
  }
66
- }, [e]), c = w(async () => {
67
- if (!e)
76
+ }, [t]), l = f(async () => {
77
+ if (!t)
68
78
  throw new Error("SDK가 초기화되지 않았습니다");
69
- s(!0), r(null);
79
+ n(!0), e(null);
70
80
  try {
71
- await e.withdraw(), window.location.reload();
72
- } catch (t) {
73
- const n = t instanceof Error ? t.message : "탈퇴 실패";
74
- throw r(n), t;
81
+ await t.signOut();
82
+ } catch (s) {
83
+ const c = s instanceof Error ? s.message : "로그아웃 실패";
84
+ throw e(c), s;
75
85
  } finally {
76
- s(!1);
86
+ n(!1);
77
87
  }
78
- }, [e]);
88
+ }, [t]);
79
89
  return {
80
- isAuthenticated: u,
81
- isLoading: a,
82
- error: d,
83
- signIn: f,
84
- signOut: l,
85
- withdraw: c
90
+ isAuthenticated: a,
91
+ isLoading: r,
92
+ error: u,
93
+ signIn: o,
94
+ signOut: l
86
95
  };
87
96
  }
88
97
  function R() {
89
- const { sdk: e, walletAddress: u } = S(), [a, s] = i(!1), [d, r] = i(null), f = w(
90
- async (c, t) => {
91
- if (!e) throw new Error("SDK가 초기화되지 않았습니다");
92
- s(!0), r(null);
98
+ const { sdk: t, walletAddress: a } = g(), [r, n] = d(!1), [u, e] = d(null), o = f(
99
+ async (s, c) => {
100
+ if (!t) throw new Error("SDK가 초기화되지 않았습니다");
101
+ n(!0), e(null);
93
102
  try {
94
- return await e.signMessage(c, t);
95
- } catch (n) {
96
- const o = n instanceof Error ? n.message : "서명 실패";
97
- throw r(o), n;
103
+ return await t.signMessage(s, c);
104
+ } catch (i) {
105
+ const h = i instanceof Error ? i.message : "서명 실패";
106
+ throw e(h), i;
98
107
  } finally {
99
- s(!1);
108
+ n(!1);
100
109
  }
101
110
  },
102
- [e]
103
- ), l = w(
104
- async (c, t) => {
105
- if (!e) throw new Error("SDK가 초기화되지 않았습니다");
106
- s(!0), r(null);
111
+ [t]
112
+ ), l = f(
113
+ async (s, c) => {
114
+ if (!t) throw new Error("SDK가 초기화되지 않았습니다");
115
+ n(!0), e(null);
107
116
  try {
108
- return await e.sendTransaction(c, t);
109
- } catch (n) {
110
- const o = n instanceof Error ? n.message : "트랜잭션 전송 실패";
111
- throw r(o), n;
117
+ return await t.sendTransaction(s, c);
118
+ } catch (i) {
119
+ const h = i instanceof Error ? i.message : "트랜잭션 전송 실패";
120
+ throw e(h), i;
112
121
  } finally {
113
- s(!1);
122
+ n(!1);
114
123
  }
115
124
  },
116
- [e]
125
+ [t]
117
126
  );
118
127
  return {
119
- address: u,
120
- isLoading: a,
121
- error: d,
122
- signMessage: f,
128
+ address: a,
129
+ isLoading: r,
130
+ error: u,
131
+ signMessage: o,
123
132
  sendTransaction: l
124
133
  };
125
134
  }
126
135
  export {
127
- K as CROSSxProvider,
136
+ D as CROSSxProvider,
128
137
  v as ChainId,
129
- O as useAuth,
130
- S as useCROSSx,
138
+ K as useAuth,
139
+ g as useCROSSx,
131
140
  R as useWallet
132
141
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nexus-cross/crossx-sdk-react",
3
- "version": "0.0.0-beta.2",
3
+ "version": "1.0.0-beta.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": "0.0.0-beta.2"
36
+ "@nexus-cross/crossx-sdk-core": "1.0.0-beta.1"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/react": "^18.2.48",