@gluwa/connect-kit 0.2.0-next.1 → 0.2.0-next.11

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 (99) hide show
  1. package/CHANGELOG.md +72 -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 -409
  15. package/dist/index.css +1903 -389
  16. package/dist/index.d.ts +21 -10
  17. package/dist/index.js +1507 -922
  18. package/dist/package.json +7 -6
  19. package/package.json +8 -8
  20. package/src/ConnectKitProvider.tsx +97 -65
  21. package/src/api/asset.ts +10 -0
  22. package/src/assets.d.ts +5 -0
  23. package/src/components/actionItem/index.tsx +50 -0
  24. package/src/components/actionItem/style.scss +47 -0
  25. package/src/components/copyLink/index.tsx +16 -0
  26. package/src/components/copyLink/style.scss +16 -0
  27. package/src/components/qrArea/index.tsx +72 -0
  28. package/src/components/qrArea/style.scss +122 -0
  29. package/src/components/searchBar/asset/Search.tsx +20 -0
  30. package/src/components/searchBar/asset/XMarkCircle.tsx +24 -0
  31. package/src/components/searchBar/index.tsx +44 -0
  32. package/src/components/searchBar/style.scss +58 -0
  33. package/src/components/toast/index.tsx +41 -0
  34. package/src/components/toast/style.scss +108 -0
  35. package/src/components/toggle/index.tsx +27 -0
  36. package/src/components/toggle/style.scss +53 -0
  37. package/src/components/walletGrid/index.tsx +64 -0
  38. package/src/components/walletGrid/style.scss +108 -0
  39. package/src/components/walletItem/index.tsx +49 -0
  40. package/src/components/walletItem/style.scss +70 -0
  41. package/src/connector-meta.ts +16 -11
  42. package/src/core/config.ts +20 -1
  43. package/src/creditConnectConnector.ts +23 -25
  44. package/src/events/account.ts +30 -3
  45. package/src/hooks/useConnectBanner.ts +79 -0
  46. package/src/hooks/useConnectTimeout.ts +92 -0
  47. package/src/hooks/useMetaMaskExtension.ts +29 -0
  48. package/src/hooks/useWCState.ts +21 -5
  49. package/src/hooks/useWagmiConnect.ts +35 -9
  50. package/src/index.ts +5 -2
  51. package/src/layout/allWallets/index.tsx +52 -0
  52. package/src/layout/allWallets/style.scss +57 -0
  53. package/src/layout/connectDialog/asset/backIcon.tsx +24 -0
  54. package/src/layout/connectDialog/asset/checkIcon.tsx +28 -0
  55. package/src/layout/connectDialog/asset/closeIcon.tsx +21 -0
  56. package/src/layout/connectDialog/asset/copyIcon.tsx +28 -0
  57. package/src/layout/connectDialog/asset/linkIcon.tsx +24 -0
  58. package/src/layout/connectDialog/asset/spinner.tsx +21 -0
  59. package/src/layout/connectDialog/asset/warningIcon.tsx +21 -0
  60. package/src/layout/connectDialog/idle/assets/banner-placeholder.png +0 -0
  61. package/src/layout/connectDialog/idle/index.tsx +55 -0
  62. package/src/layout/connectDialog/idle/style.scss +52 -0
  63. package/src/layout/connectDialog/index.tsx +432 -0
  64. package/src/layout/connectDialog/loading/index.tsx +13 -0
  65. package/src/layout/connectDialog/loading/style.scss +19 -0
  66. package/src/layout/connectDialog/metaMask/index.tsx +61 -0
  67. package/src/layout/connectDialog/metaMask/style.scss +65 -0
  68. package/src/layout/connectDialog/qr/index.tsx +33 -0
  69. package/src/layout/connectDialog/style.scss +48 -0
  70. package/src/layout/connectDialog/timeout/index.tsx +31 -0
  71. package/src/layout/connectDialog/timeout/style.scss +64 -0
  72. package/src/layout/connectDialog/walletConnect/index.tsx +45 -0
  73. package/src/layout/connectDialog/walletConnect/style.scss +48 -0
  74. package/src/layout/connectDialog/walletQR/index.tsx +37 -0
  75. package/src/layout/detailPanel/index.tsx +175 -0
  76. package/src/layout/detailPanel/style.scss +70 -0
  77. package/src/layout/selectorPanel/index.tsx +100 -0
  78. package/src/layout/selectorPanel/style.scss +113 -0
  79. package/src/style/color.scss +417 -0
  80. package/src/style/font.scss +28 -0
  81. package/src/style/index.scss +5 -0
  82. package/src/style/mixin.scss +217 -0
  83. package/src/style/reset.scss +110 -0
  84. package/src/style/variables.scss +13 -0
  85. package/src/types.ts +32 -8
  86. package/src/utils/platform.ts +5 -3
  87. package/src/wallet-display-override.ts +15 -0
  88. package/tsconfig.json +5 -1
  89. package/tsup.config.ts +32 -2
  90. package/assets/creditwallet.png +0 -0
  91. package/dist/chunk-DDA6FP6U.js +0 -7
  92. package/src/ConnectModal.scss +0 -665
  93. package/src/ConnectModal.tsx +0 -573
  94. package/src/components/QRFrame.tsx +0 -43
  95. package/src/views/CreditWalletView.tsx +0 -58
  96. package/src/views/IdleView.tsx +0 -10
  97. package/src/views/MetaMaskView.tsx +0 -66
  98. package/src/views/SwitchChainView.tsx +0 -72
  99. package/src/views/WalletConnectView.tsx +0 -206
