@dappworks/kit 0.4.230 → 0.4.231

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/wallet.mjs CHANGED
@@ -1,701 +1,26 @@
1
- import { AIem } from './chunk-NPQ7GCFM.mjs';
2
- import './chunk-7MDKCI65.mjs';
3
- import { ObjectPool, StorageState, PromiseHook } from './chunk-DRTTNPZI.mjs';
1
+ import { WalletConfigStore, WalletStore, WalletRpcStore } from './chunk-NO4O46V2.mjs';
2
+ export { WalletConfigStore, WalletHistoryStore, WalletRpcStore, WalletStore } from './chunk-NO4O46V2.mjs';
4
3
  import './chunk-TSUKTLY3.mjs';
5
- import { DialogStore } from './chunk-GT4R5SDI.mjs';
4
+ import './chunk-NPQ7GCFM.mjs';
5
+ import './chunk-7MDKCI65.mjs';
6
+ import './chunk-GT4R5SDI.mjs';
6
7
  import { ToastPlugin } from './chunk-IMOLRP7I.mjs';
7
8
  import './chunk-K73JTEJQ.mjs';
8
9
  import { RootStore } from './chunk-XSGTWROT.mjs';
9
- import { helper } from './chunk-R4N52NI2.mjs';
10
+ import './chunk-R4N52NI2.mjs';
10
11
  import './chunk-ONVPCAMQ.mjs';
11
12
  import './chunk-K7LFG5BA.mjs';
12
- import { __spreadValues, __spreadProps } from './chunk-R4SQKVDQ.mjs';
13
- import { RainbowKitProvider, darkTheme, lightTheme, getDefaultConfig, useConnectModal } from '@rainbow-me/rainbowkit';
13
+ import { __spreadValues } from './chunk-R4SQKVDQ.mjs';
14
+ import { RainbowKitProvider, darkTheme, lightTheme } from '@rainbow-me/rainbowkit';
14
15
  import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
15
- import React5, { useEffect } from 'react';
16
- import { WagmiProvider, useAccount, useSwitchChain, useConnect, useDisconnect, useWalletClient } from 'wagmi';
17
- import { toHex, createWalletClient, custom, publicActions } from 'viem';
18
- import EventEmitter from 'events';
19
- import { Icon } from '@iconify/react';
20
- import { iopayWallet, metaMaskWallet, walletConnectWallet, okxWallet, binanceWallet, safeWallet } from '@rainbow-me/rainbowkit/wallets';
21
- import SafeAppsSDK, { TransactionStatus } from '@safe-global/safe-apps-sdk';
22
- import { observer } from 'mobx-react-lite';
16
+ import React2, { useEffect } from 'react';
17
+ import { WagmiProvider } from 'wagmi';
23
18
  import { iotex as iotex$1, iotexTestnet as iotexTestnet$1 } from 'viem/chains';
19
+ import SafeAppsSDK from '@safe-global/safe-apps-sdk';
20
+ import { observer } from 'mobx-react-lite';
21
+ import { Icon } from '@iconify/react';
24
22
  import { Checkbox, Tooltip, Button, Popover, PopoverTrigger, PopoverContent, Input, Table, TableHeader, TableColumn, TableBody, TableRow, TableCell } from '@nextui-org/react';
25
23
 
