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

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