@nexus-cross/crossx-sdk-wagmi 1.3.1 → 1.3.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.
- package/dist/connector.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +66 -65
- package/package.json +2 -2
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;CAChD;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;CAChD,CAAC;AAgCF,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,8GAI9D;AAID,wBAAgB,qBAAqB,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;CAChD;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;CAChD,CAAC;AAgCF,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,8GAI9D;AAID,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,8GAoNpE"}
|
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 v=require("wagmi"),D=require("viem"),f=require("@nexus-cross/crossx-sdk-core");function P(i){return parseInt(i.split(":")[1]??"1",10)}function y(i){return`eip155:${i}`}function E(i){return"0x"+i.toString(16)}function R(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 W{constructor(t,s=f.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:P(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 f.CROSSxError&&n.code===f.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 E(this.chainId);case"net_version":return String(this.chainId);case"personal_sign":{const[e]=n,r=e.startsWith("0x")?R(e):e;return(await this.sdk.signMessage(y(this.chainId),r,{index:this.walletIndex})).signature}case"eth_sign":{const[,e]=n,r=e.startsWith("0x")?R(e):e;return(await this.sdk.signMessage(y(this.chainId),r,{index:this.walletIndex})).signature}case"eth_signTypedData":case"eth_signTypedData_v3":case"eth_signTypedData_v4":{const[,e]=n,r=typeof e=="string"?JSON.parse(e):e,l=(o=r==null?void 0:r.domain)==null?void 0:o.chainId,I=l==null||l===0,u=I?0:Number(l),h={index:this.walletIndex};return(I?await this.sdk.signTypedDataOffchain(r,h):await this.sdk.signTypedData(y(u),r,h)).signature}case"eth_sendTransaction":{const[e]=n,r=y(this.chainId);return(await this.sdk.sendTransaction(r,{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,r=parseInt(e,16);return r!==this.chainId&&(this.chainId=r,this.emit("chainChanged",E(r))),null}case"wallet_addEthereumChain":return null;default:return this.sdk.walletRpc(t,n,y(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",E(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 N(i){return typeof i=="number"?i:parseInt(i.split(":")[1]??"1",10)}const _="crossx-wallet-index";function L(){try{const i=typeof window<"u"?localStorage.getItem(_):null;return i&&Number(i)||0}catch{return 0}}function q(i){try{typeof window<"u"&&localStorage.setItem(_,String(i))}catch{}}function G(){try{typeof window<"u"&&localStorage.removeItem(_)}catch{}}function M(i){const{defaultChainId:t,getStoredWalletIndex:s,onWalletIndexChanged:n,...o}=i,e=f.createCROSSxSDK(o);return b({sdk:e,defaultChainId:t,getStoredWalletIndex:s,onWalletIndexChanged:n})}function b(i){const{sdk:t,defaultChainId:s=f.ChainId.CROSS_MAINNET,getStoredWalletIndex:n=L,onWalletIndexChanged:o=q}=i,e=N(s);let r=null,l=!1,I=!1;function u(){return r||(r=new W(t,e),r._setWalletIndexChangeCallback(o)),r}return v.createConnector(h=>({id:"crossx",name:"CROSSx Wallet",type:"crossx",async setup(){if(!l){const g=n();await t.initialize({preferredWalletIndex:g}),l=!0,t.on("addressChanged",({address:c,index:C})=>{if(I)return;const m=u();m.setWalletIndex(C),c&&m.notifyAccountsChanged([c])})}const a=u();a.on("accountsChanged",this.onAccountsChanged.bind(this)),a.on("chainChanged",this.onChainChanged.bind(this)),a.on("disconnect",this.onDisconnect.bind(this))},async connect({chainId:a,isReconnecting:g}={}){var m;const c=u(),C=a??e;I=!0;try{if(g||t.isAuthenticated()){const d=n();if(t.isAuthenticated()){try{const S=await t.getAddresses();if(S.length>0){const A=S.find(T=>T.index===d)??S[0];return c.setWalletIndex(A.index),c.notifyAccountsChanged([A.address]),{accounts:[A.address],chainId:C}}}catch{}await t.signOut().catch(()=>{}),c.notifyDisconnect()}}let x;try{x=await t.signInWithCreate()}catch(d){throw d instanceof f.CROSSxError&&d.code===f.ErrorCode.EXTERNAL_WALLET_REQUESTED?(c.notifyDisconnect(),new D.UserRejectedRequestError(d)):(t.isAuthenticated()||(c.notifyDisconnect(),h.emitter.emit("disconnect")),d)}if(!x.success)throw new Error(x.error??"CROSSx sign-in failed");const w=x.address,O=x.addresses.map(d=>d.address).filter(d=>!w||d.toLowerCase()!==w.toLowerCase()),p=w?[w,...O]:O;if(p.length===0)throw new Error("No address found after sign-in");const k=((m=x.addresses.find(d=>w&&d.address.toLowerCase()===w.toLowerCase()))==null?void 0:m.index)??0;return c.setWalletIndex(k),c.notifyAccountsChanged(p),{accounts:p,chainId:C}}finally{I=!1}},async disconnect(){const a=u();await t.signOut(),a.notifyDisconnect(),G(),o(0),h.emitter.emit("disconnect")},async getAccounts(){const g=u().getCurrentAccounts();if(g.length>0)return g;const c=await t.getAddress();return c?[c.address]:[]},async getChainId(){return u().getCurrentChainId()},async getProvider({chainId:a}={}){return u()},async isAuthorized(){return await t.whenReady(),t.isAuthenticated()},async switchChain({chainId:a}){u().setChainId(a),h.emitter.emit("change",{chainId:a});const c=h.chains.find(C=>C.id===a);if(!c)throw new Error(`Chain ${a} is not configured`);return c},onAccountsChanged(a){a.length===0?h.emitter.emit("disconnect"):h.emitter.emit("change",{accounts:a})},onChainChanged(a){h.emitter.emit("change",{chainId:Number(a)})},onDisconnect(){h.emitter.emit("disconnect")}}))}exports.CROSSxEIP1193Provider=W;exports.createCROSSxConnector=b;exports.crossxConnector=M;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { createConnector as
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { createConnector as D } from "wagmi";
|
|
2
|
+
import { UserRejectedRequestError as v } from "viem";
|
|
3
|
+
import { ChainId as b, CROSSxError as R, ErrorCode as k, createCROSSxSDK as P } from "@nexus-cross/crossx-sdk-core";
|
|
4
|
+
function N(i) {
|
|
4
5
|
return parseInt(i.split(":")[1] ?? "1", 10);
|
|
5
6
|
}
|
|
6
7
|
function m(i) {
|
|
@@ -9,15 +10,15 @@ function m(i) {
|
|
|
9
10
|
function A(i) {
|
|
10
11
|
return "0x" + i.toString(16);
|
|
11
12
|
}
|
|
12
|
-
function
|
|
13
|
+
function W(i) {
|
|
13
14
|
const t = i.startsWith("0x") ? i.slice(2) : i, s = new Uint8Array(t.length / 2);
|
|
14
15
|
for (let n = 0; n < s.length; n++)
|
|
15
16
|
s[n] = parseInt(t.substring(n * 2, n * 2 + 2), 16);
|
|
16
17
|
return new TextDecoder().decode(s);
|
|
17
18
|
}
|
|
18
|
-
class
|
|
19
|
+
class L {
|
|
19
20
|
constructor(t, s = b.CROSS_MAINNET) {
|
|
20
|
-
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 :
|
|
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 : N(s), this.sdk.on("addressChanged", ({ address: n, index: o }) => {
|
|
21
22
|
this.setWalletIndex(o), this.notifyAccountsChanged([n]);
|
|
22
23
|
});
|
|
23
24
|
}
|
|
@@ -30,7 +31,7 @@ class N {
|
|
|
30
31
|
try {
|
|
31
32
|
return await this._handleRequest(t, s);
|
|
32
33
|
} catch (n) {
|
|
33
|
-
throw n instanceof
|
|
34
|
+
throw n instanceof R && n.code === k.USER_REJECTED ? Object.assign(
|
|
34
35
|
new Error("User rejected the request"),
|
|
35
36
|
{ code: 4001, data: n.details }
|
|
36
37
|
) : n;
|
|
@@ -52,30 +53,30 @@ class N {
|
|
|
52
53
|
case "net_version":
|
|
53
54
|
return String(this.chainId);
|
|
54
55
|
case "personal_sign": {
|
|
55
|
-
const [e] = n,
|
|
56
|
+
const [e] = n, r = e.startsWith("0x") ? W(e) : e;
|
|
56
57
|
return (await this.sdk.signMessage(
|
|
57
58
|
m(this.chainId),
|
|
58
|
-
|
|
59
|
+
r,
|
|
59
60
|
{ index: this.walletIndex }
|
|
60
61
|
)).signature;
|
|
61
62
|
}
|
|
62
63
|
case "eth_sign": {
|
|
63
|
-
const [, e] = n,
|
|
64
|
+
const [, e] = n, r = e.startsWith("0x") ? W(e) : e;
|
|
64
65
|
return (await this.sdk.signMessage(
|
|
65
66
|
m(this.chainId),
|
|
66
|
-
|
|
67
|
+
r,
|
|
67
68
|
{ index: this.walletIndex }
|
|
68
69
|
)).signature;
|
|
69
70
|
}
|
|
70
71
|
case "eth_signTypedData":
|
|
71
72
|
case "eth_signTypedData_v3":
|
|
72
73
|
case "eth_signTypedData_v4": {
|
|
73
|
-
const [, e] = n,
|
|
74
|
-
return (f ? await this.sdk.signTypedDataOffchain(
|
|
74
|
+
const [, e] = n, r = typeof e == "string" ? JSON.parse(e) : e, l = (o = r == null ? void 0 : r.domain) == null ? void 0 : o.chainId, f = l == null || l === 0, u = f ? 0 : Number(l), h = { index: this.walletIndex };
|
|
75
|
+
return (f ? await this.sdk.signTypedDataOffchain(r, h) : await this.sdk.signTypedData(m(u), r, h)).signature;
|
|
75
76
|
}
|
|
76
77
|
case "eth_sendTransaction": {
|
|
77
|
-
const [e] = n,
|
|
78
|
-
return (await this.sdk.sendTransaction(
|
|
78
|
+
const [e] = n, r = m(this.chainId);
|
|
79
|
+
return (await this.sdk.sendTransaction(r, {
|
|
79
80
|
from: e.from,
|
|
80
81
|
to: e.to,
|
|
81
82
|
value: e.value,
|
|
@@ -89,8 +90,8 @@ class N {
|
|
|
89
90
|
}, { index: this.walletIndex })).txHash;
|
|
90
91
|
}
|
|
91
92
|
case "wallet_switchEthereumChain": {
|
|
92
|
-
const [{ chainId: e }] = n,
|
|
93
|
-
return
|
|
93
|
+
const [{ chainId: e }] = n, r = parseInt(e, 16);
|
|
94
|
+
return r !== this.chainId && (this.chainId = r, this.emit("chainChanged", A(r))), null;
|
|
94
95
|
}
|
|
95
96
|
case "wallet_addEthereumChain":
|
|
96
97
|
return null;
|
|
@@ -138,32 +139,32 @@ class N {
|
|
|
138
139
|
return [...this.currentAccounts];
|
|
139
140
|
}
|
|
140
141
|
}
|
|
141
|
-
function
|
|
142
|
+
function q(i) {
|
|
142
143
|
return typeof i == "number" ? i : parseInt(i.split(":")[1] ?? "1", 10);
|
|
143
144
|
}
|
|
144
|
-
const
|
|
145
|
+
const E = "crossx-wallet-index";
|
|
145
146
|
function G() {
|
|
146
147
|
try {
|
|
147
|
-
const i = typeof window < "u" ? localStorage.getItem(
|
|
148
|
+
const i = typeof window < "u" ? localStorage.getItem(E) : null;
|
|
148
149
|
return i && Number(i) || 0;
|
|
149
150
|
} catch {
|
|
150
151
|
return 0;
|
|
151
152
|
}
|
|
152
153
|
}
|
|
153
|
-
function
|
|
154
|
+
function U(i) {
|
|
154
155
|
try {
|
|
155
|
-
typeof window < "u" && localStorage.setItem(
|
|
156
|
+
typeof window < "u" && localStorage.setItem(E, String(i));
|
|
156
157
|
} catch {
|
|
157
158
|
}
|
|
158
159
|
}
|
|
159
160
|
function M() {
|
|
160
161
|
try {
|
|
161
|
-
typeof window < "u" && localStorage.removeItem(
|
|
162
|
+
typeof window < "u" && localStorage.removeItem(E);
|
|
162
163
|
} catch {
|
|
163
164
|
}
|
|
164
165
|
}
|
|
165
|
-
function
|
|
166
|
-
const { defaultChainId: t, getStoredWalletIndex: s, onWalletIndexChanged: n, ...o } = i, e =
|
|
166
|
+
function J(i) {
|
|
167
|
+
const { defaultChainId: t, getStoredWalletIndex: s, onWalletIndexChanged: n, ...o } = i, e = P(o);
|
|
167
168
|
return F({ sdk: e, defaultChainId: t, getStoredWalletIndex: s, onWalletIndexChanged: n });
|
|
168
169
|
}
|
|
169
170
|
function F(i) {
|
|
@@ -171,41 +172,41 @@ function F(i) {
|
|
|
171
172
|
sdk: t,
|
|
172
173
|
defaultChainId: s = b.CROSS_MAINNET,
|
|
173
174
|
getStoredWalletIndex: n = G,
|
|
174
|
-
onWalletIndexChanged: o =
|
|
175
|
-
} = i, e =
|
|
176
|
-
let
|
|
177
|
-
function
|
|
178
|
-
return
|
|
175
|
+
onWalletIndexChanged: o = U
|
|
176
|
+
} = i, e = q(s);
|
|
177
|
+
let r = null, l = !1, f = !1;
|
|
178
|
+
function u() {
|
|
179
|
+
return r || (r = new L(t, e), r._setWalletIndexChangeCallback(o)), r;
|
|
179
180
|
}
|
|
180
|
-
return
|
|
181
|
+
return D((h) => ({
|
|
181
182
|
id: "crossx",
|
|
182
183
|
name: "CROSSx Wallet",
|
|
183
184
|
type: "crossx",
|
|
184
185
|
async setup() {
|
|
185
|
-
if (!
|
|
186
|
+
if (!l) {
|
|
186
187
|
const g = n();
|
|
187
|
-
await t.initialize({ preferredWalletIndex: g }),
|
|
188
|
+
await t.initialize({ preferredWalletIndex: g }), l = !0, t.on("addressChanged", ({ address: c, index: I }) => {
|
|
188
189
|
if (f) return;
|
|
189
|
-
const w =
|
|
190
|
+
const w = u();
|
|
190
191
|
w.setWalletIndex(I), c && w.notifyAccountsChanged([c]);
|
|
191
192
|
});
|
|
192
193
|
}
|
|
193
|
-
const
|
|
194
|
-
|
|
194
|
+
const a = u();
|
|
195
|
+
a.on("accountsChanged", this.onAccountsChanged.bind(this)), a.on("chainChanged", this.onChainChanged.bind(this)), a.on("disconnect", this.onDisconnect.bind(this));
|
|
195
196
|
},
|
|
196
197
|
// ── connect ─────────────────────────────────────────────────────────────
|
|
197
|
-
async connect({ chainId:
|
|
198
|
+
async connect({ chainId: a, isReconnecting: g } = {}) {
|
|
198
199
|
var w;
|
|
199
|
-
const c =
|
|
200
|
+
const c = u(), I = a ?? e;
|
|
200
201
|
f = !0;
|
|
201
202
|
try {
|
|
202
203
|
if (g || t.isAuthenticated()) {
|
|
203
|
-
const
|
|
204
|
+
const d = n();
|
|
204
205
|
if (t.isAuthenticated()) {
|
|
205
206
|
try {
|
|
206
207
|
const y = await t.getAddresses();
|
|
207
208
|
if (y.length > 0) {
|
|
208
|
-
const S = y.find((
|
|
209
|
+
const S = y.find((T) => T.index === d) ?? y[0];
|
|
209
210
|
return c.setWalletIndex(S.index), c.notifyAccountsChanged([S.address]), {
|
|
210
211
|
accounts: [S.address],
|
|
211
212
|
chainId: I
|
|
@@ -221,18 +222,18 @@ function F(i) {
|
|
|
221
222
|
let C;
|
|
222
223
|
try {
|
|
223
224
|
C = await t.signInWithCreate();
|
|
224
|
-
} catch (
|
|
225
|
-
throw t.isAuthenticated() || (c.notifyDisconnect(),
|
|
225
|
+
} catch (d) {
|
|
226
|
+
throw d instanceof R && d.code === k.EXTERNAL_WALLET_REQUESTED ? (c.notifyDisconnect(), new v(d)) : (t.isAuthenticated() || (c.notifyDisconnect(), h.emitter.emit("disconnect")), d);
|
|
226
227
|
}
|
|
227
228
|
if (!C.success)
|
|
228
229
|
throw new Error(C.error ?? "CROSSx sign-in failed");
|
|
229
|
-
const x = C.address,
|
|
230
|
+
const x = C.address, _ = C.addresses.map((d) => d.address).filter((d) => !x || d.toLowerCase() !== x.toLowerCase()), p = x ? [x, ..._] : _;
|
|
230
231
|
if (p.length === 0)
|
|
231
232
|
throw new Error("No address found after sign-in");
|
|
232
|
-
const
|
|
233
|
-
(
|
|
233
|
+
const O = ((w = C.addresses.find(
|
|
234
|
+
(d) => x && d.address.toLowerCase() === x.toLowerCase()
|
|
234
235
|
)) == null ? void 0 : w.index) ?? 0;
|
|
235
|
-
return c.setWalletIndex(
|
|
236
|
+
return c.setWalletIndex(O), c.notifyAccountsChanged(p), {
|
|
236
237
|
accounts: p,
|
|
237
238
|
chainId: I
|
|
238
239
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -243,54 +244,54 @@ function F(i) {
|
|
|
243
244
|
},
|
|
244
245
|
// ── disconnect ──────────────────────────────────────────────────────────
|
|
245
246
|
async disconnect() {
|
|
246
|
-
const
|
|
247
|
-
await t.signOut(),
|
|
247
|
+
const a = u();
|
|
248
|
+
await t.signOut(), a.notifyDisconnect(), M(), o(0), h.emitter.emit("disconnect");
|
|
248
249
|
},
|
|
249
250
|
// ── getAccounts ─────────────────────────────────────────────────────────
|
|
250
251
|
async getAccounts() {
|
|
251
|
-
const g =
|
|
252
|
+
const g = u().getCurrentAccounts();
|
|
252
253
|
if (g.length > 0) return g;
|
|
253
254
|
const c = await t.getAddress();
|
|
254
255
|
return c ? [c.address] : [];
|
|
255
256
|
},
|
|
256
257
|
// ── getChainId ──────────────────────────────────────────────────────────
|
|
257
258
|
async getChainId() {
|
|
258
|
-
return
|
|
259
|
+
return u().getCurrentChainId();
|
|
259
260
|
},
|
|
260
261
|
// ── getProvider ─────────────────────────────────────────────────────────
|
|
261
|
-
async getProvider({ chainId:
|
|
262
|
-
return
|
|
262
|
+
async getProvider({ chainId: a } = {}) {
|
|
263
|
+
return u();
|
|
263
264
|
},
|
|
264
265
|
// ── isAuthorized ────────────────────────────────────────────────────────
|
|
265
266
|
async isAuthorized() {
|
|
266
267
|
return await t.whenReady(), t.isAuthenticated();
|
|
267
268
|
},
|
|
268
269
|
// ── switchChain ─────────────────────────────────────────────────────────
|
|
269
|
-
async switchChain({ chainId:
|
|
270
|
-
|
|
271
|
-
const c =
|
|
270
|
+
async switchChain({ chainId: a }) {
|
|
271
|
+
u().setChainId(a), h.emitter.emit("change", { chainId: a });
|
|
272
|
+
const c = h.chains.find((I) => I.id === a);
|
|
272
273
|
if (!c)
|
|
273
|
-
throw new Error(`Chain ${
|
|
274
|
+
throw new Error(`Chain ${a} is not configured`);
|
|
274
275
|
return c;
|
|
275
276
|
},
|
|
276
277
|
// ── 이벤트 핸들러 ───────────────────────────────────────────────────────
|
|
277
|
-
onAccountsChanged(
|
|
278
|
-
|
|
279
|
-
accounts:
|
|
278
|
+
onAccountsChanged(a) {
|
|
279
|
+
a.length === 0 ? h.emitter.emit("disconnect") : h.emitter.emit("change", {
|
|
280
|
+
accounts: a
|
|
280
281
|
});
|
|
281
282
|
},
|
|
282
|
-
onChainChanged(
|
|
283
|
-
|
|
284
|
-
chainId: Number(
|
|
283
|
+
onChainChanged(a) {
|
|
284
|
+
h.emitter.emit("change", {
|
|
285
|
+
chainId: Number(a)
|
|
285
286
|
});
|
|
286
287
|
},
|
|
287
288
|
onDisconnect() {
|
|
288
|
-
|
|
289
|
+
h.emitter.emit("disconnect");
|
|
289
290
|
}
|
|
290
291
|
}));
|
|
291
292
|
}
|
|
292
293
|
export {
|
|
293
|
-
|
|
294
|
+
L as CROSSxEIP1193Provider,
|
|
294
295
|
F as createCROSSxConnector,
|
|
295
|
-
|
|
296
|
+
J as crossxConnector
|
|
296
297
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexus-cross/crossx-sdk-wagmi",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.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": "1.3.
|
|
20
|
+
"@nexus-cross/crossx-sdk-core": "1.3.2"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"viem": ">=2.0.0",
|