package/CHANGELOG.md CHANGED
@@ -1,5 +1,77 @@
1
1
  # @gluwa/wallet-kit
2
2
 
3
+ ## 0.2.0-next.11
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [4cba4bb]
8
+ - @gluwa/credit-connect-sdk@0.2.0-next.6
9
+ - @gluwa/credit-connect-e2ee-tweetnacl@0.2.0-next.6
10
+ - @gluwa/credit-connect-hub-node-ws@0.1.0-next.6
11
+ - @gluwa/credit-connect-storage-local@0.2.0-next.6
12
+
13
+ ## 0.2.0-next.10
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies [0b7cf10]
18
+ - @gluwa/credit-connect-sdk@0.2.0-next.5
19
+ - @gluwa/credit-connect-e2ee-tweetnacl@0.2.0-next.5
20
+ - @gluwa/credit-connect-hub-node-ws@0.1.0-next.5
21
+ - @gluwa/credit-connect-storage-local@0.2.0-next.5
22
+
23
+ ## 0.2.0-next.9
24
+
25
+ ### Patch Changes
26
+
27
+ - 18e631a: fix bugs
28
+
29
+ ## 0.2.0-next.8
30
+
31
+ ### Patch Changes
32
+
33
+ - e3789b4: emit OnSessionExpired when credit-connect QR session times out
34
+ - Updated dependencies [e3789b4]
35
+ - @gluwa/credit-connect-hub-node-ws@0.1.0-next.4
36
+ - @gluwa/credit-connect-sdk@0.2.0-next.4
37
+ - @gluwa/credit-connect-e2ee-tweetnacl@0.2.0-next.4
38
+ - @gluwa/credit-connect-storage-local@0.2.0-next.4
39
+
40
+ ## 0.2.0-next.7
41
+
42
+ ### Patch Changes
43
+
44
+ - 343c6ef: change UI wallet name credit wallet -> penguinWallet
45
+
46
+ ## 0.2.0-next.6
47
+
48
+ ### Patch Changes
49
+
50
+ - a9bbec9: enhance reconnect logic with auto-connect for injected connectors
51
+
52
+ ## 0.2.0-next.5
53
+
54
+ ### Patch Changes
55
+
56
+ - d3d52e9: fix: react version paths
57
+
58
+ ## 0.2.0-next.4
59
+
60
+ ### Patch Changes
61
+
62
+ - ed8effc: add watchAsset
63
+
64
+ ## 0.2.0-next.3
65
+
66
+ ### Patch Changes
67
+
68
+ - fb3f3c4: support connect-kit
69
+ - Updated dependencies [fb3f3c4]
70
+ - @gluwa/credit-connect-hub-node-ws@0.1.0-next.3
71
+ - @gluwa/credit-connect-sdk@0.2.0-next.3
72
+ - @gluwa/credit-connect-e2ee-tweetnacl@0.2.0-next.3
73
+ - @gluwa/credit-connect-storage-local@0.2.0-next.3
74
+
3
75
  ## 0.2.0-next.1
4
76
 
5
77
  ### 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
+ };