26
- var WalletConfigStore = class {
27
- constructor(args) {
28
- this.sid = "WalletConfigStore";
29
- this.autoObservable = true;
30
- this.appName = "Dappkit";
31
- this.projectId = "b69e844f38265667350efd78e3e1a5fb";
32
- this.defaultChainId = 4689;
33
- this.updateTicker = 1;
34
- this.walletUpdateTick = 0;
35
- this.isConnect = false;
36
- this.isInSafeApp = false;
37
- // This mode to resolve and walletClient and nextui in some extreme cases cause page infinite redraw bugs
38
- this.compatibleMode = true;
39
- Object.assign(this, args);
40
- }
41
- set(params) {
42
- Object.assign(this, params);
43
- this.updateTicker += 1;
44
- }
45
- get reconnectOnMount() {
46
- if (!this.compatibleMode)
47
- return true;
48
- if (!this.isConnect && this.walletUpdateTick == 0) {
49
- return true;
50
- }
51
- if (!this.isConnect && this.walletUpdateTick != 0) {
52
- return false;
53
- }
54
- if (this.isConnect) {
55
- return true;
56
- }
57
- }
58
- get rainbowKitConfig() {
59
- var _a;
60
- return ObjectPool.get(`rainbowKitConfig-${(_a = this.supportedChains) == null ? void 0 : _a.map((i) => i.id).join("-")}`, () => {
61
- return getDefaultConfig({
62
- appName: this.appName,
63
- projectId: this.projectId,
64
- //@ts-ignore
65
- chains: this.supportedChains,
66
- wallets: [
67
- {
68
- groupName: "Recommended",
69
- wallets: [iopayWallet, metaMaskWallet]
70
- },
71
- {
72
- groupName: "Others",
73
- wallets: [metaMaskWallet, walletConnectWallet, iopayWallet, okxWallet, binanceWallet, safeWallet]
74
- }
75
- ]
76
- });
77
- });
78
- }
79
- };
80
-
81
- // module/Wallet/walletPluginStore.tsx
82
- var defaultRPCList = [
83
- { name: "https://babel-api.fastblocks.io", latency: 0, height: 0, custom: false },
84
- { name: "https://babel-api.mainnet.iotex.one", latency: 0, height: 0 },
85
- { name: "https://babel-api.mainnet.iotex.io", latency: 0, height: 0 },
86
- { name: "https://iotex-network.rpc.thirdweb.com", latency: 0, height: 0 },
87
- { name: "https://iotexrpc.com", latency: 0, height: 0 },
88
- { name: "https://iotex.api.onfinality.io/public", latency: 0, height: 0 },
89
- { name: "https://rpc.ankr.com/iotex", latency: 0, height: 0 }
90
- ];
91
- var WalletRpcStore = class {
92
- constructor() {
93
- this.sid = "WalletPluginStore";
94
- this.autoObservable = true;
95
- this.curRpc = new StorageState({ default: "https://babel-api.mainnet.iotex.one", key: "curRPC-v2", value: "https://babel-api.mainnet.iotex.one" });
96
- this.isAutoSelectRpc = new StorageState({ key: "isAutoSelectRpc", default: true });
97
- this.customRpc = "";
98
- this.rpcList = new StorageState({ key: "customRpcList-v2", default: defaultRPCList, value: [] });
99
- this.showCustomRpc = false;
100
- }
101
- get currentRpc() {
102
- var _a, _b;
103
- console.log((_a = this.rpcList.value) == null ? void 0 : _a.find((i) => i.name == this.curRpc));
104
- return ((_b = this.rpcList.value) == null ? void 0 : _b.find((i) => i.name == this.curRpc.value)) || null;
105
- }
106
- addCustomRpc() {
107
- const item = { name: this.customRpc, latency: 0, height: 0, custom: true };
108
- if (defaultRPCList.find((i) => i.name === item.name)) {
109
- return RootStore.Get(ToastPlugin).error("Rpc already exists");
110
- }
111
- if (this.rpcList.value) {
112
- this.rpcList.save([...this.rpcList.value, item]);
113
- this.refresh();
114
- return;
115
- }
116
- this.rpcList.save([...defaultRPCList, item]);
117
- this.refresh();
118
- }
119
- async addToMetamask(url) {
120
- var _a;
121
- try {
122
- if (typeof window == "undefined")
123
- return;
124
- await ((_a = window == null ? void 0 : window.ethereum) == null ? void 0 : _a.request({
125
- method: "wallet_addEthereumChain",
126
- params: [{
127
- chainId: `0x${4689 .toString(16)}`,
128
- chainName: "IoTeX Mainnet",
129
- nativeCurrency: {
130
- name: "IoTeX",
131
- symbol: "IOTX",
132
- decimals: 18
133
- },
134
- rpcUrls: [url],
135
- blockExplorerUrls: ["https://iotexscan.io"]
136
- }]
137
- }));
138
- RootStore.Get(ToastPlugin).success("Network added");
139
- console.log("Network added");
140
- } catch (error) {
141
- console.error("Failed to add network", error);
142
- }
143
- }
144
- async switchOrAddChain(chainId) {
145
- return new Promise(async (resolve, reject) => {
146
- try {
147
- await window.ethereum.request({
148
- method: "wallet_switchEthereumChain",
149
- params: [{ chainId: toHex(chainId) }]
150
- });
151
- resolve(true);
152
- } catch (switchError) {
153
- if (switchError.code === 4902) {
154
- try {
155
- await this.addToMetamaskById(chainId);
156
- } catch (addError) {
157
- reject(addError);
158
- }
159
- } else {
160
- reject(switchError);
161
- }
162
- }
163
- });
164
- }
165
- async addToMetamaskById(id) {
166
- return new Promise(async (resolve, reject) => {
167
- try {
168
- if (typeof window == "undefined")
169
- return;
170
- const chain = RootStore.Get(WalletConfigStore).supportedChains.find((i) => i.id == id);
171
- const res = await window.ethereum.request({
172
- method: "wallet_addEthereumChain",
173
- params: [{
174
- "chainId": toHex(chain.id),
175
- "chainName": chain.name,
176
- "nativeCurrency": {
177
- "name": chain.nativeCurrency.name,
178
- "symbol": chain.nativeCurrency.symbol,
179
- "decimals": chain.nativeCurrency.decimals
180
- },
181
- "rpcUrls": JSON.parse(JSON.stringify(chain.rpcUrls.default.http)),
182
- "blockExplorerUrls": [chain.blockExplorers.default.url]
183
- }]
184
- });
185
- console.log(res);
186
- resolve(res);
187
- } catch (switchError) {
188
- reject(false);
189
- }
190
- });
191
- }
192
- refresh() {
193
- this.showCustomRpc = false;
194
- this.customRpc = "";
195
- setTimeout(() => {
196
- this.testRpc();
197
- }, 500);
198
- }
199
- latencyColor(latency) {
200
- if (latency < 0) {
201
- return "text-red-500";
202
- }
203
- if (latency < 1) {
204
- return "text-green-500";
205
- }
206
- if (latency < 2) {
207
- return "text-yellow-500";
208
- }
209
- return "text-red-500";
210
- }
211
- async testRpcFunction(url) {
212
- const start = performance.now();
213
- try {
214
- const response = await fetch(url, {
215
- method: "POST",
216
- headers: {
217
- "Content-Type": "application/json"
218
- },
219
- body: JSON.stringify({
220
- jsonrpc: "2.0",
221
- method: "eth_getBlockByNumber",
222
- params: ["latest", false],
223
- id: 1
224
- })
225
- });
226
- if (!response.ok) {
227
- throw new Error(`Error from server: ${response.status}`);
228
- }
229
- const res = await response.json();
230
- console.log(res);
231
- const end = performance.now();
232
- return { url, lentency: Number(helper.number.numberFormat((end - start) / 1e3, "0.000", { fallback: "-1" })), height: parseInt(res.result.number, 16) };
233
- } catch (error) {
234
- console.error("RPC Latency Test Failed:", error);
235
- return { url, lentency: -1, height: -1 };
236
- }
237
- }
238
- testRpc() {
239
- var _a;
240
- (_a = this.rpcList) == null ? void 0 : _a.value.forEach((i) => {
241
- this.testRpcFunction(i.name).then((res) => {
242
- i.latency = res.lentency;
243
- i.height = res.height;
244
- });
245
- });
246
- this.rpcList.save(this.rpcList.value);
247
- }
248
- removeRpc(name) {
249
- this.rpcList.save(this.rpcList.value.filter((i) => i.name !== name));
250
- }
251
- scoreIcon(score) {
252
- if (score < 0) {
253
- return /* @__PURE__ */ React5.createElement(Icon, { icon: "codicon:error", width: "18", height: "18", style: { color: "#FF0000" } });
254
- }
255
- if (score < 1) {
256
- return /* @__PURE__ */ React5.createElement(Icon, { icon: "icon-park-solid:check-one", width: "18", height: "18", style: { color: "#289726" } });
257
- }
258
- if (score < 2) {
259
- return /* @__PURE__ */ React5.createElement(Icon, { icon: "bxs:error", width: "18", height: "18", style: { color: "#FFA500" } });
260
- }
261
- return /* @__PURE__ */ React5.createElement(Icon, { icon: "codicon:error", width: "18", height: "18", style: { color: "#FF0000" } });
262
- }
263
- get wallet() {
264
- return RootStore.Get(WalletStore);
265
- }
266
- // debounceAutoSelectRpc = pDebounce(this.autoSelectRpc, 3000)
267
- async autoSelectRpc() {
268
- console.log("autoSelectRpc");
269
- for (let i = 0; i < this.rpcList.value.length; i++) {
270
- const item = this.rpcList.value[i];
271
- const res = await this.testRpcFunction(item.name);
272
- if (res.lentency != -1 || res.height > 0) {
273
- this.curRpc.save(item.name);
274
- break;
275
- }
276
- }
277
- }
278
- };
279
- var WalletHistoryStore = class {
280
- constructor() {
281
- this.sid = "WalletHistoryStore";
282
- this.isRender = false;
283
- this.autoObservable = true;
284
- this.history = new StorageState({ value: [], key: "history" });
285
- }
286
- set(params) {
287
- Object.assign(this, params);
288
- }
289
- get historyList() {
290
- if (this.isRender) {
291
- return this.history.value;
292
- }
293
- return [];
294
- }
295
- recordHistory(item) {
296
- let value = this.history.load();
297
- if (!value) {
298
- value = [item];
299
- } else {
300
- value = [...value, item];
301
- }
302
- this.history.setValue(value);
303
- }
304
- updateHistoryStatusByTx(tx, status) {
305
- let value = this.history.load();
306
- if (!value) {
307
- return;
308
- }
309
- value = value.map((i) => {
310
- if (i.tx == tx) {
311
- i.status = status;
312
- return i;
313
- }
314
- if (!tx) {
315
- i.status = status;
316
- }
317
- return i;
318
- });
319
- this.history.setValue(value);
320
- }
321
- clearHistory() {
322
- this.history.setValue(null);
323
- }
324
- };
325
- var SuccessTxDialog = observer((props) => {
326
- return /* @__PURE__ */ React5.createElement("div", { className: "flex-col gap-4 py-10" }, /* @__PURE__ */ React5.createElement("div", { className: "w-full flex items-center justify-center" }, /* @__PURE__ */ React5.createElement(Icon, { icon: "icon-park-solid:check-one", width: "48", height: "48", className: "text-green-500" })), /* @__PURE__ */ React5.createElement("div", { className: "text-2xl font-[900] text-center mt-4" }, props.msg), /* @__PURE__ */ React5.createElement(
327
- "div",
328
- {
329
- className: "flex items-center justify-center text-green-500 text-sm mt-6 gap-2 cursor-pointer hover:text-green-600 transition",
330
- onClick: (e) => window.open(`https://iotexscan.io/tx/${props.hash}`, "_blank")
331
- },
332
- "View on IoTeXScan ",
333
- /* @__PURE__ */ React5.createElement(Icon, { icon: "material-symbols:chip-extraction-rounded", width: "18", height: "18" })
334
- ));
335
- });
336
- var ShowSuccessTxDialog = ({ msg, hash }) => {
337
- RootStore.Get(DialogStore).setData({
338
- title: "",
339
- content: /* @__PURE__ */ React5.createElement(SuccessTxDialog, { msg, hash }),
340
- isOpen: true
341
- });
342
- };
343
-
344
- // module/Wallet/index.tsx
345
- var WalletStore = class _WalletStore {
346
- constructor(args) {
347
- this.sid = "wallet";
348
- this.autoObservable = true;
349
- this.account = null;
350
- this.isSuccessDialogOpen = false;
351
- this.isConnect = false;
352
- this.event = new EventEmitter();
353
- this.updateTicker = 0;
354
- this.addressMode = "0x";
355
- this.isIoTeXChain = false;
356
- this.balance = PromiseHook.wrap({
357
- func: async () => {
358
- var _a;
359
- if (!this.publicClient || !this.account)
360
- return helper.number.warpBigNumber("0");
361
- const balance = await this.publicClient.getBalance({
362
- address: this.account
363
- });
364
- if (balance) {
365
- return helper.number.warpBigNumber((_a = balance == null ? void 0 : balance.toString()) != null ? _a : "0");
366
- }
367
- }
368
- });
369
- Object.assign(this, args);
370
- }
371
- // isInSafeApp = false;
372
- get isInSafeApp() {
373
- return RootStore.Get(WalletConfigStore).isInSafeApp;
374
- }
375
- setAddressMode(mode) {
376
- this.addressMode = mode;
377
- localStorage.setItem("addressMode", mode);
378
- }
379
- get accountFormat() {
380
- return this.account ? helper.address.convertAddress(this.addressMode, this.account) : "-";
381
- }
382
- get connectAccountEllipsisFormat() {
383
- return this.account ? helper.string.truncate(helper.address.convertAddress(this.addressMode, this.account), 11, "...") : "-";
384
- }
385
- get accountEllipsisFormat() {
386
- return this.account ? helper.string.truncate(helper.address.convertAddress(this.addressMode, this.account), 16, "...") : "-";
387
- }
388
- get supportedChains() {
389
- return RootStore.Get(WalletConfigStore).supportedChains;
390
- }
391
- use() {
392
- const { chain, address, isConnected } = useAccount();
393
- const { switchChainAsync } = useSwitchChain();
394
- const { openConnectModal } = useConnectModal();
395
- const { connect } = useConnect();
396
- const { disconnect } = useDisconnect();
397
- const walletConfigStore = RootStore.Get(WalletConfigStore);
398
- this.set({
399
- //@ts-ignore
400
- connect,
401
- // @ts-ignore
402
- // walletClient,
403
- openConnectModal,
404
- switchChain: switchChainAsync,
405
- disconnect
406
- });
407
- useEffect(() => {
408
- RootStore.Get(WalletHistoryStore).set({ isRender: true });
409
- this.set({
410
- isConnect: isConnected,
411
- account: address,
412
- chain
413
- });
414
- if ((chain == null ? void 0 : chain.id) == 4689) {
415
- this.isIoTeXChain = true;
416
- } else {
417
- this.isIoTeXChain = false;
418
- }
419
- walletConfigStore.set({
420
- isConnect: isConnected
421
- });
422
- if (this.account) {
423
- this.updateTicker++;
424
- walletConfigStore.set({
425
- walletUpdateTick: this.updateTicker
426
- });
427
- this.event.emit("walletAccount:ready");
428
- }
429
- this.useWalletClientWithCompatibleMode();
430
- }, [address, isConnected, chain]);
431
- useEffect(() => {
432
- setTimeout(() => {
433
- this.balance.call();
434
- }, 1500);
435
- }, [this.updateTicker]);
436
- }
437
- useWalletClientWithCompatibleMode() {
438
- if (RootStore.Get(WalletConfigStore).compatibleMode) {
439
- if (this.account) {
440
- this.walletClient = createWalletClient({
441
- account: this.account,
442
- chain: this.chain,
443
- transport: custom(window.ethereum)
444
- }).extend(publicActions);
445
- }
446
- console.log(this.walletClient, "this.walletClientxxx");
447
- }
448
- }
449
- useWalletClientWithoutCompatibleMode() {
450
- const { data: walletClient } = useWalletClient();
451
- this.set({
452
- walletClient
453
- });
454
- }
455
- //always return or return default chain
456
- get publicClient() {
457
- if (this.chain && this.supportedChains.some((i) => i.id === this.chain.id)) {
458
- if (this.chain.id == 4689) {
459
- return AIem.PubClient("4689", { rpcUrls: { default: { http: [RootStore.Get(WalletRpcStore).curRpc.value] } }, multicall: true });
460
- }
461
- return AIem.PubClient(this.chain.id.toString());
462
- } else {
463
- return AIem.PubClient("4689");
464
- }
465
- }
466
- set(args) {
467
- Object.assign(this, args);
468
- }
469
- toJSON() {
470
- const { account } = this;
471
- return { account };
472
- }
473
- async prepare(chainId) {
474
- const walletRpcStore = RootStore.Get(WalletRpcStore);
475
- return new Promise(async (res, rej) => {
476
- var _a, _b;
477
- try {
478
- if (this.account) {
479
- if ((!chainId || Number((_a = this.chain) == null ? void 0 : _a.id) == Number(chainId)) && this.walletClient) {
480
- res(this);
481
- }
482
- const interval = setInterval(() => {
483
- var _a2;
484
- if (((_a2 = this.chain) == null ? void 0 : _a2.id) == chainId) {
485
- try {
486
- console.log("useWalletClientWithCompatibleMode");
487
- this.useWalletClientWithCompatibleMode();
488
- res(this);
489
- } catch (error) {
490
- console.log(error, "myerror");
491
- rej(error);
492
- }
493
- clearInterval(interval);
494
- }
495
- }, 1e3);
496
- if (chainId != ((_b = this.chain) == null ? void 0 : _b.id)) {
497
- try {
498
- walletRpcStore.switchOrAddChain(chainId != null ? chainId : 4689);
499
- } catch (error) {
500
- rej(error);
501
- }
502
- }
503
- } else {
504
- this.openConnectModal();
505
- const interval = setInterval(() => {
506
- if (this.account) {
507
- clearInterval(interval);
508
- res(this);
509
- }
510
- }, 1e3);
511
- }
512
- } catch (error) {
513
- rej(error);
514
- }
515
- });
516
- }
517
- async waitForTransactionReceipt({ hash }) {
518
- if (this.isInSafeApp) {
519
- const sdk = new SafeAppsSDK();
520
- while (true) {
521
- const queued = await sdk.txs.getBySafeTxHash(hash);
522
- if (queued.txStatus === TransactionStatus.AWAITING_CONFIRMATIONS || queued.txStatus === TransactionStatus.AWAITING_EXECUTION || queued.txStatus === TransactionStatus.CANCELLED) {
523
- await new Promise((resolve) => setTimeout(resolve, 2e3));
524
- } else {
525
- return this.publicClient.waitForTransactionReceipt({ hash: queued.txHash });
526
- }
527
- }
528
- } else {
529
- return this.publicClient.waitForTransactionReceipt({ hash });
530
- }
531
- }
532
- static async SendTx(...args) {
533
- return RootStore.Get(_WalletStore).sendTx(...args);
534
- }
535
- static async SendRawTx(...args) {
536
- return RootStore.Get(_WalletStore).sendRawTx(...args);
537
- }
538
- async sendTx({
539
- chainId,
540
- tx,
541
- autoAlert = true,
542
- loadingText,
543
- successText,
544
- onError,
545
- historyItem,
546
- showSuccessDialog = false
547
- }) {
548
- var _a, _b, _c;
549
- const toast = RootStore.Get(ToastPlugin);
550
- let hash;
551
- const historyStore = RootStore.Get(WalletHistoryStore);
552
- try {
553
- if (loadingText)
554
- toast.loading(loadingText);
555
- if (!chainId)
556
- throw new Error("chainId, address, data is required");
557
- await RootStore.Get(_WalletStore).prepare(Number(chainId));
558
- hash = await tx();
559
- if (historyItem) {
560
- historyStore.recordHistory(__spreadProps(__spreadValues({}, historyItem), { tx: hash, timestamp: Date.now(), status: "loading", chainId: Number(chainId) }));
561
- }
562
- const receipt = await this.waitForTransactionReceipt({ hash });
563
- if (receipt.status == "success") {
564
- toast.dismiss();
565
- toast.success("The transaction was successful");
566
- if (historyItem) {
567
- if (showSuccessDialog) {
568
- ShowSuccessTxDialog({ msg: historyItem.msg, hash });
569
- }
570
- historyStore.updateHistoryStatusByTx(hash, "success");
571
- }
572
- } else {
573
- toast.dismiss();
574
- toast.error("The transaction failed");
575
- historyStore.updateHistoryStatusByTx(hash, "fail");
576
- }
577
- if (successText)
578
- toast.success(successText);
579
- this.updateTicker++;
580
- return receipt;
581
- } catch (error) {
582
- console.log(error);
583
- toast.dismiss();
584
- if (autoAlert) {
585
- const msg = /reason="[A-Za-z0-9_ :"]*/g.exec(error == null ? void 0 : error.message);
586
- console.log("sendTx", error == null ? void 0 : error.message);
587
- if (((_a = error == null ? void 0 : error.message) == null ? void 0 : _a.includes("rejected")) || String(error).toLowerCase().includes("rejected") || String(error).toLowerCase().includes("denied")) {
588
- toast.error("User rejected transaction");
589
- return;
590
- }
591
- if (((_b = error == null ? void 0 : error.message) == null ? void 0 : _b.includes("The Transaction may not be processed on a block yet")) || ((_c = error == null ? void 0 : error.message) == null ? void 0 : _c.includes("could not be found"))) {
592
- if (historyItem) {
593
- historyStore.updateHistoryStatusByTx(hash, "success");
594
- }
595
- toast.success("The transaction was successful");
596
- return;
597
- }
598
- if (msg) {
599
- onError == null ? void 0 : onError(new Error(msg || "Transaction failed"));
600
- } else {
601
- if (error == null ? void 0 : error.message.includes("viem")) {
602
- const messageArr = error == null ? void 0 : error.message.split("\n");
603
- console.log("messageArr---", messageArr);
604
- if (messageArr.length > 0) {
605
- onError == null ? void 0 : onError(new Error(messageArr[0] || "Transaction failed"));
606
- }
607
- } else {
608
- onError == null ? void 0 : onError(new Error((error == null ? void 0 : error.message) || "Transaction failed"));
609
- }
610
- }
611
- } else {
612
- onError == null ? void 0 : onError(error);
613
- throw error;
614
- }
615
- }
616
- }
617
- async sendRawTx({
618
- chainId,
619
- address,
620
- data,
621
- value = "0",
622
- autoAlert = true,
623
- onSended,
624
- onSuccess,
625
- onError,
626
- historyItem,
627
- loadingText,
628
- showSuccessDialog = false
629
- }) {
630
- var _a, _b, _c, _d;
631
- chainId = Number(chainId);
632
- const toast = RootStore.Get(ToastPlugin);
633
- try {
634
- if (!chainId || !address)
635
- throw new Error("chainId, address, is required");
636
- await RootStore.Get(_WalletStore).prepare(chainId);
637
- if (loadingText)
638
- toast.loading(loadingText);
639
- const historyStore = RootStore.Get(WalletHistoryStore);
640
- const hash = await this.walletClient.sendTransaction({
641
- account: this.account,
642
- to: address,
643
- data,
644
- value: value ? BigInt(value) : void 0
645
- });
646
- let receipt = await this.waitForTransactionReceipt({ hash });
647
- if (historyItem) {
648
- historyStore.recordHistory(__spreadProps(__spreadValues({}, historyItem), { tx: receipt.transactionHash, timestamp: Date.now(), status: "loading", chainId: Number(chainId) }));
649
- }
650
- onSended ? onSended({ res: receipt }) : null;
651
- if (receipt.status == "success") {
652
- if (historyItem) {
653
- if (showSuccessDialog) {
654
- ShowSuccessTxDialog({ msg: historyItem.msg, hash });
655
- }
656
- historyStore.updateHistoryStatusByTx(receipt.transactionHash, "success");
657
- }
658
- onSuccess && onSuccess({ res: receipt });
659
- toast.dismiss();
660
- toast.success("The transaction was successful");
661
- } else {
662
- if (historyItem) {
663
- historyStore.updateHistoryStatusByTx(receipt.transactionHash, "fail");
664
- }
665
- onError && (onError == null ? void 0 : onError(new Error("The transaction failed")));
666
- toast.dismiss();
667
- toast.error("The transaction failed");
668
- }
669
- return receipt;
670
- } catch (error) {
671
- console.log(error, "xty");
672
- toast.dismiss();
673
- onError == null ? void 0 : onError(error);
674
- console.log(error.message);
675
- /reason="[A-Za-z0-9_ :"]*/g.exec(error == null ? void 0 : error.message);
676
- if (((_a = error == null ? void 0 : error.message) == null ? void 0 : _a.includes("rejected")) || ((_b = error == null ? void 0 : error.message) == null ? void 0 : _b.includes("cancel")) || String(error).toLowerCase().includes("rejected") || String(error).toLowerCase().includes("user denied")) {
677
- autoAlert && toast.error("User rejected transaction");
678
- return;
679
- }
680
- if ((_c = error == null ? void 0 : error.message) == null ? void 0 : _c.includes("Price slippage check")) {
681
- autoAlert && toast.error("The latest pool price has changed, please try to increase the slippage tolerance or reload the page.");
682
- return;
683
- }
684
- if (error == null ? void 0 : error.message.includes("viem")) {
685
- const messageArr = error == null ? void 0 : error.message.split("\n");
686
- console.log("messageArr---", messageArr);
687
- if (messageArr.length > 0) {
688
- onError == null ? void 0 : onError(new Error((_d = messageArr[0]) != null ? _d : "Transaction failed"));
689
- return;
690
- }
691
- }
692
- if (!autoAlert) {
693
- onError == null ? void 0 : onError(error);
694
- throw error;
695
- }
696
- }
697
- }
698
- };
699
24
  var iotex = __spreadValues({
700
25
  iconUrl: "https://cdn-dapp-works.s3.us-east-1.amazonaws.com/1dd84d927ae959c508392be62e6eb549.png"
701
26
  }, iotex$1);
