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