@gluwa/connect-kit 0.1.0-next.3 → 0.2.0-next.10

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.
Files changed (104) hide show
  1. package/CHANGELOG.md +68 -0
  2. package/assets/fonts/Inter-Medium.ttf +0 -0
  3. package/assets/fonts/Inter-Medium.woff2 +0 -0
  4. package/assets/fonts/Inter-Regular.ttf +0 -0
  5. package/assets/fonts/Inter-Regular.woff2 +0 -0
  6. package/assets/fonts/Inter-SemiBold.ttf +0 -0
  7. package/assets/fonts/Inter-SemiBold.woff2 +0 -0
  8. package/assets/graphic.png +0 -0
  9. package/assets/metamask.png +0 -0
  10. package/assets/penguinwallet.png +0 -0
  11. package/assets/wc-logo.svg +3 -0
  12. package/assets/wc-search.png +0 -0
  13. package/dist/chunk-VE5LB7BN.js +405 -0
  14. package/dist/credit-connect.js +2 -394
  15. package/dist/index.css +2075 -0
  16. package/dist/index.d.ts +58 -33
  17. package/dist/index.js +1748 -1503
  18. package/dist/package.json +16 -10
  19. package/package.json +14 -11
  20. package/src/ConnectKitProvider.tsx +133 -75
  21. package/src/api/account.ts +21 -0
  22. package/src/api/asset.ts +10 -0
  23. package/src/api/balance.ts +10 -0
  24. package/src/api/chain.ts +17 -0
  25. package/src/api/contract.ts +33 -0
  26. package/src/api/transaction.ts +12 -0
  27. package/src/assets.d.ts +5 -0
  28. package/src/components/actionItem/index.tsx +50 -0
  29. package/src/components/actionItem/style.scss +47 -0
  30. package/src/components/copyLink/index.tsx +16 -0
  31. package/src/components/copyLink/style.scss +16 -0
  32. package/src/components/qrArea/index.tsx +72 -0
  33. package/src/components/qrArea/style.scss +122 -0
  34. package/src/components/searchBar/asset/Search.tsx +20 -0
  35. package/src/components/searchBar/asset/XMarkCircle.tsx +24 -0
  36. package/src/components/searchBar/index.tsx +44 -0
  37. package/src/components/searchBar/style.scss +58 -0
  38. package/src/components/toast/index.tsx +41 -0
  39. package/src/components/toast/style.scss +108 -0
  40. package/src/components/toggle/index.tsx +27 -0
  41. package/src/components/toggle/style.scss +53 -0
  42. package/src/components/walletGrid/index.tsx +64 -0
  43. package/src/components/walletGrid/style.scss +108 -0
  44. package/src/components/walletItem/index.tsx +49 -0
  45. package/src/components/walletItem/style.scss +70 -0
  46. package/src/connector-meta.ts +16 -11
  47. package/src/core/config.ts +102 -0
  48. package/src/creditConnectConnector.ts +198 -184
  49. package/src/events/account.ts +76 -0
  50. package/src/hooks/useConnectBanner.ts +79 -0
  51. package/src/hooks/useConnectTimeout.ts +92 -0
  52. package/src/hooks/useMetaMaskExtension.ts +29 -0
  53. package/src/hooks/useWCState.ts +45 -14
  54. package/src/hooks/useWagmiConnect.ts +42 -11
  55. package/src/index.ts +38 -2
  56. package/src/layout/allWallets/index.tsx +52 -0
  57. package/src/layout/allWallets/style.scss +57 -0
  58. package/src/layout/connectDialog/asset/backIcon.tsx +24 -0
  59. package/src/layout/connectDialog/asset/checkIcon.tsx +28 -0
  60. package/src/layout/connectDialog/asset/closeIcon.tsx +21 -0
  61. package/src/layout/connectDialog/asset/copyIcon.tsx +28 -0
  62. package/src/layout/connectDialog/asset/linkIcon.tsx +24 -0
  63. package/src/layout/connectDialog/asset/spinner.tsx +21 -0
  64. package/src/layout/connectDialog/asset/warningIcon.tsx +21 -0
  65. package/src/layout/connectDialog/idle/assets/banner-placeholder.png +0 -0
  66. package/src/layout/connectDialog/idle/index.tsx +55 -0
  67. package/src/layout/connectDialog/idle/style.scss +52 -0
  68. package/src/layout/connectDialog/index.tsx +432 -0
  69. package/src/layout/connectDialog/loading/index.tsx +13 -0
  70. package/src/layout/connectDialog/loading/style.scss +19 -0
  71. package/src/layout/connectDialog/metaMask/index.tsx +61 -0
  72. package/src/layout/connectDialog/metaMask/style.scss +65 -0
  73. package/src/layout/connectDialog/qr/index.tsx +33 -0
  74. package/src/layout/connectDialog/style.scss +48 -0
  75. package/src/layout/connectDialog/timeout/index.tsx +31 -0
  76. package/src/layout/connectDialog/timeout/style.scss +64 -0
  77. package/src/layout/connectDialog/walletConnect/index.tsx +45 -0
  78. package/src/layout/connectDialog/walletConnect/style.scss +48 -0
  79. package/src/layout/connectDialog/walletQR/index.tsx +37 -0
  80. package/src/layout/detailPanel/index.tsx +175 -0
  81. package/src/layout/detailPanel/style.scss +70 -0
  82. package/src/layout/selectorPanel/index.tsx +100 -0
  83. package/src/layout/selectorPanel/style.scss +113 -0
  84. package/src/style/color.scss +417 -0
  85. package/src/style/font.scss +28 -0
  86. package/src/style/index.scss +5 -0
  87. package/src/style/mixin.scss +217 -0
  88. package/src/style/reset.scss +110 -0
  89. package/src/style/variables.scss +13 -0
  90. package/src/types.ts +40 -7
  91. package/src/utils/platform.ts +6 -7
  92. package/src/wallet-display-override.ts +15 -0
  93. package/tsconfig.json +5 -1
  94. package/tsup.config.ts +32 -2
  95. package/assets/creditwallet.png +0 -0
  96. package/dist/chunk-DDA6FP6U.js +0 -7
  97. package/src/ConnectModal.scss +0 -665
  98. package/src/ConnectModal.tsx +0 -559
  99. package/src/components/QRFrame.tsx +0 -43
  100. package/src/views/CreditWalletView.tsx +0 -59
  101. package/src/views/IdleView.tsx +0 -10
  102. package/src/views/MetaMaskView.tsx +0 -64
  103. package/src/views/SwitchChainView.tsx +0 -67
  104. package/src/views/WalletConnectView.tsx +0 -206