@@ -727,18 +52,18 @@ var WalletProvider = observer(({
727
52
  }
728
53
  });
729
54
  }, []);
730
- return /* @__PURE__ */ React5.createElement(WagmiProvider, { config: walletConfig.rainbowKitConfig, reconnectOnMount: walletConfig.reconnectOnMount }, /* @__PURE__ */ React5.createElement(QueryClientProvider, { client: queryClient }, /* @__PURE__ */ React5.createElement(RainbowKitProvider, { locale: "en", theme: theme == "dark" ? darkTheme() : lightTheme() }, children, compatibleMode ? /* @__PURE__ */ React5.createElement(WalletConnectcompatibleMode, null) : /* @__PURE__ */ React5.createElement(WalletConnect, null))));
55
+ return /* @__PURE__ */ React2.createElement(WagmiProvider, { config: walletConfig.rainbowKitConfig, reconnectOnMount: walletConfig.reconnectOnMount }, /* @__PURE__ */ React2.createElement(QueryClientProvider, { client: queryClient }, /* @__PURE__ */ React2.createElement(RainbowKitProvider, { locale: "en", theme: theme == "dark" ? darkTheme() : lightTheme() }, children, compatibleMode ? /* @__PURE__ */ React2.createElement(WalletConnectcompatibleMode, null) : /* @__PURE__ */ React2.createElement(WalletConnect, null))));
731
56
  });
