@nexus-cross/crossx-sdk-wagmi 2.0.0 → 2.0.1-beta.2

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,10 +10,10 @@ export interface CROSSxConnectorOptions {
10
10
  /** 활성 지갑 인덱스 변경 시 호출되는 콜백. 미설정 시 localStorage 자동 사용. */
11
11
  onWalletIndexChanged?: (index: number) => void;
12
12
  /**
13
- * 로그인 모달에서 "Connect with Other Wallets" 클릭 시 호출되는 콜백.
13
+ * 로그인 모달에서 외부 지갑 클릭 시 호출되는 콜백.
14
14
  *
15
- * 제공 시 SDK `connectExternalWallet` 이벤트에 자동 등록됩니다.
16
- * DApp에서 콜백으로 wagmi 외부 지갑 연결 UI를 열어주세요.
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
- * 로그인 모달에서 "Connect with Other Wallets" 클릭 시 호출되는 콜백.
34
+ * 로그인 모달에서 외부 지갑 클릭 시 호출되는 콜백.
35
35
  *
36
- * 제공 시 `showConnectOtherWallets: true`가 자동 적용되며,
36
+ * 제공 시 `showConnectOtherWallets`·`connectOtherWallets`가 없으면 `showConnectOtherWallets: true`가 자동 적용되며,
37
37
  * SDK의 `connectExternalWallet` 이벤트에 자동 등록됩니다.
38
- * 별도로 `showConnectOtherWallets`를 설정하거나 이벤트 리스너를 등록할 필요가 없습니다.
38
+ * 일부 지갑만 쓰려면 `connectOtherWallets: [ ... ]`로 좁히면 됩니다.
39
39
  *
40
40
  * @example
41
41
  * crossxConnector({
@@ -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,8GAS9D;AAID,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,8GAqPpE"}
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 N=require("wagmi"),L=require("viem"),C=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=C.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:o})=>{this.setWalletIndex(o),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 C.CROSSxError&&n.code===C.ErrorCode.USER_REJECTED?Object.assign(new Error("User rejected the request"),{code:4001,data:n.details}):n}}async _handleRequest(t,s){var o;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,d=(o=a==null?void 0:a.domain)==null?void 0:o.chainId,y=d==null||d===0,I=y?0:Number(d),x={index:this.walletIndex};return(y?await this.sdk.signTypedDataOffchain(a,x):await this.sdk.signTypedData(S(I),a,x)).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(o=>o(...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:o,...e}=i;o&&(e.showConnectOtherWallets=!0);const a=C.createCROSSxSDK(e);return T({sdk:a,defaultChainId:t,getStoredWalletIndex:s,onWalletIndexChanged:n,openConnectOtherWallet:o})}function T(i){const{sdk:t,defaultChainId:s=C.ChainId.CROSS_MAINNET,getStoredWalletIndex:n=M,onWalletIndexChanged:o=U,openConnectOtherWallet:e}=i,a=G(s);let d=null,y=!1,I=!1,x=!1;function l(){return d||(d=new D(t,a),d._setWalletIndexChangeCallback(o)),d}return N.createConnector(u=>({id:"crossx",name:"CROSSx Wallet",type:"crossx",async setup(){if(!y){const f=n();await t.initialize({preferredWalletIndex:f}),y=!0,t.on("addressChanged",({address:r,index:g})=>{if(I)return;const p=l();p.setWalletIndex(g),r&&p.notifyAccountsChanged([r])}),t.on("authChanged",r=>{if(!(I||x))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(),o(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:f}={}){var p;const r=l(),g=c??a;I=!0;try{if(f||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 w;try{w=await t.signInWithCreate()}catch(h){throw h instanceof C.CROSSxError&&h.code===C.ErrorCode.EXTERNAL_WALLET_REQUESTED?(r.notifyDisconnect(),new L.UserRejectedRequestError(h)):(t.isAuthenticated()||(r.notifyDisconnect(),u.emitter.emit("disconnect")),h)}if(!w.success)throw new Error(w.error??"CROSSx sign-in failed");const m=w.address,R=w.addresses.map(h=>h.address).filter(h=>!m||h.toLowerCase()!==m.toLowerCase()),A=m?[m,...R]:R;if(A.length===0)throw new Error("No address found after sign-in");const P=((p=w.addresses.find(h=>m&&h.address.toLowerCase()===m.toLowerCase()))==null?void 0:p.index)??0;return r.setWalletIndex(P),r.notifyAccountsChanged(A),{accounts:A,chainId:g}}finally{I=!1}},async disconnect(){x=!0;try{const c=l();await t.signOut(),c.notifyDisconnect(),k(),o(0),u.emitter.emit("disconnect")}finally{x=!1}},async getAccounts(){const f=l().getCurrentAccounts();if(f.length>0)return f;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;
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 v } from "wagmi";
2
- import { UserRejectedRequestError as L } from "viem";
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: o }) => {
22
- this.setWalletIndex(o), this.notifyAccountsChanged([n]);
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 o;
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, d = (o = r == null ? void 0 : r.domain) == null ? void 0 : o.chainId, w = d == null || d === 0, I = w ? 0 : Number(d), C = { index: this.walletIndex };
75
- return (w ? await this.sdk.signTypedDataOffchain(r, C) : await this.sdk.signTypedData(y(I), r, C)).signature;
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((o) => o(...s));
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: o, ...e } = i;
168
- o && (e.showConnectOtherWallets = !0);
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: o });
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: o = j,
180
+ onWalletIndexChanged: d = j,
178
181
  openConnectOtherWallet: e
179
182
  } = i, r = M(s);
180
- let d = null, w = !1, I = !1, C = !1;
183
+ let o = null, I = !1, f = !1, m = !1;
181
184
  function l() {
182
- return d || (d = new U(t, r), d._setWalletIndexChangeCallback(o)), d;
185
+ return o || (o = new U(t, r), o._setWalletIndexChangeCallback(d)), o;
183
186
  }
184
- return v((u) => ({
187
+ return N((u) => ({
185
188
  id: "crossx",
186
189
  name: "CROSSx Wallet",
187
190
  type: "crossx",
188
191
  async setup() {
189
- if (!w) {
190
- const g = n();
191
- await t.initialize({ preferredWalletIndex: g }), w = !0, t.on("addressChanged", ({ address: a, index: f }) => {
192
- if (I) return;
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(f), a && p.notifyAccountsChanged([a]);
197
+ p.setWalletIndex(g), a && p.notifyAccountsChanged([a]);
195
198
  }), t.on("authChanged", (a) => {
196
- if (!(I || C))
199
+ if (!(f || m))
197
200
  if (a.isAuthenticated && a.address) {
198
- const f = l();
199
- f.notifyAccountsChanged([a.address]), u.emitter.emit("connect", {
201
+ const g = l();
202
+ g.notifyAccountsChanged([a.address]), u.emitter.emit("connect", {
200
203
  accounts: [a.address],
201
- chainId: f.getCurrentChainId()
204
+ chainId: g.getCurrentChainId()
202
205
  });
203
- } else a.isAuthenticated || (l().notifyDisconnect(), D(), o(0), u.emitter.emit("disconnect"));
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: g } = {}) {
213
+ async connect({ chainId: c, isReconnecting: C } = {}) {
211
214
  var p;
212
- const a = l(), f = c ?? r;
213
- I = !0;
215
+ const a = l(), g = c ?? r;
216
+ f = !0;
214
217
  try {
215
- if (g || t.isAuthenticated()) {
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((N) => N.index === h) ?? S[0];
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: f
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 m;
237
+ let w;
235
238
  try {
236
- m = await t.signInWithCreate();
239
+ w = await t.signInWithCreate();
237
240
  } catch (h) {
238
- throw h instanceof k && h.code === T.EXTERNAL_WALLET_REQUESTED ? (a.notifyDisconnect(), new L(h)) : (t.isAuthenticated() || (a.notifyDisconnect(), u.emitter.emit("disconnect")), h);
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 (!m.success)
241
- throw new Error(m.error ?? "CROSSx sign-in failed");
242
- const x = m.address, O = m.addresses.map((h) => h.address).filter((h) => !x || h.toLowerCase() !== x.toLowerCase()), A = x ? [x, ...O] : O;
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 = m.addresses.find(
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: f
253
+ chainId: g
251
254
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
252
255
  };
253
256
  } finally {
254
- I = !1;
257
+ f = !1;
255
258
  }
256
259
  },
257
260
  // ── disconnect ──────────────────────────────────────────────────────────
258
261
  async disconnect() {
259
- C = !0;
262
+ m = !0;
260
263
  try {
261
264
  const c = l();
262
- await t.signOut(), c.notifyDisconnect(), D(), o(0), u.emitter.emit("disconnect");
265
+ await t.signOut(), c.notifyDisconnect(), D(), d(0), u.emitter.emit("disconnect");
263
266
  } finally {
264
- C = !1;
267
+ m = !1;
265
268
  }
266
269
  },
267
270
  // ── getAccounts ─────────────────────────────────────────────────────────
268
271
  async getAccounts() {
269
- const g = l().getCurrentAccounts();
270
- if (g.length > 0) return g;
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((f) => f.id === c);
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.0",
3
+ "version": "2.0.1-beta.2",
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.0"
20
+ "@nexus-cross/crossx-sdk-core": "2.0.1-beta.2"
21
21
  },
22
22
  "peerDependencies": {
23
23
  "viem": ">=2.0.0",