package/CHANGELOG.md CHANGED
@@ -1,5 +1,73 @@
1
1
  # @gluwa/wallet-kit
2
2
 
3
+ ## 0.2.0-next.10
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [0b7cf10]
8
+ - @gluwa/credit-connect-sdk@0.2.0-next.5
9
+ - @gluwa/credit-connect-e2ee-tweetnacl@0.2.0-next.5
10
+ - @gluwa/credit-connect-hub-node-ws@0.1.0-next.5
11
+ - @gluwa/credit-connect-storage-local@0.2.0-next.5
12
+
13
+ ## 0.2.0-next.9
14
+
15
+ ### Patch Changes
16
+
17
+ - 18e631a: fix bugs
18
+
19
+ ## 0.2.0-next.8
20
+
21
+ ### Patch Changes
22
+
23
+ - e3789b4: emit OnSessionExpired when credit-connect QR session times out
24
+ - Updated dependencies [e3789b4]
25
+ - @gluwa/credit-connect-hub-node-ws@0.1.0-next.4
26
+ - @gluwa/credit-connect-sdk@0.2.0-next.4
27
+ - @gluwa/credit-connect-e2ee-tweetnacl@0.2.0-next.4
28
+ - @gluwa/credit-connect-storage-local@0.2.0-next.4
29
+
30
+ ## 0.2.0-next.7
31
+
32
+ ### Patch Changes
33
+
34
+ - 343c6ef: change UI wallet name credit wallet -> penguinWallet
35
+
36
+ ## 0.2.0-next.6
37
+
38
+ ### Patch Changes
39
+
40
+ - a9bbec9: enhance reconnect logic with auto-connect for injected connectors
41
+
42
+ ## 0.2.0-next.5
43
+
44
+ ### Patch Changes
45
+
46
+ - d3d52e9: fix: react version paths
47
+
48
+ ## 0.2.0-next.4
49
+
50
+ ### Patch Changes
51
+
52
+ - ed8effc: add watchAsset
53
+
54
+ ## 0.2.0-next.3
55
+
56
+ ### Patch Changes
57
+
58
+ - fb3f3c4: support connect-kit
59
+ - Updated dependencies [fb3f3c4]
60
+ - @gluwa/credit-connect-hub-node-ws@0.1.0-next.3
61
+ - @gluwa/credit-connect-sdk@0.2.0-next.3
62
+ - @gluwa/credit-connect-e2ee-tweetnacl@0.2.0-next.3
63
+ - @gluwa/credit-connect-storage-local@0.2.0-next.3
64
+
65
+ ## 0.2.0-next.1
66
+
67
+ ### Patch Changes
68
+
69
+ - ee79ef9: 0.2.0
70
+
3
71
  ## 0.1.0-next.3
