@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.
@@ -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;;;;;;EAyDtB"}
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"),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;
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 A, useState as d, useMemo as S, useSyncExternalStore as x, useEffect as y, useContext as E, useCallback as f } from "react";
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 w = A({
5
+ const S = y({
6
6
  sdk: null,
7
7
  isInitialized: !1,
8
8
  isAuthenticated: !1,
9
9
  walletAddress: null
10
10
  });
11
- function b(t) {
12
- let a = {
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", (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());
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: (e) => (r.add(e), () => {
26
- r.delete(e), r.size === 0 && (n(), u());
25
+ subscribe: (s) => (r.add(s), () => {
26
+ r.delete(s), r.size === 0 && (n(), c());
27
27
  }),
28
- getSnapshot: () => a
28
+ getSnapshot: () => o
29
29
  };
30
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
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
- y(() => {
36
+ E(() => {
37
37
  (async () => {
38
38
  try {
39
- await r.initialize(), u(!0);
40
- } catch (i) {
41
- console.error("CROSSx SDK 초기화 실패:", i);
39
+ await r.initialize(), c(!0);
40
+ } catch (a) {
41
+ console.error("CROSSx SDK 초기화 실패:", a);
42
42
  }
43
43
  })();
44
44
  }, [r]);
45
- const s = S(
45
+ const u = w(
46
46
  () => ({
47
47
  sdk: r,
48
48
  isInitialized: n,
49
- isAuthenticated: o,
49
+ isAuthenticated: i,
50
50
  walletAddress: l
51
51
  }),
52
- [r, n, o, l]
52
+ [r, n, i, l]
53
53
  );
54
- return /* @__PURE__ */ m(w.Provider, { value: s, children: a });
54
+ return /* @__PURE__ */ m(S.Provider, { value: u, children: o });
55
55
  }
56
56
  function g() {
57
- const t = E(w);
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 K() {
63
- const { sdk: t, isAuthenticated: a } = g(), [r, n] = d(!1), [u, e] = d(null), o = f(async () => {
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), e(null);
66
+ n(!0), s(null);
67
67
  try {
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;
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), e(null);
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 (s) {
83
- const c = s instanceof Error ? s.message : "로그아웃 실패";
84
- throw e(c), s;
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: a,
103
+ isAuthenticated: o,
91
104
  isLoading: r,
92
- error: u,
93
- signIn: o,
94
- signOut: l
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: a } = g(), [r, n] = d(!1), [u, e] = d(null), o = f(
99
- async (s, c) => {
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), e(null);
115
+ n(!0), s(null);
102
116
  try {
103
- return await t.signMessage(s, c);
104
- } catch (i) {
105
- const h = i instanceof Error ? i.message : "서명 실패";
106
- throw e(h), i;
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 (s, c) => {
127
+ async (u, e) => {
114
128
  if (!t) throw new Error("SDK가 초기화되지 않았습니다");
115
- n(!0), e(null);
129
+ n(!0), s(null);
116
130
  try {
117
- return await t.sendTransaction(s, c);
118
- } catch (i) {
119
- const h = i instanceof Error ? i.message : "트랜잭션 전송 실패";
120
- throw e(h), i;
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: a,
142
+ address: o,
129
143
  isLoading: r,
130
- error: u,
131
- signMessage: o,
144
+ error: c,
145
+ signMessage: i,
132
146
  sendTransaction: l
133
147
  };
134
148
  }
135
149
  export {
136
- D as CROSSxProvider,
150
+ O as CROSSxProvider,
137
151
  v as ChainId,
138
- K as useAuth,
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.2-beta.1",
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.2-beta.1"
36
+ "@nexus-cross/crossx-sdk-core": "1.0.3"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/react": "^18.2.48",