732
57
  var WalletConnectcompatibleMode = () => {
733
58
  const wallet = RootStore.Get(WalletStore);
734
59
  wallet.use();
735
- return /* @__PURE__ */ React5.createElement(React5.Fragment, null);
60
+ return /* @__PURE__ */ React2.createElement(React2.Fragment, null);
736
61
  };
737
62
  var WalletConnect = () => {
738
63
  const wallet = RootStore.Get(WalletStore);
739
64
  wallet.useWalletClientWithoutCompatibleMode();
740
65
  wallet.use();
741
- return /* @__PURE__ */ React5.createElement(React5.Fragment, null);
66
+ return /* @__PURE__ */ React2.createElement(React2.Fragment, null);
742
67
  };
743
68
  var RpcList = observer(() => {
744
69
  var _a, _b;
@@ -747,9 +72,9 @@ var RpcList = observer(() => {
747
72
  useEffect(() => {
748
73
  rpcStore.testRpc();
749
74
  }, []);
750
- return /* @__PURE__ */ React5.createElement("div", { className: "mb-3 mt-4" }, /* @__PURE__ */ React5.createElement("div", { className: "w-full flex mb-2 mt-2" }, /* @__PURE__ */ React5.createElement("div", { className: "flex items-center justify-center gap-2" }, /* @__PURE__ */ React5.createElement(Checkbox, { size: "sm", isSelected: rpcStore.isAutoSelectRpc.value, onValueChange: (e) => rpcStore.isAutoSelectRpc.save(e) }, "Auto select rpc"), /* @__PURE__ */ React5.createElement(Tooltip, { content: /* @__PURE__ */ React5.createElement("div", { className: "w-[300px]" }, "Once selected, if the current RPC cannot send a request, an available RPC will be automatically chosen.") }, /* @__PURE__ */ React5.createElement(Icon, { icon: "ph:question", width: "18", height: "18", className: "text-gray-500" }))), /* @__PURE__ */ React5.createElement(Button, { startContent: /* @__PURE__ */ React5.createElement(Icon, { icon: "tabler:test-pipe", width: "18", height: "18" }), className: "ml-auto", onClick: (e) => {
75
+ return /* @__PURE__ */ React2.createElement("div", { className: "mb-3 mt-4" }, /* @__PURE__ */ React2.createElement("div", { className: "w-full flex mb-2 mt-2" }, /* @__PURE__ */ React2.createElement("div", { className: "flex items-center justify-center gap-2" }, /* @__PURE__ */ React2.createElement(Checkbox, { size: "sm", isSelected: rpcStore.isAutoSelectRpc.value, onValueChange: (e) => rpcStore.isAutoSelectRpc.save(e) }, "Auto select rpc"), /* @__PURE__ */ React2.createElement(Tooltip, { content: /* @__PURE__ */ React2.createElement("div", { className: "w-[300px]" }, "Once selected, if the current RPC cannot send a request, an available RPC will be automatically chosen.") }, /* @__PURE__ */ React2.createElement(Icon, { icon: "ph:question", width: "18", height: "18", className: "text-gray-500" }))), /* @__PURE__ */ React2.createElement(Button, { startContent: /* @__PURE__ */ React2.createElement(Icon, { icon: "tabler:test-pipe", width: "18", height: "18" }), className: "ml-auto", onClick: (e) => {
751
76
  rpcStore.testRpc();
752
- } }, "Test"), /* @__PURE__ */ React5.createElement(Popover, { placement: "bottom", offset: 20, showArrow: true, isOpen: rpcStore.showCustomRpc, onOpenChange: (open) => rpcStore.showCustomRpc = open }, /* @__PURE__ */ React5.createElement(PopoverTrigger, null, /* @__PURE__ */ React5.createElement(Button, { color: "primary", startContent: /* @__PURE__ */ React5.createElement(Icon, { icon: "basil:add-solid", width: "18", height: "18" }), className: "ml-4" }, "Add custom rpc")), /* @__PURE__ */ React5.createElement(PopoverContent, null, /* @__PURE__ */ React5.createElement("div", { className: "px-1 py-2" }, /* @__PURE__ */ React5.createElement(
77
+ } }, "Test"), /* @__PURE__ */ React2.createElement(Popover, { placement: "bottom", offset: 20, showArrow: true, isOpen: rpcStore.showCustomRpc, onOpenChange: (open) => rpcStore.showCustomRpc = open }, /* @__PURE__ */ React2.createElement(PopoverTrigger, null, /* @__PURE__ */ React2.createElement(Button, { color: "primary", startContent: /* @__PURE__ */ React2.createElement(Icon, { icon: "basil:add-solid", width: "18", height: "18" }), className: "ml-4" }, "Add custom rpc")), /* @__PURE__ */ React2.createElement(PopoverContent, null, /* @__PURE__ */ React2.createElement("div", { className: "px-1 py-2" }, /* @__PURE__ */ React2.createElement(
753
78
  Input,
754
79
  {
755
80
  type: "url",
@@ -760,7 +85,7 @@ var RpcList = observer(() => {
760
85
  rpcStore.customRpc = value;
761
86
  }
762
87
  }
763
- ), /* @__PURE__ */ React5.createElement(Button, { color: "primary", isDisabled: !rpcStore.customRpc, onClick: (e) => rpcStore.addCustomRpc() }, "Save"))))), /* @__PURE__ */ React5.createElement(
88
+ ), /* @__PURE__ */ React2.createElement(Button, { color: "primary", isDisabled: !rpcStore.customRpc, onClick: (e) => rpcStore.addCustomRpc() }, "Save"))))), /* @__PURE__ */ React2.createElement(
764
89
  Table,
765
90
  {
766
91
  color: "success",
@@ -768,22 +93,22 @@ var RpcList = observer(() => {
768
93
  defaultSelectedKeys: [rpcStore.curRpc.value],
769
94
  "aria-label": "Example static collection table"
770
95
  },
771
- /* @__PURE__ */ React5.createElement(TableHeader, null, /* @__PURE__ */ React5.createElement(TableColumn, null, "RPC Server Address"), /* @__PURE__ */ React5.createElement(TableColumn, { align: "center" }, "Score"), /* @__PURE__ */ React5.createElement(TableColumn, { align: "center" }, "Height"), /* @__PURE__ */ React5.createElement(TableColumn, { align: "center" }, "Latency"), /* @__PURE__ */ React5.createElement(TableColumn, { align: "center" }, "Action")),
772
- /* @__PURE__ */ React5.createElement(TableBody, null, (_b = (_a = rpcStore.rpcList) == null ? void 0 : _a.value) == null ? void 0 : _b.map((item, index) => {
773
- return /* @__PURE__ */ React5.createElement(TableRow, { className: "cursor-pointer", key: item.name, onClick: (e) => {
96
+ /* @__PURE__ */ React2.createElement(TableHeader, null, /* @__PURE__ */ React2.createElement(TableColumn, null, "RPC Server Address"), /* @__PURE__ */ React2.createElement(TableColumn, { align: "center" }, "Score"), /* @__PURE__ */ React2.createElement(TableColumn, { align: "center" }, "Height"), /* @__PURE__ */ React2.createElement(TableColumn, { align: "center" }, "Latency"), /* @__PURE__ */ React2.createElement(TableColumn, { align: "center" }, "Action")),
97
+ /* @__PURE__ */ React2.createElement(TableBody, null, (_b = (_a = rpcStore.rpcList) == null ? void 0 : _a.value) == null ? void 0 : _b.map((item, index) => {
98
+ return /* @__PURE__ */ React2.createElement(TableRow, { className: "cursor-pointer", key: item.name, onClick: (e) => {
774
99
  rpcStore.curRpc.save(item.name);
775
100
  RootStore.Get(ToastPlugin).success("Set rpc success");
776
- } }, /* @__PURE__ */ React5.createElement(TableCell, null, item.name), /* @__PURE__ */ React5.createElement(TableCell, null, rpcStore.scoreIcon(item.latency)), /* @__PURE__ */ React5.createElement(TableCell, null, item.height), /* @__PURE__ */ React5.createElement(TableCell, { className: rpcStore.latencyColor(item.latency) }, item.latency, "s"), /* @__PURE__ */ React5.createElement(TableCell, null, /* @__PURE__ */ React5.createElement("div", { className: "relative flex items-center gap-2" }, /* @__PURE__ */ React5.createElement(Tooltip, { content: "Add to metamask" }, /* @__PURE__ */ React5.createElement("span", { className: "text-lg text-danger cursor-pointer active:opacity-50", onClick: (e) => {
101
+ } }, /* @__PURE__ */ React2.createElement(TableCell, null, item.name), /* @__PURE__ */ React2.createElement(TableCell, null, rpcStore.scoreIcon(item.latency)), /* @__PURE__ */ React2.createElement(TableCell, null, item.height), /* @__PURE__ */ React2.createElement(TableCell, { className: rpcStore.latencyColor(item.latency) }, item.latency, "s"), /* @__PURE__ */ React2.createElement(TableCell, null, /* @__PURE__ */ React2.createElement("div", { className: "relative flex items-center gap-2" }, /* @__PURE__ */ React2.createElement(Tooltip, { content: "Add to metamask" }, /* @__PURE__ */ React2.createElement("span", { className: "text-lg text-danger cursor-pointer active:opacity-50", onClick: (e) => {
777
102
  e.stopPropagation();
778
103
  rpcStore.addToMetamask(item.name);
779
- } }, /* @__PURE__ */ React5.createElement(Icon, { icon: "logos:metamask-icon", width: "18", height: "18" }))), item.custom && /* @__PURE__ */ React5.createElement(Tooltip, { content: "Remove" }, /* @__PURE__ */ React5.createElement("span", { className: "text-lg text-danger cursor-pointer active:opacity-50", onClick: (e) => {
104
+ } }, /* @__PURE__ */ React2.createElement(Icon, { icon: "logos:metamask-icon", width: "18", height: "18" }))), item.custom && /* @__PURE__ */ React2.createElement(Tooltip, { content: "Remove" }, /* @__PURE__ */ React2.createElement("span", { className: "text-lg text-danger cursor-pointer active:opacity-50", onClick: (e) => {
780
105
  e.stopPropagation();
781
106
  rpcStore.removeRpc(item.name);
782
- } }, /* @__PURE__ */ React5.createElement(Icon, { icon: "solar:trash-bin-minimalistic-broken", width: "20", height: "20" }))))));
107
+ } }, /* @__PURE__ */ React2.createElement(Icon, { icon: "solar:trash-bin-minimalistic-broken", width: "20", height: "20" }))))));
783
108
  }))
784
109
  ));
785
110
  });
786
111
 
787
- export { RpcList, WalletConfigStore, WalletHistoryStore, WalletProvider, WalletRpcStore, WalletStore, iotex, iotexTestnet };
112
+ export { RpcList, WalletProvider, iotex, iotexTestnet };
788
113
  //# sourceMappingURL=out.js.map
789
114
  //# sourceMappingURL=wallet.mjs.map