4
72
 
5
73
  ### Patch Changes
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,3 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 96 96" fill="none">
2
+ <path fill="#3396FF" d="M24.534 34.2c13.01-12.749 34.11-12.749 47.12 0l1.565 1.534a1.607 1.607 0 0 1 0 2.302l-5.355 5.247a.845.845 0 0 1-1.177 0l-2.154-2.11c-9.077-8.896-23.796-8.896-32.874 0l-2.308 2.262a.845.845 0 0 1-1.177 0l-5.354-5.247a1.607 1.607 0 0 1 0-2.302l1.714-1.686zm58.195 10.85 4.763 4.668a1.607 1.607 0 0 1 0 2.302L66.024 73.389a1.69 1.69 0 0 1-2.354 0L48.588 58.706a.422.422 0 0 0-.588 0L32.918 73.389a1.69 1.69 0 0 1-2.354 0L9.096 52.02a1.607 1.607 0 0 1 0-2.302l4.763-4.668a1.69 1.69 0 0 1 2.354 0l15.083 14.683a.422.422 0 0 0 .588 0l15.082-14.683a1.69 1.69 0 0 1 2.354 0l15.083 14.683a.422.422 0 0 0 .588 0L79.375 45.05a1.69 1.69 0 0 1 2.354 0z"/>
3
+ </svg>
Binary file
@@ -0,0 +1,405 @@
1
+ import React from "react";
2
+ var __defProp = Object.defineProperty;
3
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
+
5
+ // src/creditConnectConnector.ts
6
+ import { createConnector } from "@wagmi/core";
7
+ import { getAddress } from "viem";
8
+ import { DappSessionManager } from "@gluwa/credit-connect-sdk/dapp";
9
+ var CONNECTOR_ID = "credit-connect";
10
+ var CONNECTOR_NAME = "Credit Wallet";
11
+ var CONNECTOR_TYPE = "credit-connect";
12
+ var castConnectResult = /* @__PURE__ */ __name((value) => value, "castConnectResult");
13
+ var creditConnectConnector = /* @__PURE__ */ __name((options) => {
14
+ let manager = null;
15
+ let selectedChainId = null;
16
+ let connectPromise = null;
17
+ let provider = null;
18
+ let providerPromise = null;
19
+ let isLocalDisconnect = false;
20
+ let emitWagmiMessage = null;
21
+ let emitWagmiDisconnect = null;
22
+ const providerListeners = /* @__PURE__ */ new Map();
23
+ const emitProviderEvent = /* @__PURE__ */ __name((event, ...args) => {
24
+ const listeners = providerListeners.get(event);
25
+ if (listeners) for (const fn of listeners) fn(...args);
26
+ }, "emitProviderEvent");
27
+ const getCurrentSession = /* @__PURE__ */ __name(() => {
28
+ if (!manager || manager.state.status !== "CONNECTED" || !manager.state.session) return null;
29
+ return manager.state.session;
30
+ }, "getCurrentSession");
31
+ const getEvmAddressInfo = /* @__PURE__ */ __name((session) => session.addressInfoList.filter((info) => info.networkType === "eip155"), "getEvmAddressInfo");
32
+ const getChecksummedAccounts = /* @__PURE__ */ __name((session) => getEvmAddressInfo(session).map((info) => getAddress(info.address)), "getChecksummedAccounts");
33
+ const resetState = /* @__PURE__ */ __name(() => {
34
+ connectPromise = null;
35
+ selectedChainId = null;
36
+ }, "resetState");
37
+ const createManagerIfNeeded = /* @__PURE__ */ __name(() => {
38
+ if (manager) return manager;
39
+ manager = new DappSessionManager({
40
+ projectKey: options.projectKey,
41
+ serverUrl: options.serverUrl,
42
+ storage: options.storage,
43
+ e2ee: options.e2ee,
44
+ createHub: options.createHub,
45
+ enableReconnect: true,
46
+ autoInit: true
47
+ });
48
+ manager.on("changeState", (state) => {
49
+ var _a;
50
+ console.log("[CC connector] manager state \u2192", state.status, {
51
+ hasConnectingPayload: Boolean(state.connectingPayload),
52
+ hasSession: "session" in state && Boolean(state.session)
53
+ });
54
+ if (state.status === "CONNECTING" && state.connectingPayload) {
55
+ console.log("[CC connector] emit display_uri", {
56
+ payloadPrefix: state.connectingPayload.slice(0, 80)
57
+ });
58
+ (_a = options.onDisplayUri) == null ? void 0 : _a.call(options, state.connectingPayload);
59
+ emitWagmiMessage == null ? void 0 : emitWagmiMessage("display_uri", state.connectingPayload);
60
+ }
61
+ if (state.status === "DISCONNECTED" && !isLocalDisconnect) {
62
+ console.log("[CC connector] DISCONNECTED (non-local) \u2192 resetState + emit");
63
+ resetState();
64
+ emitProviderEvent("disconnect");
65
+ emitWagmiDisconnect == null ? void 0 : emitWagmiDisconnect();
66
+ }
67
+ });
68
+ manager.on("sessionExpired", (payload) => {
69
+ console.log("[CC connector] session expired \u2192 emit session_expired", payload);
70
+ emitWagmiMessage == null ? void 0 : emitWagmiMessage("session_expired", payload);
71
+ });
72
+ return manager;
73
+ }, "createManagerIfNeeded");
74
+ const ensureManagerInitialized = /* @__PURE__ */ __name(async () => {
75
+ const m = createManagerIfNeeded();
76
+ if (m.state.status === "PENDING") {
77
+ await m.initSession();
78
+ return m;
79
+ }
80
+ if (m.state.status === "INITIALIZING") {
81
+ await new Promise((resolve) => {
82
+ const unsub = m.on("changeState", (state) => {
83
+ if (state.status !== "INITIALIZING") {
84
+ unsub();
85
+ resolve();
86
+ }
87
+ });
88
+ });
89
+ }
90
+ return m;
91
+ }, "ensureManagerInitialized");
92
+ return createConnector((config) => {
93
+ emitWagmiMessage = /* @__PURE__ */ __name((type, data) => {
94
+ config.emitter.emit("message", {
95
+ type,
96
+ data
97
+ });
98
+ }, "emitWagmiMessage");
99
+ emitWagmiDisconnect = /* @__PURE__ */ __name(() => {
100
+ config.emitter.emit("disconnect");
101
+ }, "emitWagmiDisconnect");
102
+ const buildProvider = /* @__PURE__ */ __name(() => {
103
+ const createdProvider = {
104
+ request: /* @__PURE__ */ __name(async (args) => {
105
+ const { method, params: rawParams } = args;
106
+ const params = Array.isArray(rawParams) ? [
107
+ ...rawParams
108
+ ] : rawParams === void 0 ? [] : [
109
+ rawParams
110
+ ];
111
+ const session = getCurrentSession();
112
+ const getSelectedAddressInfo = /* @__PURE__ */ __name((address) => {
113
+ if (!session) throw new Error("No active session");
114
+ const evmInfo = getEvmAddressInfo(session);
115
+ if (evmInfo.length === 0) throw new Error("No EVM address found");
116
+ if (!address) return evmInfo[0];
117
+ const found = evmInfo.find((info) => info.address.toLowerCase() === address.toLowerCase());
118
+ if (!found) throw new Error(`Address not in session: ${address}`);
119
+ return found;
120
+ }, "getSelectedAddressInfo");
121
+ if (method === "eth_accounts") {
122
+ if (!session) return [];
123
+ return getChecksummedAccounts(session);
124
+ }
125
+ if (method === "eth_chainId") {
126
+ if (!session) throw new Error("No active session");
127
+ if (selectedChainId !== null) return `0x${selectedChainId.toString(16)}`;
128
+ const evmInfo = getEvmAddressInfo(session);
129
+ if (evmInfo.length === 0) throw new Error("No EVM address found");
130
+ const chainId = Number.parseInt(evmInfo[0].networkIdentifier, 10);
131
+ if (!Number.isFinite(chainId)) throw new Error(`Invalid chainId: ${chainId}`);
132
+ selectedChainId = chainId;
133
+ return `0x${chainId.toString(16)}`;
134
+ }
135
+ if (method === "wallet_switchEthereumChain") {
136
+ const [{ chainId: rawChainId }] = params != null ? params : [];
137
+ if (!rawChainId) throw new Error("wallet_switchEthereumChain missing chainId param");
138
+ const chainId = Number.parseInt(rawChainId, 16);
139
+ if (!Number.isFinite(chainId)) throw new Error(`Invalid chainId: ${rawChainId}`);
140
+ if (!session) throw new Error("No active session");
141
+ const supported = getEvmAddressInfo(session).some((info) => Number.parseInt(info.networkIdentifier, 10) === chainId);
142
+ if (!supported) {
143
+ const err = new Error(`Unsupported chain: ${chainId}`);
144
+ err.code = 4902;
145
+ throw err;
146
+ }
147
+ selectedChainId = chainId;
148
+ config.emitter.emit("change", {
149
+ chainId
150
+ });
151
+ return null;
152
+ }
153
+ if (method === "personal_sign") {
154
+ const [messageParam, addressParam] = params != null ? params : [];
155
+ const message = typeof messageParam === "string" ? messageParam : String(messageParam != null ? messageParam : "");
156
+ const address = typeof addressParam === "string" ? addressParam : void 0;
157
+ const addressInfo = getSelectedAddressInfo(address);
158
+ const response = await (session == null ? void 0 : session.jsonRpc.request("signMessage", {
159
+ message,
160
+ addressInfo
161
+ }));
162
+ return response == null ? void 0 : response.signature;
163
+ }
164
+ if (method === "eth_sign") {
165
+ const [addressParam, messageParam] = params != null ? params : [];
166
+ const address = typeof addressParam === "string" ? addressParam : void 0;
167
+ const message = typeof messageParam === "string" ? messageParam : String(messageParam != null ? messageParam : "");
168
+ const addressInfo = getSelectedAddressInfo(address);
169
+ const response = await (session == null ? void 0 : session.jsonRpc.request("signMessage", {
170
+ message,
171
+ addressInfo
172
+ }));
173
+ return response == null ? void 0 : response.signature;
174
+ }
175
+ if (method === "eth_signTypedData" || method === "eth_signTypedData_v4") {
176
+ const [addressParam, typedDataParam] = params != null ? params : [];
177
+ const address = typeof addressParam === "string" ? addressParam : void 0;
178
+ const typedData = typeof typedDataParam === "string" ? typedDataParam : JSON.stringify(typedDataParam != null ? typedDataParam : "");
179
+ const addressInfo = getSelectedAddressInfo(address);
180
+ const response = await (session == null ? void 0 : session.jsonRpc.request("signTypedData", {
181
+ typedData,
182
+ addressInfo
183
+ }));
184
+ return response == null ? void 0 : response.signature;
185
+ }
186
+ if (method === "eth_sendTransaction") {
187
+ const [txParams] = params != null ? params : [];
188
+ const addressInfo = getSelectedAddressInfo(txParams == null ? void 0 : txParams.from);
189
+ const response = await (session == null ? void 0 : session.jsonRpc.request("sendTransaction", {
190
+ addressInfo,
191
+ to: txParams == null ? void 0 : txParams.to,
192
+ value: txParams == null ? void 0 : txParams.value,
193
+ data: txParams == null ? void 0 : txParams.data,
194
+ gas: txParams == null ? void 0 : txParams.gas,
195
+ gasPrice: txParams == null ? void 0 : txParams.gasPrice,
196
+ maxFeePerGas: txParams == null ? void 0 : txParams.maxFeePerGas,
197
+ maxPriorityFeePerGas: txParams == null ? void 0 : txParams.maxPriorityFeePerGas,
198
+ nonce: txParams == null ? void 0 : txParams.nonce,
199
+ chainId: txParams == null ? void 0 : txParams.chainId
200
+ }));
201
+ return response == null ? void 0 : response.txHash;
202
+ }
203
+ if (method === "credit_connect_send_message") {
204
+ if (!session) throw new Error("No active session");
205
+ const [messageParam] = params != null ? params : [];
206
+ const message = typeof messageParam === "string" ? messageParam : JSON.stringify(messageParam != null ? messageParam : "");
207
+ await session.msg.sendMessage(message);
208
+ return true;
209
+ }
210
+ if (method === "credit_connect_jsonrpc_ping") {
211
+ if (!session) throw new Error("No active session");
212
+ return await session.jsonRpc.request("pingPong", {});
213
+ }
214
+ throw new Error(`Unsupported provider method: ${method}`);
215
+ }, "request"),
216
+ on: /* @__PURE__ */ __name((event, listener) => {
217
+ let listeners = providerListeners.get(event);
218
+ if (!listeners) {
219
+ listeners = /* @__PURE__ */ new Set();
220
+ providerListeners.set(event, listeners);
221
+ }
222
+ listeners.add(listener);
223
+ return createdProvider;
224
+ }, "on"),
225
+ removeListener: /* @__PURE__ */ __name((event, listener) => {
226
+ var _a;
227
+ (_a = providerListeners.get(event)) == null ? void 0 : _a.delete(listener);
228
+ return createdProvider;
229
+ }, "removeListener")
230
+ };
231
+ return createdProvider;
232
+ }, "buildProvider");
233
+ return {
234
+ id: CONNECTOR_ID,
235
+ name: CONNECTOR_NAME,
236
+ type: CONNECTOR_TYPE,
237
+ async setup() {
238
+ await ensureManagerInitialized();
239
+ },
240
+ async connect(parameters) {
241
+ try {
242
+ const m = createManagerIfNeeded();
243
+ if (m.state.status === "INITIALIZING") {
244
+ await new Promise((resolve) => {
245
+ const unsub = m.on("changeState", (state) => {
246
+ if (state.status !== "INITIALIZING") {
247
+ unsub();
248
+ resolve();
249
+ }
250
+ });
251
+ });
252
+ }
253
+ if (parameters == null ? void 0 : parameters.isReconnecting) {
254
+ const session2 = getCurrentSession();
255
+ if (!session2) throw new Error("No active session to reconnect");
256
+ const accounts2 = getChecksummedAccounts(session2);
257
+ if (accounts2.length === 0) throw new Error("No EVM address found");
258
+ const chainId2 = Number.parseInt(getEvmAddressInfo(session2)[0].networkIdentifier, 10);
259
+ if (!Number.isFinite(chainId2)) throw new Error(`Invalid chainId: ${chainId2}`);
260
+ selectedChainId = chainId2;
261
+ if ((parameters == null ? void 0 : parameters.withCapabilities) === true) {
262
+ return castConnectResult({
263
+ accounts: accounts2.map((address) => ({
264
+ address,
265
+ capabilities: {}
266
+ })),
267
+ chainId: chainId2
268
+ });
269
+ }
270
+ return castConnectResult({
271
+ accounts: accounts2,
272
+ chainId: chainId2
273
+ });
274
+ }
275
+ if (m.state.status !== "CONNECTED") {
276
+ connectPromise = m.connectNewSession();
277
+ const connected = await connectPromise;
278
+ connectPromise = null;
279
+ if (!connected) throw new Error("Credit Connect session failed");
280
+ }
281
+ const session = getCurrentSession();
282
+ if (!session) throw new Error("Credit Connect session failed");
283
+ const accounts = getChecksummedAccounts(session);
284
+ if (accounts.length === 0) throw new Error("No EVM address found");
285
+ const chainId = Number.parseInt(getEvmAddressInfo(session)[0].networkIdentifier, 10);
286
+ if (!Number.isFinite(chainId)) throw new Error(`Invalid chainId: ${chainId}`);
287
+ selectedChainId = chainId;
288
+ if ((parameters == null ? void 0 : parameters.withCapabilities) === true) {
289
+ return castConnectResult({
290
+ accounts: accounts.map((address) => ({
291
+ address,
292
+ capabilities: {}
293
+ })),
294
+ chainId
295
+ });
296
+ }
297
+ return castConnectResult({
298
+ accounts,
299
+ chainId
300
+ });
301
+ } catch (error) {
302
+ resetState();
303
+ throw error;
304
+ }
305
+ },
306
+ async switchChain({ chainId }) {
307
+ const session = getCurrentSession();
308
+ if (!session) throw new Error("No active session");
309
+ const supported = getEvmAddressInfo(session).some((info) => Number.parseInt(info.networkIdentifier, 10) === chainId);
310
+ if (!supported) {
311
+ const err = new Error(`Unsupported chain: ${chainId}`);
312
+ err.code = 4902;
313
+ throw err;
314
+ }
315
+ const chain = config.chains.find((c) => c.id === chainId);
316
+ if (!chain) throw new Error(`Chain ${chainId} not in config`);
317
+ selectedChainId = chainId;
318
+ config.emitter.emit("change", {
319
+ chainId
320
+ });
321
+ await Promise.resolve();
322
+ return chain;
323
+ },
324
+ async isAuthorized() {
325
+ await ensureManagerInitialized();
326
+ const session = getCurrentSession();
327
+ if (!session) return false;
328
+ return session.addressInfoList.some((info) => info.networkType === "eip155");
329
+ },
330
+ async disconnect() {
331
+ isLocalDisconnect = true;
332
+ try {
333
+ if ((manager == null ? void 0 : manager.state.status) === "CONNECTED") {
334
+ await manager.disconnectSession();
335
+ }
336
+ } finally {
337
+ isLocalDisconnect = false;
338
+ }
339
+ provider = null;
340
+ providerPromise = null;
341
+ resetState();
342
+ config.emitter.emit("disconnect");
343
+ },
344
+ async getAccounts() {
345
+ await ensureManagerInitialized();
346
+ const session = getCurrentSession();
347
+ if (!session) return [];
348
+ return getChecksummedAccounts(session);
349
+ },
350
+ async getChainId() {
351
+ await ensureManagerInitialized();
352
+ const session = getCurrentSession();
353
+ if (!session) throw new Error("No active session");
354
+ if (selectedChainId !== null) return selectedChainId;
355
+ const evmAddressInfo = getEvmAddressInfo(session);
356
+ if (evmAddressInfo.length === 0) throw new Error("No EVM address found");
357
+ const chainId = Number.parseInt(evmAddressInfo[0].networkIdentifier, 10);
358
+ if (!Number.isFinite(chainId)) throw new Error(`Invalid chainId: ${chainId}`);
359
+ selectedChainId = chainId;
360
+ return chainId;
361
+ },
362
+ async getProvider() {
363
+ if (provider) return provider;
364
+ if (providerPromise) return providerPromise;
365
+ providerPromise = (async () => {
366
+ await ensureManagerInitialized();
367
+ const createdProvider = buildProvider();
368
+ provider = createdProvider;
369
+ return createdProvider;
370
+ })();
371
+ try {
372
+ return await providerPromise;
373
+ } finally {
374
+ providerPromise = null;
375
+ }
376
+ },
377
+ onAccountsChanged(accounts) {
378
+ if (!accounts || accounts.length === 0) {
379
+ config.emitter.emit("disconnect");
380
+ return;
381
+ }
382
+ config.emitter.emit("change", {
383
+ accounts: accounts.map(getAddress)
384
+ });
385
+ },
386
+ onChainChanged(chainId) {
387
+ const normalized = typeof chainId === "string" ? Number.parseInt(chainId, 16) : Number(chainId);
388
+ if (!Number.isFinite(normalized)) return;
389
+ selectedChainId = normalized;
390
+ config.emitter.emit("change", {
391
+ chainId: normalized
392
+ });
393
+ },
394
+ onDisconnect() {
395
+ resetState();
396
+ config.emitter.emit("disconnect");
397
+ }
398
+ };
399
+ });
400
+ }, "creditConnectConnector");
401
+
402
+ export {
403
+ __name,
404
+ creditConnectConnector
405
+ };