@nexus-cross/crossx-sdk-wagmi 2.0.0 → 2.0.1-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/dist/connector.d.ts +6 -6
- package/dist/connector.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +49 -46
- package/package.json +2 -2
package/dist/connector.d.ts
CHANGED
|
@@ -10,10 +10,10 @@ export interface CROSSxConnectorOptions {
|
|
|
10
10
|
/** 활성 지갑 인덱스 변경 시 호출되는 콜백. 미설정 시 localStorage 자동 사용. */
|
|
11
11
|
onWalletIndexChanged?: (index: number) => void;
|
|
12
12
|
/**
|
|
13
|
-
* 로그인 모달에서
|
|
13
|
+
* 로그인 모달에서 외부 지갑 행 클릭 시 호출되는 콜백.
|
|
14
14
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
15
|
+
* SDK에 `connectOtherWallets` / `showConnectOtherWallets`가 없으면 외부 지갑 구역이 나오지 않습니다.
|
|
16
|
+
* `crossxConnector({ openConnectOtherWallet })`만 주면 `showConnectOtherWallets: true`가 자동 설정되어 Binance·MetaMask·CROSSx 행이 표시됩니다.
|
|
17
17
|
*
|
|
18
18
|
* @example
|
|
19
19
|
* createCROSSxConnector({
|
|
@@ -31,11 +31,11 @@ export type CrossxConnectorOptions = Omit<SDKConfig, 'useMockWallet'> & {
|
|
|
31
31
|
/** 활성 지갑 인덱스 변경 시 호출되는 콜백. 미설정 시 localStorage 자동 사용. */
|
|
32
32
|
onWalletIndexChanged?: (index: number) => void;
|
|
33
33
|
/**
|
|
34
|
-
* 로그인 모달에서
|
|
34
|
+
* 로그인 모달에서 외부 지갑 행 클릭 시 호출되는 콜백.
|
|
35
35
|
*
|
|
36
|
-
* 제공 시 `showConnectOtherWallets: true`가 자동 적용되며,
|
|
36
|
+
* 제공 시 `showConnectOtherWallets`·`connectOtherWallets`가 없으면 `showConnectOtherWallets: true`가 자동 적용되며,
|
|
37
37
|
* SDK의 `connectExternalWallet` 이벤트에 자동 등록됩니다.
|
|
38
|
-
*
|
|
38
|
+
* 일부 지갑만 쓰려면 `connectOtherWallets: [ ... ]`로 좁히면 됩니다.
|
|
39
39
|
*
|
|
40
40
|
* @example
|
|
41
41
|
* crossxConnector({
|
package/dist/connector.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connector.d.ts","sourceRoot":"","sources":["../src/connector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAEzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAInD,oCAAoC;AACpC,MAAM,WAAW,sBAAsB;IACrC,GAAG,EAAE,SAAS,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACjC,qDAAqD;IACrD,oBAAoB,CAAC,EAAE,MAAM,MAAM,CAAC;IACpC,wDAAwD;IACxD,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/C;;;;;;;;;;;OAWG;IACH,sBAAsB,CAAC,EAAE,MAAM,IAAI,CAAC;CACrC;AAED,uCAAuC;AACvC,MAAM,MAAM,sBAAsB,GAAG,IAAI,CAAC,SAAS,EAAE,eAAe,CAAC,GAAG;IACtE,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACjC,qDAAqD;IACrD,oBAAoB,CAAC,EAAE,MAAM,MAAM,CAAC;IACpC,wDAAwD;IACxD,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/C;;;;;;;;;;;;;OAaG;IACH,sBAAsB,CAAC,EAAE,MAAM,IAAI,CAAC;CACrC,CAAC;AAgCF,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,
|
|
1
|
+
{"version":3,"file":"connector.d.ts","sourceRoot":"","sources":["../src/connector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAEzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAInD,oCAAoC;AACpC,MAAM,WAAW,sBAAsB;IACrC,GAAG,EAAE,SAAS,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACjC,qDAAqD;IACrD,oBAAoB,CAAC,EAAE,MAAM,MAAM,CAAC;IACpC,wDAAwD;IACxD,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/C;;;;;;;;;;;OAWG;IACH,sBAAsB,CAAC,EAAE,MAAM,IAAI,CAAC;CACrC;AAED,uCAAuC;AACvC,MAAM,MAAM,sBAAsB,GAAG,IAAI,CAAC,SAAS,EAAE,eAAe,CAAC,GAAG;IACtE,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACjC,qDAAqD;IACrD,oBAAoB,CAAC,EAAE,MAAM,MAAM,CAAC;IACpC,wDAAwD;IACxD,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/C;;;;;;;;;;;;;OAaG;IACH,sBAAsB,CAAC,EAAE,MAAM,IAAI,CAAC;CACrC,CAAC;AAgCF,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,8GAc9D;AAID,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,8GAqPpE"}
|
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 L=require("wagmi"),N=require("viem"),x=require("@nexus-cross/crossx-sdk-core");function q(i){return parseInt(i.split(":")[1]??"1",10)}function S(i){return`eip155:${i}`}function O(i){return"0x"+i.toString(16)}function b(i){const t=i.startsWith("0x")?i.slice(2):i,s=new Uint8Array(t.length/2);for(let n=0;n<s.length;n++)s[n]=parseInt(t.substring(n*2,n*2+2),16);return new TextDecoder().decode(s)}class D{constructor(t,s=x.ChainId.CROSS_MAINNET){this.sdk=t,this.listeners=new Map,this.walletIndex=0,this.currentAccounts=[],this.off=this.removeListener.bind(this),this.chainId=typeof s=="number"?s:q(s),this.sdk.on("addressChanged",({address:n,index:d})=>{this.setWalletIndex(d),this.notifyAccountsChanged([n])})}_setWalletIndexChangeCallback(t){this.walletIndexChangeCallback=t}async request({method:t,params:s}){try{return await this._handleRequest(t,s)}catch(n){throw n instanceof x.CROSSxError&&n.code===x.ErrorCode.USER_REJECTED?Object.assign(new Error("User rejected the request"),{code:4001,data:n.details}):n}}async _handleRequest(t,s){var d;const n=s??[];switch(t){case"eth_requestAccounts":case"eth_accounts":{if(this.currentAccounts.length>0)return[...this.currentAccounts];const e=await this.sdk.getAddress();return e?[e.address]:[]}case"eth_chainId":return O(this.chainId);case"net_version":return String(this.chainId);case"personal_sign":{const[e]=n,a=e.startsWith("0x")?b(e):e;return(await this.sdk.signMessage(S(this.chainId),a,{index:this.walletIndex})).signature}case"eth_sign":{const[,e]=n,a=e.startsWith("0x")?b(e):e;return(await this.sdk.signMessage(S(this.chainId),a,{index:this.walletIndex})).signature}case"eth_signTypedData":case"eth_signTypedData_v3":case"eth_signTypedData_v4":{const[,e]=n,a=typeof e=="string"?JSON.parse(e):e,o=(d=a==null?void 0:a.domain)==null?void 0:d.chainId,C=o==null||o===0,f=C?0:Number(o),w={index:this.walletIndex};return(C?await this.sdk.signTypedDataOffchain(a,w):await this.sdk.signTypedData(S(f),a,w)).signature}case"eth_sendTransaction":{const[e]=n,a=S(this.chainId);return(await this.sdk.sendTransaction(a,{from:e.from,to:e.to,value:e.value,data:e.data,gasLimit:e.gasLimit??e.gas,gasPrice:e.gasPrice,maxFeePerGas:e.maxFeePerGas,maxPriorityFeePerGas:e.maxPriorityFeePerGas,nonce:e.nonce!==void 0?parseInt(String(e.nonce),16):void 0,chainId:this.chainId},{index:this.walletIndex})).txHash}case"wallet_switchEthereumChain":{const[{chainId:e}]=n,a=parseInt(e,16);return a!==this.chainId&&(this.chainId=a,this.emit("chainChanged",O(a))),null}case"wallet_addEthereumChain":return null;default:return this.sdk.walletRpc(t,n,S(this.chainId))}}on(t,s){return this.listeners.has(t)||this.listeners.set(t,new Set),this.listeners.get(t).add(s),this}removeListener(t,s){var n;return(n=this.listeners.get(t))==null||n.delete(s),this}emit(t,...s){var n;(n=this.listeners.get(t))==null||n.forEach(d=>d(...s))}notifyAccountsChanged(t){this.currentAccounts=t,this.emit("accountsChanged",t)}notifyDisconnect(t){this.currentAccounts=[],this.walletIndex=0,this.emit("disconnect",t)}getCurrentChainId(){return this.chainId}setChainId(t){t!==this.chainId&&(this.chainId=t,this.emit("chainChanged",O(t)))}setWalletIndex(t){var s;this.walletIndex=t,(s=this.walletIndexChangeCallback)==null||s.call(this,t)}getWalletIndex(){return this.walletIndex}getCurrentAccounts(){return[...this.currentAccounts]}}function G(i){return typeof i=="number"?i:parseInt(i.split(":")[1]??"1",10)}const _="crossx-wallet-index";function M(){try{const i=typeof window<"u"?localStorage.getItem(_):null;return i&&Number(i)||0}catch{return 0}}function U(i){try{typeof window<"u"&&localStorage.setItem(_,String(i))}catch{}}function k(){try{typeof window<"u"&&localStorage.removeItem(_)}catch{}}function j(i){const{defaultChainId:t,getStoredWalletIndex:s,onWalletIndexChanged:n,openConnectOtherWallet:d,...e}=i;if(d){const o=e.connectOtherWallets,C=Array.isArray(o)&&o.length>0,f=e.showConnectOtherWallets===!0;!C&&!f&&(e.showConnectOtherWallets=!0)}const a=x.createCROSSxSDK(e);return T({sdk:a,defaultChainId:t,getStoredWalletIndex:s,onWalletIndexChanged:n,openConnectOtherWallet:d})}function T(i){const{sdk:t,defaultChainId:s=x.ChainId.CROSS_MAINNET,getStoredWalletIndex:n=M,onWalletIndexChanged:d=U,openConnectOtherWallet:e}=i,a=G(s);let o=null,C=!1,f=!1,w=!1;function l(){return o||(o=new D(t,a),o._setWalletIndexChangeCallback(d)),o}return L.createConnector(u=>({id:"crossx",name:"CROSSx Wallet",type:"crossx",async setup(){if(!C){const I=n();await t.initialize({preferredWalletIndex:I}),C=!0,t.on("addressChanged",({address:r,index:g})=>{if(f)return;const p=l();p.setWalletIndex(g),r&&p.notifyAccountsChanged([r])}),t.on("authChanged",r=>{if(!(f||w))if(r.isAuthenticated&&r.address){const g=l();g.notifyAccountsChanged([r.address]),u.emitter.emit("connect",{accounts:[r.address],chainId:g.getCurrentChainId()})}else r.isAuthenticated||(l().notifyDisconnect(),k(),d(0),u.emitter.emit("disconnect"))}),e&&t.on("connectExternalWallet",e)}const c=l();c.on("accountsChanged",this.onAccountsChanged.bind(this)),c.on("chainChanged",this.onChainChanged.bind(this)),c.on("disconnect",this.onDisconnect.bind(this))},async connect({chainId:c,isReconnecting:I}={}){var p;const r=l(),g=c??a;f=!0;try{if(I||t.isAuthenticated()){const h=n();if(t.isAuthenticated()){try{const E=await t.getAddresses();if(E.length>0){const W=E.find(v=>v.index===h)??E[0];return r.setWalletIndex(W.index),r.notifyAccountsChanged([W.address]),{accounts:[W.address],chainId:g}}}catch{}await t.signOut().catch(()=>{}),r.notifyDisconnect()}}let m;try{m=await t.signInWithCreate()}catch(h){throw h instanceof x.CROSSxError&&h.code===x.ErrorCode.EXTERNAL_WALLET_REQUESTED?(r.notifyDisconnect(),new N.UserRejectedRequestError(h)):(t.isAuthenticated()||(r.notifyDisconnect(),u.emitter.emit("disconnect")),h)}if(!m.success)throw new Error(m.error??"CROSSx sign-in failed");const y=m.address,R=m.addresses.map(h=>h.address).filter(h=>!y||h.toLowerCase()!==y.toLowerCase()),A=y?[y,...R]:R;if(A.length===0)throw new Error("No address found after sign-in");const P=((p=m.addresses.find(h=>y&&h.address.toLowerCase()===y.toLowerCase()))==null?void 0:p.index)??0;return r.setWalletIndex(P),r.notifyAccountsChanged(A),{accounts:A,chainId:g}}finally{f=!1}},async disconnect(){w=!0;try{const c=l();await t.signOut(),c.notifyDisconnect(),k(),d(0),u.emitter.emit("disconnect")}finally{w=!1}},async getAccounts(){const I=l().getCurrentAccounts();if(I.length>0)return I;const r=await t.getAddress();return r?[r.address]:[]},async getChainId(){return l().getCurrentChainId()},async getProvider({chainId:c}={}){return l()},async isAuthorized(){return await t.whenReady(),t.isAuthenticated()},async switchChain({chainId:c}){l().setChainId(c),u.emitter.emit("change",{chainId:c});const r=u.chains.find(g=>g.id===c);if(!r)throw new Error(`Chain ${c} is not configured`);return r},onAccountsChanged(c){c.length===0?u.emitter.emit("disconnect"):u.emitter.emit("change",{accounts:c})},onChainChanged(c){u.emitter.emit("change",{chainId:Number(c)})},onDisconnect(){u.emitter.emit("disconnect")}}))}exports.CROSSxEIP1193Provider=D;exports.createCROSSxConnector=T;exports.crossxConnector=j;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createConnector as
|
|
2
|
-
import { UserRejectedRequestError as
|
|
1
|
+
import { createConnector as N } from "wagmi";
|
|
2
|
+
import { UserRejectedRequestError as v } from "viem";
|
|
3
3
|
import { ChainId as R, CROSSxError as k, ErrorCode as T, createCROSSxSDK as q } from "@nexus-cross/crossx-sdk-core";
|
|
4
4
|
function G(i) {
|
|
5
5
|
return parseInt(i.split(":")[1] ?? "1", 10);
|
|
@@ -18,8 +18,8 @@ function b(i) {
|
|
|
18
18
|
}
|
|
19
19
|
class U {
|
|
20
20
|
constructor(t, s = R.CROSS_MAINNET) {
|
|
21
|
-
this.sdk = t, this.listeners = /* @__PURE__ */ new Map(), this.walletIndex = 0, this.currentAccounts = [], this.off = this.removeListener.bind(this), this.chainId = typeof s == "number" ? s : G(s), this.sdk.on("addressChanged", ({ address: n, index:
|
|
22
|
-
this.setWalletIndex(
|
|
21
|
+
this.sdk = t, this.listeners = /* @__PURE__ */ new Map(), this.walletIndex = 0, this.currentAccounts = [], this.off = this.removeListener.bind(this), this.chainId = typeof s == "number" ? s : G(s), this.sdk.on("addressChanged", ({ address: n, index: d }) => {
|
|
22
|
+
this.setWalletIndex(d), this.notifyAccountsChanged([n]);
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
/** connector가 내부적으로 호출. 외부에서 사용하지 않습니다. */
|
|
@@ -38,7 +38,7 @@ class U {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
async _handleRequest(t, s) {
|
|
41
|
-
var
|
|
41
|
+
var d;
|
|
42
42
|
const n = s ?? [];
|
|
43
43
|
switch (t) {
|
|
44
44
|
case "eth_requestAccounts":
|
|
@@ -71,8 +71,8 @@ class U {
|
|
|
71
71
|
case "eth_signTypedData":
|
|
72
72
|
case "eth_signTypedData_v3":
|
|
73
73
|
case "eth_signTypedData_v4": {
|
|
74
|
-
const [, e] = n, r = typeof e == "string" ? JSON.parse(e) : e,
|
|
75
|
-
return (
|
|
74
|
+
const [, e] = n, r = typeof e == "string" ? JSON.parse(e) : e, o = (d = r == null ? void 0 : r.domain) == null ? void 0 : d.chainId, I = o == null || o === 0, f = I ? 0 : Number(o), m = { index: this.walletIndex };
|
|
75
|
+
return (I ? await this.sdk.signTypedDataOffchain(r, m) : await this.sdk.signTypedData(y(f), r, m)).signature;
|
|
76
76
|
}
|
|
77
77
|
case "eth_sendTransaction": {
|
|
78
78
|
const [e] = n, r = y(this.chainId);
|
|
@@ -109,7 +109,7 @@ class U {
|
|
|
109
109
|
}
|
|
110
110
|
emit(t, ...s) {
|
|
111
111
|
var n;
|
|
112
|
-
(n = this.listeners.get(t)) == null || n.forEach((
|
|
112
|
+
(n = this.listeners.get(t)) == null || n.forEach((d) => d(...s));
|
|
113
113
|
}
|
|
114
114
|
// ── Connector 전용 헬퍼 ───────────────────────────────────────────────────
|
|
115
115
|
notifyAccountsChanged(t) {
|
|
@@ -164,64 +164,67 @@ function D() {
|
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
166
|
function $(i) {
|
|
167
|
-
const { defaultChainId: t, getStoredWalletIndex: s, onWalletIndexChanged: n, openConnectOtherWallet:
|
|
168
|
-
|
|
167
|
+
const { defaultChainId: t, getStoredWalletIndex: s, onWalletIndexChanged: n, openConnectOtherWallet: d, ...e } = i;
|
|
168
|
+
if (d) {
|
|
169
|
+
const o = e.connectOtherWallets, I = Array.isArray(o) && o.length > 0, f = e.showConnectOtherWallets === !0;
|
|
170
|
+
!I && !f && (e.showConnectOtherWallets = !0);
|
|
171
|
+
}
|
|
169
172
|
const r = q(e);
|
|
170
|
-
return z({ sdk: r, defaultChainId: t, getStoredWalletIndex: s, onWalletIndexChanged: n, openConnectOtherWallet:
|
|
173
|
+
return z({ sdk: r, defaultChainId: t, getStoredWalletIndex: s, onWalletIndexChanged: n, openConnectOtherWallet: d });
|
|
171
174
|
}
|
|
172
175
|
function z(i) {
|
|
173
176
|
const {
|
|
174
177
|
sdk: t,
|
|
175
178
|
defaultChainId: s = R.CROSS_MAINNET,
|
|
176
179
|
getStoredWalletIndex: n = F,
|
|
177
|
-
onWalletIndexChanged:
|
|
180
|
+
onWalletIndexChanged: d = j,
|
|
178
181
|
openConnectOtherWallet: e
|
|
179
182
|
} = i, r = M(s);
|
|
180
|
-
let
|
|
183
|
+
let o = null, I = !1, f = !1, m = !1;
|
|
181
184
|
function l() {
|
|
182
|
-
return
|
|
185
|
+
return o || (o = new U(t, r), o._setWalletIndexChangeCallback(d)), o;
|
|
183
186
|
}
|
|
184
|
-
return
|
|
187
|
+
return N((u) => ({
|
|
185
188
|
id: "crossx",
|
|
186
189
|
name: "CROSSx Wallet",
|
|
187
190
|
type: "crossx",
|
|
188
191
|
async setup() {
|
|
189
|
-
if (!
|
|
190
|
-
const
|
|
191
|
-
await t.initialize({ preferredWalletIndex:
|
|
192
|
-
if (
|
|
192
|
+
if (!I) {
|
|
193
|
+
const C = n();
|
|
194
|
+
await t.initialize({ preferredWalletIndex: C }), I = !0, t.on("addressChanged", ({ address: a, index: g }) => {
|
|
195
|
+
if (f) return;
|
|
193
196
|
const p = l();
|
|
194
|
-
p.setWalletIndex(
|
|
197
|
+
p.setWalletIndex(g), a && p.notifyAccountsChanged([a]);
|
|
195
198
|
}), t.on("authChanged", (a) => {
|
|
196
|
-
if (!(
|
|
199
|
+
if (!(f || m))
|
|
197
200
|
if (a.isAuthenticated && a.address) {
|
|
198
|
-
const
|
|
199
|
-
|
|
201
|
+
const g = l();
|
|
202
|
+
g.notifyAccountsChanged([a.address]), u.emitter.emit("connect", {
|
|
200
203
|
accounts: [a.address],
|
|
201
|
-
chainId:
|
|
204
|
+
chainId: g.getCurrentChainId()
|
|
202
205
|
});
|
|
203
|
-
} else a.isAuthenticated || (l().notifyDisconnect(), D(),
|
|
206
|
+
} else a.isAuthenticated || (l().notifyDisconnect(), D(), d(0), u.emitter.emit("disconnect"));
|
|
204
207
|
}), e && t.on("connectExternalWallet", e);
|
|
205
208
|
}
|
|
206
209
|
const c = l();
|
|
207
210
|
c.on("accountsChanged", this.onAccountsChanged.bind(this)), c.on("chainChanged", this.onChainChanged.bind(this)), c.on("disconnect", this.onDisconnect.bind(this));
|
|
208
211
|
},
|
|
209
212
|
// ── connect ─────────────────────────────────────────────────────────────
|
|
210
|
-
async connect({ chainId: c, isReconnecting:
|
|
213
|
+
async connect({ chainId: c, isReconnecting: C } = {}) {
|
|
211
214
|
var p;
|
|
212
|
-
const a = l(),
|
|
213
|
-
|
|
215
|
+
const a = l(), g = c ?? r;
|
|
216
|
+
f = !0;
|
|
214
217
|
try {
|
|
215
|
-
if (
|
|
218
|
+
if (C || t.isAuthenticated()) {
|
|
216
219
|
const h = n();
|
|
217
220
|
if (t.isAuthenticated()) {
|
|
218
221
|
try {
|
|
219
222
|
const S = await t.getAddresses();
|
|
220
223
|
if (S.length > 0) {
|
|
221
|
-
const E = S.find((
|
|
224
|
+
const E = S.find((L) => L.index === h) ?? S[0];
|
|
222
225
|
return a.setWalletIndex(E.index), a.notifyAccountsChanged([E.address]), {
|
|
223
226
|
accounts: [E.address],
|
|
224
|
-
chainId:
|
|
227
|
+
chainId: g
|
|
225
228
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
226
229
|
};
|
|
227
230
|
}
|
|
@@ -231,43 +234,43 @@ function z(i) {
|
|
|
231
234
|
}), a.notifyDisconnect();
|
|
232
235
|
}
|
|
233
236
|
}
|
|
234
|
-
let
|
|
237
|
+
let w;
|
|
235
238
|
try {
|
|
236
|
-
|
|
239
|
+
w = await t.signInWithCreate();
|
|
237
240
|
} catch (h) {
|
|
238
|
-
throw h instanceof k && h.code === T.EXTERNAL_WALLET_REQUESTED ? (a.notifyDisconnect(), new
|
|
241
|
+
throw h instanceof k && h.code === T.EXTERNAL_WALLET_REQUESTED ? (a.notifyDisconnect(), new v(h)) : (t.isAuthenticated() || (a.notifyDisconnect(), u.emitter.emit("disconnect")), h);
|
|
239
242
|
}
|
|
240
|
-
if (!
|
|
241
|
-
throw new Error(
|
|
242
|
-
const x =
|
|
243
|
+
if (!w.success)
|
|
244
|
+
throw new Error(w.error ?? "CROSSx sign-in failed");
|
|
245
|
+
const x = w.address, O = w.addresses.map((h) => h.address).filter((h) => !x || h.toLowerCase() !== x.toLowerCase()), A = x ? [x, ...O] : O;
|
|
243
246
|
if (A.length === 0)
|
|
244
247
|
throw new Error("No address found after sign-in");
|
|
245
|
-
const P = ((p =
|
|
248
|
+
const P = ((p = w.addresses.find(
|
|
246
249
|
(h) => x && h.address.toLowerCase() === x.toLowerCase()
|
|
247
250
|
)) == null ? void 0 : p.index) ?? 0;
|
|
248
251
|
return a.setWalletIndex(P), a.notifyAccountsChanged(A), {
|
|
249
252
|
accounts: A,
|
|
250
|
-
chainId:
|
|
253
|
+
chainId: g
|
|
251
254
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
252
255
|
};
|
|
253
256
|
} finally {
|
|
254
|
-
|
|
257
|
+
f = !1;
|
|
255
258
|
}
|
|
256
259
|
},
|
|
257
260
|
// ── disconnect ──────────────────────────────────────────────────────────
|
|
258
261
|
async disconnect() {
|
|
259
|
-
|
|
262
|
+
m = !0;
|
|
260
263
|
try {
|
|
261
264
|
const c = l();
|
|
262
|
-
await t.signOut(), c.notifyDisconnect(), D(),
|
|
265
|
+
await t.signOut(), c.notifyDisconnect(), D(), d(0), u.emitter.emit("disconnect");
|
|
263
266
|
} finally {
|
|
264
|
-
|
|
267
|
+
m = !1;
|
|
265
268
|
}
|
|
266
269
|
},
|
|
267
270
|
// ── getAccounts ─────────────────────────────────────────────────────────
|
|
268
271
|
async getAccounts() {
|
|
269
|
-
const
|
|
270
|
-
if (
|
|
272
|
+
const C = l().getCurrentAccounts();
|
|
273
|
+
if (C.length > 0) return C;
|
|
271
274
|
const a = await t.getAddress();
|
|
272
275
|
return a ? [a.address] : [];
|
|
273
276
|
},
|
|
@@ -286,7 +289,7 @@ function z(i) {
|
|
|
286
289
|
// ── switchChain ─────────────────────────────────────────────────────────
|
|
287
290
|
async switchChain({ chainId: c }) {
|
|
288
291
|
l().setChainId(c), u.emitter.emit("change", { chainId: c });
|
|
289
|
-
const a = u.chains.find((
|
|
292
|
+
const a = u.chains.find((g) => g.id === c);
|
|
290
293
|
if (!a)
|
|
291
294
|
throw new Error(`Chain ${c} is not configured`);
|
|
292
295
|
return a;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexus-cross/crossx-sdk-wagmi",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1-beta.1",
|
|
4
4
|
"description": "CROSSx SDK wagmi Connector — OAuth 임베디드 지갑을 wagmi에 통합",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"dist"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@nexus-cross/crossx-sdk-core": "2.0.
|
|
20
|
+
"@nexus-cross/crossx-sdk-core": "2.0.1-beta.1"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"viem": ">=2.0.0",
|