@unisat/wallet-state 1.0.1 → 1.0.2

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/lib/index.js ADDED
@@ -0,0 +1,2225 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var reduxLocalstorageSimple = require('redux-localstorage-simple');
6
+ var toolkit = require('@reduxjs/toolkit');
7
+ var react$1 = require('@reduxjs/toolkit/query/react');
8
+ var walletTypes = require('@unisat/wallet-types');
9
+ var walletShared = require('@unisat/wallet-shared');
10
+ var log = require('loglevel');
11
+ var react = require('react');
12
+ var i18n = require('@unisat/i18n');
13
+ var jsxRuntime = require('react/jsx-runtime');
14
+ var compareVersions = require('compare-versions');
15
+ var i18n$1 = require('i18next');
16
+ var reactI18next = require('react-i18next');
17
+ var types = require('@unisat/babylon-service/types');
18
+ require('@unisat/keyring-service/types');
19
+ var reactRedux = require('react-redux');
20
+ var reactRouterDom = require('react-router-dom');
21
+ var baseUtils = require('@unisat/base-utils');
22
+
23
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
24
+
25
+ var log__default = /*#__PURE__*/_interopDefault(log);
26
+ var compareVersions__default = /*#__PURE__*/_interopDefault(compareVersions);
27
+ var i18n__default = /*#__PURE__*/_interopDefault(i18n$1);
28
+
29
+ // src/index.ts
30
+ var updateVersion = toolkit.createAction("global/updateVersion");
31
+
32
+ // src/reducers/accounts.ts
33
+ var initialAccount = {
34
+ type: "",
35
+ address: "",
36
+ brandName: "",
37
+ alianName: "",
38
+ displayBrandName: "",
39
+ index: 0,
40
+ balance: 0,
41
+ pubkey: "",
42
+ key: "",
43
+ flag: 0
44
+ };
45
+ var initialState = {
46
+ accounts: [],
47
+ current: initialAccount,
48
+ loading: false,
49
+ balanceMap: {},
50
+ balanceV2Map: {},
51
+ historyMap: {},
52
+ inscriptionsMap: {},
53
+ appSummary: {
54
+ apps: []
55
+ },
56
+ inscriptionSummary: {
57
+ mintedList: []
58
+ },
59
+ addressSummary: {
60
+ totalSatoshis: 0,
61
+ btcSatoshis: 0,
62
+ assetSatoshis: 0,
63
+ inscriptionCount: 0,
64
+ brc20Count: 0,
65
+ brc20Count5Byte: 0,
66
+ brc20Count6Byte: 0,
67
+ loading: true,
68
+ address: "",
69
+ runesCount: 0
70
+ }
71
+ };
72
+ var slice = toolkit.createSlice({
73
+ name: "accounts",
74
+ initialState,
75
+ reducers: {
76
+ pendingLogin(state) {
77
+ state.loading = true;
78
+ },
79
+ setCurrent(state, action) {
80
+ const { payload } = action;
81
+ state.current = payload || initialAccount;
82
+ },
83
+ setAccounts(state, action) {
84
+ const { payload } = action;
85
+ state.accounts = payload;
86
+ },
87
+ setBalance(state, action) {
88
+ const {
89
+ payload: {
90
+ address,
91
+ amount,
92
+ btc_amount,
93
+ inscription_amount,
94
+ confirm_btc_amount,
95
+ pending_btc_amount
96
+ }
97
+ } = action;
98
+ state.balanceMap[address] = state.balanceMap[address] || {
99
+ amount: "0",
100
+ btc_amount: "0",
101
+ inscription_amount: "0",
102
+ confirm_btc_amount: "0",
103
+ pending_btc_amount: "0",
104
+ expired: true
105
+ };
106
+ state.balanceMap[address].amount = amount;
107
+ state.balanceMap[address].btc_amount = btc_amount;
108
+ state.balanceMap[address].inscription_amount = inscription_amount;
109
+ state.balanceMap[address].confirm_btc_amount = confirm_btc_amount;
110
+ state.balanceMap[address].pending_btc_amount = pending_btc_amount;
111
+ state.balanceMap[address].expired = false;
112
+ },
113
+ setBalanceV2(state, action) {
114
+ const {
115
+ payload: {
116
+ balance: { availableBalance, unavailableBalance, totalBalance },
117
+ address
118
+ }
119
+ } = action;
120
+ state.balanceV2Map[address] = state.balanceV2Map[address] || {
121
+ availableBalance: 0,
122
+ unavailableBalance: 0,
123
+ totalBalance: 0
124
+ };
125
+ state.balanceV2Map[address].availableBalance = availableBalance;
126
+ state.balanceV2Map[address].unavailableBalance = unavailableBalance;
127
+ state.balanceV2Map[address].totalBalance = totalBalance;
128
+ },
129
+ setAddressSummary(state, action) {
130
+ state.addressSummary = action.payload;
131
+ },
132
+ expireBalance(state) {
133
+ const balance = state.balanceMap[state.current.address];
134
+ if (balance) {
135
+ balance.expired = true;
136
+ }
137
+ },
138
+ setHistory(state, action) {
139
+ const {
140
+ payload: { address, list }
141
+ } = action;
142
+ state.historyMap[address] = state.historyMap[address] || {
143
+ list: [],
144
+ expired: true
145
+ };
146
+ state.historyMap[address].list = list;
147
+ state.historyMap[address].expired = false;
148
+ },
149
+ expireHistory(state) {
150
+ const history = state.historyMap[state.current.address];
151
+ if (history) {
152
+ history.expired = true;
153
+ }
154
+ },
155
+ setInscriptions(state, action) {
156
+ const {
157
+ payload: { address, list }
158
+ } = action;
159
+ state.inscriptionsMap[address] = state.inscriptionsMap[address] || {
160
+ list: [],
161
+ expired: true
162
+ };
163
+ state.inscriptionsMap[address].list = list;
164
+ state.inscriptionsMap[address].expired = false;
165
+ },
166
+ expireInscriptions(state) {
167
+ const inscriptions = state.inscriptionsMap[state.current.address];
168
+ if (inscriptions) {
169
+ inscriptions.expired = true;
170
+ }
171
+ },
172
+ setCurrentAccountName(state, action) {
173
+ const { payload } = action;
174
+ state.current.alianName = payload;
175
+ const account = state.accounts.find((v) => v.address === state.current.address);
176
+ if (account) {
177
+ account.alianName = payload;
178
+ }
179
+ },
180
+ setCurrentAddressFlag(state, action) {
181
+ const { payload } = action;
182
+ state.current.flag = payload;
183
+ const account = state.accounts.find((v) => v.address === state.current.address);
184
+ if (account) {
185
+ account.flag = payload;
186
+ }
187
+ },
188
+ setInscriptionSummary(state, action) {
189
+ const { payload } = action;
190
+ state.inscriptionSummary = payload;
191
+ },
192
+ setAppSummary(state, action) {
193
+ const { payload } = action;
194
+ state.appSummary = payload;
195
+ },
196
+ rejectLogin(state) {
197
+ state.loading = false;
198
+ },
199
+ reset(state) {
200
+ return initialState;
201
+ },
202
+ updateAccountName(state, action) {
203
+ const account = action.payload;
204
+ if (state.current.key === account.key) {
205
+ state.current.alianName = account.alianName;
206
+ }
207
+ state.accounts.forEach((v) => {
208
+ if (v.key === account.key) {
209
+ v.alianName = account.alianName;
210
+ }
211
+ });
212
+ }
213
+ },
214
+ extraReducers: (builder) => {
215
+ builder.addCase(updateVersion, (state) => {
216
+ if (!state.addressSummary) {
217
+ state.addressSummary = {
218
+ totalSatoshis: 0,
219
+ btcSatoshis: 0,
220
+ assetSatoshis: 0,
221
+ inscriptionCount: 0,
222
+ brc20Count: 0,
223
+ brc20Count5Byte: 0,
224
+ brc20Count6Byte: 0,
225
+ loading: true,
226
+ address: "",
227
+ runesCount: 0
228
+ };
229
+ }
230
+ if (!state.balanceV2Map) {
231
+ state.balanceV2Map = {};
232
+ }
233
+ });
234
+ }
235
+ });
236
+ var accountActions = slice.actions;
237
+ var accounts_default = slice.reducer;
238
+ var initialState2 = {
239
+ bannerList: [],
240
+ appList: [],
241
+ lastFetchTime: 0,
242
+ lastFetchChainType: walletTypes.ChainType.BITCOIN_MAINNET,
243
+ cachedBannerIds: [],
244
+ hasNewBanner: true
245
+ };
246
+ var slice2 = toolkit.createSlice({
247
+ name: "discovery",
248
+ initialState: initialState2,
249
+ reducers: {
250
+ reset(state) {
251
+ return initialState2;
252
+ },
253
+ setBannerList(state, action) {
254
+ const { payload } = action;
255
+ const newBannerIds = payload.bannerList.map((banner) => banner.id);
256
+ const hasNewBanner = newBannerIds.some((id) => !state.cachedBannerIds.includes(id));
257
+ state.bannerList = payload.bannerList;
258
+ state.lastFetchChainType = payload.chainType;
259
+ state.lastFetchTime = payload.fetchTime;
260
+ state.hasNewBanner = hasNewBanner;
261
+ state.cachedBannerIds = newBannerIds;
262
+ },
263
+ setAppList(state, action) {
264
+ const { payload } = action;
265
+ state.appList = payload.appList;
266
+ state.lastFetchChainType = payload.chainType;
267
+ state.lastFetchTime = payload.fetchTime;
268
+ },
269
+ clearNewBannerFlag(state) {
270
+ state.hasNewBanner = false;
271
+ }
272
+ }
273
+ });
274
+ slice2.actions;
275
+ var discovery_default = slice2.reducer;
276
+ var initialState3 = {
277
+ tab: "home",
278
+ isUnlocked: false,
279
+ isReady: false,
280
+ isBooted: false
281
+ };
282
+ var reducers = {
283
+ reset: (state) => initialState3,
284
+ update: (state, action) => {
285
+ const { payload } = action;
286
+ state = Object.assign({}, state, payload);
287
+ return state;
288
+ }
289
+ };
290
+ var slice3 = toolkit.createSlice({
291
+ name: "global",
292
+ initialState: initialState3,
293
+ reducers,
294
+ extraReducers: (builder) => {
295
+ builder.addCase(updateVersion, (state) => {
296
+ });
297
+ }
298
+ });
299
+ var globalActions = slice3.actions;
300
+ var global_default = slice3.reducer;
301
+ var initialKeyring = {
302
+ key: "",
303
+ index: 0,
304
+ type: "",
305
+ addressType: walletTypes.AddressType.P2TR,
306
+ accounts: [],
307
+ alianName: "",
308
+ hdPath: ""
309
+ };
310
+ var initialState4 = {
311
+ keyrings: [],
312
+ current: initialKeyring
313
+ };
314
+ var slice4 = toolkit.createSlice({
315
+ name: "keyrings",
316
+ initialState: initialState4,
317
+ reducers: {
318
+ setCurrent(state, action) {
319
+ const { payload } = action;
320
+ state.current = payload || initialKeyring;
321
+ },
322
+ setKeyrings(state, action) {
323
+ const { payload } = action;
324
+ state.keyrings = payload;
325
+ },
326
+ reset(state) {
327
+ return initialState4;
328
+ },
329
+ updateKeyringName(state, action) {
330
+ const keyring = action.payload;
331
+ if (state.current.key === keyring.key) {
332
+ state.current.alianName = keyring.alianName;
333
+ }
334
+ state.keyrings.forEach((v) => {
335
+ if (v.key === keyring.key) {
336
+ v.alianName = keyring.alianName;
337
+ }
338
+ });
339
+ },
340
+ updateAccountName(state, action) {
341
+ const account = action.payload;
342
+ state.current.accounts.forEach((v) => {
343
+ if (v.key === account.key) {
344
+ v.alianName = account.alianName;
345
+ }
346
+ });
347
+ state.keyrings.forEach((v) => {
348
+ v.accounts.forEach((w) => {
349
+ if (w.key === account.key) {
350
+ w.alianName = account.alianName;
351
+ }
352
+ });
353
+ });
354
+ }
355
+ },
356
+ extraReducers: (builder) => {
357
+ builder.addCase(updateVersion, (state) => {
358
+ });
359
+ }
360
+ });
361
+ var keyringsActions = slice4.actions;
362
+ var keyrings_default = slice4.reducer;
363
+ var initialState5 = {
364
+ locale: "English",
365
+ networkType: walletTypes.NetworkType.MAINNET,
366
+ chainType: walletTypes.ChainType.BITCOIN_MAINNET,
367
+ walletConfig: {
368
+ version: "",
369
+ moonPayEnabled: true,
370
+ statusMessage: "",
371
+ endpoint: "",
372
+ chainTip: "",
373
+ disableUtxoTools: true
374
+ },
375
+ skippedVersion: "",
376
+ autoLockTimeId: walletShared.DEFAULT_LOCKTIME_ID,
377
+ developerMode: false
378
+ };
379
+ var slice5 = toolkit.createSlice({
380
+ name: "settings",
381
+ initialState: initialState5,
382
+ reducers: {
383
+ reset(state) {
384
+ return initialState5;
385
+ },
386
+ updateSettings(state, action) {
387
+ const { payload } = action;
388
+ state = Object.assign({}, state, payload);
389
+ return state;
390
+ }
391
+ },
392
+ extraReducers: (builder) => {
393
+ builder.addCase(updateVersion, (state) => {
394
+ if (!state.networkType) {
395
+ state.networkType = walletTypes.NetworkType.MAINNET;
396
+ }
397
+ });
398
+ }
399
+ });
400
+ var settingsActions = slice5.actions;
401
+ var settings_default = slice5.reducer;
402
+ var initialState6 = {
403
+ bitcoinTx: {
404
+ fromAddress: "",
405
+ toAddress: "",
406
+ toSatoshis: 0,
407
+ rawtx: "",
408
+ txid: "",
409
+ fee: 0,
410
+ estimateFee: 0,
411
+ changeSatoshis: 0,
412
+ sending: false,
413
+ autoAdjust: false,
414
+ psbtHex: "",
415
+ feeRate: 5,
416
+ toDomain: "",
417
+ enableRBF: false
418
+ },
419
+ ordinalsTx: {
420
+ fromAddress: "",
421
+ toAddress: "",
422
+ inscription: {
423
+ inscriptionId: "",
424
+ inscriptionNumber: 0,
425
+ address: "",
426
+ outputValue: 0,
427
+ preview: "",
428
+ content: "",
429
+ contentType: "",
430
+ contentLength: 0,
431
+ timestamp: 0,
432
+ genesisTransaction: "",
433
+ location: "",
434
+ output: "",
435
+ offset: 0,
436
+ contentBody: "",
437
+ utxoHeight: 0,
438
+ utxoConfirmation: 0
439
+ },
440
+ rawtx: "",
441
+ txid: "",
442
+ fee: 0,
443
+ estimateFee: 0,
444
+ changeSatoshis: 0,
445
+ sending: false,
446
+ psbtHex: "",
447
+ feeRate: 5,
448
+ toDomain: "",
449
+ outputValue: 1e4,
450
+ enableRBF: false
451
+ },
452
+ runesTx: {
453
+ fromAddress: "",
454
+ toAddress: "",
455
+ rawtx: "",
456
+ txid: "",
457
+ fee: 0,
458
+ estimateFee: 0,
459
+ changeSatoshis: 0,
460
+ sending: false,
461
+ psbtHex: "",
462
+ feeRate: 5,
463
+ toDomain: "",
464
+ outputValue: 1e4,
465
+ enableRBF: false
466
+ },
467
+ utxos: [],
468
+ spendUnavailableUtxos: [],
469
+ assetUtxos_inscriptions: [],
470
+ assetUtxos_runes: []
471
+ };
472
+ var slice6 = toolkit.createSlice({
473
+ name: "transactions",
474
+ initialState: initialState6,
475
+ reducers: {
476
+ updateBitcoinTx(state, action) {
477
+ const { payload } = action;
478
+ state.bitcoinTx = Object.assign({}, state.bitcoinTx, payload);
479
+ },
480
+ updateOrdinalsTx(state, action) {
481
+ const { payload } = action;
482
+ state.ordinalsTx = Object.assign({}, state.ordinalsTx, payload);
483
+ },
484
+ updateRunesTx(state, action) {
485
+ const { payload } = action;
486
+ state.runesTx = Object.assign({}, state.runesTx, payload);
487
+ },
488
+ setUtxos(state, action) {
489
+ state.utxos = action.payload;
490
+ },
491
+ setSpendUnavailableUtxos(state, action) {
492
+ state.spendUnavailableUtxos = action.payload;
493
+ },
494
+ setAssetUtxosInscriptions(state, action) {
495
+ state.assetUtxos_inscriptions = action.payload;
496
+ },
497
+ setAssetUtxosRunes(state, action) {
498
+ state.assetUtxos_runes = action.payload;
499
+ },
500
+ reset(state) {
501
+ return initialState6;
502
+ }
503
+ },
504
+ extraReducers: (builder) => {
505
+ builder.addCase(updateVersion, (state) => {
506
+ if (!state.assetUtxos_inscriptions) {
507
+ state.assetUtxos_inscriptions = [];
508
+ }
509
+ if (!state.spendUnavailableUtxos) {
510
+ state.spendUnavailableUtxos = [];
511
+ }
512
+ if (!state.assetUtxos_runes) {
513
+ state.assetUtxos_runes = [];
514
+ }
515
+ });
516
+ }
517
+ });
518
+ var transactionsActions = slice6.actions;
519
+ var transactions_default = slice6.reducer;
520
+ var initialState7 = {
521
+ assetTabKey: 0 /* ORDINALS */,
522
+ ordinalsAssetTabKey: 0 /* ALL */,
523
+ catAssetTabKey: 0 /* CAT20 */,
524
+ alkanesAssetTabKey: 0 /* TOKEN */,
525
+ uiTxCreateScreen: {
526
+ toInfo: {
527
+ address: "",
528
+ domain: ""
529
+ },
530
+ inputAmount: "",
531
+ enableRBF: false,
532
+ feeRate: 1
533
+ },
534
+ babylonSendScreen: {
535
+ inputAmount: "",
536
+ memo: ""
537
+ },
538
+ navigationSource: 1 /* NORMAL */,
539
+ isBalanceHidden: false
540
+ };
541
+ var slice7 = toolkit.createSlice({
542
+ name: "ui",
543
+ initialState: initialState7,
544
+ reducers: {
545
+ reset(state) {
546
+ return initialState7;
547
+ },
548
+ updateAssetTabScreen(state, action) {
549
+ const { payload } = action;
550
+ if (payload.assetTabKey !== void 0) {
551
+ state.assetTabKey = payload.assetTabKey;
552
+ }
553
+ if (payload.ordinalsAssetTabKey !== void 0) {
554
+ state.ordinalsAssetTabKey = payload.ordinalsAssetTabKey;
555
+ }
556
+ if (payload.catAssetTabKey !== void 0) {
557
+ state.catAssetTabKey = payload.catAssetTabKey;
558
+ }
559
+ if (payload.alkanesAssetTabKey !== void 0) {
560
+ state.alkanesAssetTabKey = payload.alkanesAssetTabKey;
561
+ }
562
+ return state;
563
+ },
564
+ updateTxCreateScreen(state, action) {
565
+ if (action.payload.toInfo !== void 0) {
566
+ state.uiTxCreateScreen.toInfo = action.payload.toInfo;
567
+ }
568
+ if (action.payload.inputAmount !== void 0) {
569
+ state.uiTxCreateScreen.inputAmount = action.payload.inputAmount;
570
+ }
571
+ if (action.payload.enableRBF !== void 0) {
572
+ state.uiTxCreateScreen.enableRBF = action.payload.enableRBF;
573
+ }
574
+ if (action.payload.feeRate !== void 0) {
575
+ state.uiTxCreateScreen.feeRate = action.payload.feeRate;
576
+ }
577
+ },
578
+ resetTxCreateScreen(state) {
579
+ state.uiTxCreateScreen = initialState7.uiTxCreateScreen;
580
+ },
581
+ updateBabylonSendScreen(state, action) {
582
+ if (action.payload.inputAmount !== void 0) {
583
+ state.babylonSendScreen.inputAmount = action.payload.inputAmount;
584
+ }
585
+ if (action.payload.memo !== void 0) {
586
+ state.babylonSendScreen.memo = action.payload.memo;
587
+ }
588
+ },
589
+ resetBabylonSendScreen(state) {
590
+ state.babylonSendScreen = initialState7.babylonSendScreen;
591
+ },
592
+ setNavigationSource(state, action) {
593
+ state.navigationSource = action.payload;
594
+ },
595
+ setBalanceHidden(state, action) {
596
+ state.isBalanceHidden = action.payload;
597
+ }
598
+ },
599
+ extraReducers: (builder) => {
600
+ builder.addCase(updateVersion, (state) => {
601
+ if (!state.assetTabKey) {
602
+ state.assetTabKey = 0 /* ORDINALS */;
603
+ }
604
+ if (!state.ordinalsAssetTabKey) {
605
+ state.ordinalsAssetTabKey = 0 /* ALL */;
606
+ }
607
+ if (!state.catAssetTabKey) {
608
+ state.catAssetTabKey = 0 /* CAT20 */;
609
+ }
610
+ if (!state.alkanesAssetTabKey) {
611
+ state.alkanesAssetTabKey = 0 /* TOKEN */;
612
+ }
613
+ if (!state.uiTxCreateScreen) {
614
+ state.uiTxCreateScreen = initialState7.uiTxCreateScreen;
615
+ }
616
+ if (!state.babylonSendScreen) {
617
+ state.babylonSendScreen = initialState7.babylonSendScreen;
618
+ }
619
+ if (state.isBalanceHidden === void 0) {
620
+ state.isBalanceHidden = false;
621
+ }
622
+ });
623
+ }
624
+ });
625
+ var uiActions = slice7.actions;
626
+ var ui_default = slice7.reducer;
627
+ var WalletContext = react.createContext(null);
628
+ var WalletProvider = ({
629
+ children,
630
+ wallet
631
+ }) => /* @__PURE__ */ jsxRuntime.jsx(WalletContext.Provider, { value: { wallet }, children });
632
+ var useWallet = () => {
633
+ const { wallet } = react.useContext(WalletContext);
634
+ return wallet;
635
+ };
636
+ var I18nContext = react.createContext({
637
+ t: (key) => key,
638
+ locale: i18n.FALLBACK_LOCALE,
639
+ supportedLocales: [],
640
+ localeNames: {},
641
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
642
+ changeLocale: async () => {
643
+ }
644
+ });
645
+ var I18nProvider = ({ children }) => {
646
+ const [locale, setLocale] = react.useState(i18n.FALLBACK_LOCALE);
647
+ const [isInitialized, setIsInitialized] = react.useState(false);
648
+ const [error, setError] = react.useState(null);
649
+ const wallet = useWallet();
650
+ react.useEffect(() => {
651
+ const initialize = async () => {
652
+ try {
653
+ let localeToUse = i18n.FALLBACK_LOCALE;
654
+ const userSelectedLanguage = localStorage.getItem("userSelectedLanguage") === "true";
655
+ if (userSelectedLanguage) {
656
+ const savedLocale = localStorage.getItem("i18nextLng");
657
+ if (savedLocale && i18n.getSupportedLocales().includes(savedLocale)) {
658
+ localeToUse = savedLocale;
659
+ log__default.default.debug(`Using user selected language: ${savedLocale}`);
660
+ }
661
+ } else {
662
+ try {
663
+ const isFirstOpen = await wallet.getIsFirstOpen();
664
+ if (isFirstOpen) {
665
+ const browserLang = navigator.language;
666
+ log__default.default.debug(`New user - Browser language: ${browserLang}`);
667
+ const mappedLocale = i18n.BROWSER_TO_APP_LOCALE_MAP[browserLang];
668
+ if (mappedLocale && i18n.getSupportedLocales().includes(mappedLocale)) {
669
+ localeToUse = mappedLocale;
670
+ log__default.default.debug(`Using mapped browser language: ${mappedLocale}`);
671
+ } else if (i18n.getSupportedLocales().includes(browserLang)) {
672
+ localeToUse = browserLang;
673
+ log__default.default.debug(`Using browser language: ${browserLang}`);
674
+ } else {
675
+ const mainLang = browserLang.split("-")[0];
676
+ if (i18n.getSupportedLocales().includes(mainLang)) {
677
+ localeToUse = mainLang;
678
+ log__default.default.debug(`Using browser main language: ${mainLang}`);
679
+ } else {
680
+ log__default.default.debug(`Browser language not supported, using default: ${i18n.FALLBACK_LOCALE}`);
681
+ localeToUse = i18n.FALLBACK_LOCALE;
682
+ }
683
+ }
684
+ } else {
685
+ log__default.default.debug("Existing user - Using default English");
686
+ localeToUse = i18n.FALLBACK_LOCALE;
687
+ }
688
+ } catch (error2) {
689
+ log__default.default.error("Failed to get user status, using default language:", error2);
690
+ localeToUse = i18n.FALLBACK_LOCALE;
691
+ }
692
+ }
693
+ localStorage.setItem("i18nextLng", localeToUse);
694
+ await i18n.initI18n(localeToUse);
695
+ chrome.storage.local.set({ i18nextLng: localeToUse });
696
+ await i18n.initI18n(localeToUse);
697
+ setIsInitialized(true);
698
+ } catch (error2) {
699
+ log__default.default.error("Failed to initialize i18n:", error2);
700
+ setLocale(i18n.FALLBACK_LOCALE);
701
+ setIsInitialized(true);
702
+ setError(error2 instanceof Error ? error2 : new Error("Unknown error"));
703
+ }
704
+ };
705
+ initialize();
706
+ }, [wallet]);
707
+ const changeLocale = async (newLocale) => {
708
+ try {
709
+ await i18n.changeLanguage(newLocale);
710
+ setLocale(newLocale);
711
+ localStorage.setItem("userSelectedLanguage", "true");
712
+ localStorage.setItem("i18nextLng", newLocale);
713
+ chrome.storage.local.set({ i18nextLng: newLocale });
714
+ } catch (error2) {
715
+ setError(error2 instanceof Error ? error2 : new Error("Unknown error"));
716
+ }
717
+ };
718
+ const t2 = (key, substitutions) => {
719
+ try {
720
+ return i18n.t(key, substitutions);
721
+ } catch (error2) {
722
+ log__default.default.error(`Translation error for key "${key}":`, error2);
723
+ return key;
724
+ }
725
+ };
726
+ if (!isInitialized) {
727
+ return /* @__PURE__ */ jsxRuntime.jsx(
728
+ "div",
729
+ {
730
+ style: {
731
+ display: "flex",
732
+ flexDirection: "column",
733
+ width: "100vw",
734
+ height: "100vh",
735
+ overflowY: "auto",
736
+ overflowX: "hidden"
737
+ },
738
+ children: /* @__PURE__ */ jsxRuntime.jsx(
739
+ "div",
740
+ {
741
+ style: {
742
+ display: "flex",
743
+ flex: 1,
744
+ flexDirection: "column",
745
+ justifyItems: "center",
746
+ alignItems: "center"
747
+ },
748
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", {})
749
+ }
750
+ )
751
+ }
752
+ );
753
+ }
754
+ if (error && process.env.NODE_ENV === "development") {
755
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { color: "red", padding: "20px" }, children: [
756
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { children: "Error initializing i18n" }),
757
+ /* @__PURE__ */ jsxRuntime.jsx("p", { children: error.message }),
758
+ /* @__PURE__ */ jsxRuntime.jsx("pre", { children: error.stack })
759
+ ] });
760
+ }
761
+ return /* @__PURE__ */ jsxRuntime.jsx(
762
+ I18nContext.Provider,
763
+ {
764
+ value: {
765
+ t: t2,
766
+ locale,
767
+ supportedLocales: i18n.getSupportedLocales(),
768
+ localeNames: i18n.LOCALE_NAMES,
769
+ changeLocale
770
+ },
771
+ children
772
+ }
773
+ );
774
+ };
775
+ function getAddressType(address, networkType) {
776
+ if (address.startsWith("bc1q") || address.startsWith("tb1q")) {
777
+ return walletTypes.AddressType.P2WPKH;
778
+ } else if (address.startsWith("bc1p") || address.startsWith("tb1p")) {
779
+ return walletTypes.AddressType.P2TR;
780
+ } else if (address.startsWith("1") || address.startsWith("m") || address.startsWith("n")) {
781
+ return walletTypes.AddressType.P2PKH;
782
+ } else if (address.startsWith("3") || address.startsWith("2")) {
783
+ return walletTypes.AddressType.P2SH_P2WPKH;
784
+ } else {
785
+ return walletTypes.AddressType.UNKNOWN;
786
+ }
787
+ }
788
+ var fetchLocale = async (locale) => {
789
+ const res = await fetch(`./_locales/${locale}/messages.json`);
790
+ const data = await res.json();
791
+ return Object.keys(data).reduce((res2, key) => {
792
+ return {
793
+ ...res2,
794
+ [key.replace(/__/g, " ")]: data[key].message
795
+ };
796
+ }, {});
797
+ };
798
+ i18n__default.default.use(reactI18next.initReactI18next).init({
799
+ fallbackLng: "en",
800
+ defaultNS: "translations",
801
+ interpolation: {
802
+ escapeValue: false
803
+ // react already safes from xss
804
+ }
805
+ });
806
+ var I18N_NS = "translations";
807
+ var addResourceBundle = async (locale) => {
808
+ if (i18n__default.default.hasResourceBundle(locale, I18N_NS))
809
+ return;
810
+ const bundle = await fetchLocale(locale);
811
+ i18n__default.default.addResourceBundle(locale, "translations", bundle);
812
+ };
813
+ addResourceBundle("en");
814
+ i18n__default.default.on("languageChanged", function(lng) {
815
+ addResourceBundle(lng);
816
+ });
817
+ var i18n_default = i18n__default.default;
818
+ var useAppDispatch = () => reactRedux.useDispatch();
819
+ var useAppSelector = reactRedux.useSelector;
820
+
821
+ // src/hooks/keyrings.ts
822
+ function useKeyringsState() {
823
+ return useAppSelector((state) => state.keyrings);
824
+ }
825
+ function useKeyrings() {
826
+ const keyringsState = useKeyringsState();
827
+ return keyringsState.keyrings;
828
+ }
829
+ function useCurrentKeyring() {
830
+ const keyringsState = useKeyringsState();
831
+ return keyringsState.current;
832
+ }
833
+
834
+ // src/hooks/accounts.ts
835
+ function useAccountsState() {
836
+ return useAppSelector((state) => state.accounts);
837
+ }
838
+ function useCurrentAccount() {
839
+ const accountsState = useAccountsState();
840
+ return accountsState.current;
841
+ }
842
+ function useCurrentAddress() {
843
+ const accountsState = useAccountsState();
844
+ return accountsState.current.address;
845
+ }
846
+ function useAccountBalance() {
847
+ const accountsState = useAccountsState();
848
+ const currentAccount = useCurrentAccount();
849
+ return accountsState.balanceV2Map[currentAccount.address] || {
850
+ availableBalance: 0,
851
+ unavailableBalance: 0,
852
+ totalBalance: 0
853
+ };
854
+ }
855
+ function useAccountAddress() {
856
+ const currentAccount = useCurrentAccount();
857
+ return currentAccount.address;
858
+ }
859
+ function useFetchBalanceCallback() {
860
+ const dispatch = useAppDispatch();
861
+ const wallet = useWallet();
862
+ const currentAccount = useCurrentAccount();
863
+ const balance = useAccountBalance();
864
+ return react.useCallback(async () => {
865
+ if (!currentAccount.address)
866
+ return;
867
+ const summary = await wallet.getAddressSummary(currentAccount.address);
868
+ summary.address = currentAccount.address;
869
+ dispatch(accountActions["setAddressSummary"](summary));
870
+ const balanceV2 = await wallet.getAddressBalanceV2(currentAccount.address);
871
+ dispatch(
872
+ accountActions["setBalanceV2"]({
873
+ address: currentAccount.address,
874
+ balance: balanceV2
875
+ })
876
+ );
877
+ }, [dispatch, wallet, currentAccount, balance]);
878
+ }
879
+ function useReloadAccounts() {
880
+ const dispatch = useAppDispatch();
881
+ const wallet = useWallet();
882
+ return react.useCallback(async () => {
883
+ const keyrings = await wallet.getKeyrings();
884
+ dispatch(keyringsActions["setKeyrings"](keyrings));
885
+ const currentKeyring = await wallet.getCurrentKeyring();
886
+ dispatch(keyringsActions["setCurrent"](currentKeyring));
887
+ const _accounts = await wallet.getAccounts();
888
+ dispatch(accountActions["setAccounts"](_accounts));
889
+ const account = await wallet.getCurrentAccount();
890
+ dispatch(accountActions["setCurrent"](account));
891
+ dispatch(accountActions["expireBalance"](null));
892
+ dispatch(accountActions["expireInscriptions"](null));
893
+ wallet.getWalletConfig().then((data) => {
894
+ dispatch(settingsActions["updateSettings"]({ walletConfig: data }));
895
+ });
896
+ }, [dispatch, wallet]);
897
+ }
898
+
899
+ // src/hooks/settings.ts
900
+ function useSettingsState() {
901
+ return useAppSelector((state) => state.settings);
902
+ }
903
+ function useLocale() {
904
+ const settings = useSettingsState();
905
+ return settings.locale;
906
+ }
907
+ function useChangeLocaleCallback() {
908
+ const dispatch = useAppDispatch();
909
+ const wallet = useWallet();
910
+ return react.useCallback(
911
+ async (locale) => {
912
+ await wallet.setLocale(locale);
913
+ await addResourceBundle(locale);
914
+ i18n_default.changeLanguage(locale);
915
+ dispatch(
916
+ settingsActions.updateSettings({
917
+ locale
918
+ })
919
+ );
920
+ window.location.reload();
921
+ },
922
+ [dispatch, wallet]
923
+ );
924
+ }
925
+ function useNetworkType() {
926
+ const accountsState = useSettingsState();
927
+ const chain = walletShared.CHAINS_MAP[accountsState.chainType];
928
+ if (chain) {
929
+ return chain.networkType;
930
+ } else {
931
+ return walletTypes.NetworkType.TESTNET;
932
+ }
933
+ }
934
+ function useChangeNetworkTypeCallback() {
935
+ const dispatch = useAppDispatch();
936
+ const wallet = useWallet();
937
+ return react.useCallback(
938
+ async (type) => {
939
+ if (type === walletTypes.NetworkType.MAINNET) {
940
+ await wallet.setChainType(walletTypes.ChainType.BITCOIN_MAINNET);
941
+ dispatch(
942
+ settingsActions.updateSettings({
943
+ chainType: walletTypes.ChainType.BITCOIN_MAINNET
944
+ })
945
+ );
946
+ } else if (type === walletTypes.NetworkType.TESTNET) {
947
+ await wallet.setChainType(walletTypes.ChainType.BITCOIN_TESTNET);
948
+ dispatch(
949
+ settingsActions.updateSettings({
950
+ chainType: walletTypes.ChainType.BITCOIN_TESTNET
951
+ })
952
+ );
953
+ }
954
+ },
955
+ [dispatch]
956
+ );
957
+ }
958
+ function useChainType() {
959
+ const accountsState = useSettingsState();
960
+ return accountsState.chainType;
961
+ }
962
+ function useChain() {
963
+ const accountsState = useSettingsState();
964
+ return walletShared.CHAINS_MAP[accountsState.chainType];
965
+ }
966
+ function useChangeChainTypeCallback() {
967
+ const dispatch = useAppDispatch();
968
+ const wallet = useWallet();
969
+ return react.useCallback(
970
+ async (type) => {
971
+ dispatch(
972
+ settingsActions.updateSettings({
973
+ chainType: type
974
+ })
975
+ );
976
+ await wallet.setChainType(type);
977
+ },
978
+ [dispatch]
979
+ );
980
+ }
981
+ function useBTCUnit() {
982
+ const chainType = useChainType();
983
+ return walletShared.CHAINS_MAP[chainType].unit;
984
+ }
985
+ function useTxExplorerUrl(txid) {
986
+ const chain = useChain();
987
+ if (chain.enum === walletTypes.ChainType.BITCOIN_MAINNET) {
988
+ return `${chain.unisatExplorerUrl}/tx/${txid}`;
989
+ } else if (chain.defaultExplorer === "mempool-space") {
990
+ return `${chain.mempoolSpaceUrl}/tx/${txid}`;
991
+ } else {
992
+ return `${chain.unisatExplorerUrl}/tx/${txid}`;
993
+ }
994
+ }
995
+ function useGetTxExplorerUrlCallback() {
996
+ const chain = useChain();
997
+ return react.useCallback(
998
+ (txid) => {
999
+ if (chain.enum === walletTypes.ChainType.BITCOIN_MAINNET) {
1000
+ return `${chain.unisatExplorerUrl}/tx/${txid}`;
1001
+ } else if (chain.defaultExplorer === "mempool-space") {
1002
+ return `${chain.mempoolSpaceUrl}/tx/${txid}`;
1003
+ } else {
1004
+ return `${chain.unisatExplorerUrl}/tx/${txid}`;
1005
+ }
1006
+ },
1007
+ [chain]
1008
+ );
1009
+ }
1010
+ function useAddressExplorerUrl(address) {
1011
+ const chain = useChain();
1012
+ if (chain.enum === walletTypes.ChainType.BITCOIN_MAINNET) {
1013
+ return `${chain.unisatExplorerUrl}/address/${address}`;
1014
+ } else if (chain.defaultExplorer === "mempool-space") {
1015
+ return `${chain.mempoolSpaceUrl}/address/${address}`;
1016
+ } else {
1017
+ return `${chain.unisatExplorerUrl}/address/${address}`;
1018
+ }
1019
+ }
1020
+ function useCAT20TokenInfoExplorerUrl(version, tokenId) {
1021
+ const chain = useChain();
1022
+ if (version === walletShared.CAT_VERSION.V1) {
1023
+ return `${chain.unisatExplorerUrl}/cat20/${tokenId}`;
1024
+ } else {
1025
+ return `${chain.unisatExplorerUrl}/cat20-v2/${tokenId}`;
1026
+ }
1027
+ }
1028
+ function useUnisatWebsite() {
1029
+ const chainType = useChainType();
1030
+ return walletShared.CHAINS_MAP[chainType].unisatUrl;
1031
+ }
1032
+ function useOrdinalsWebsite() {
1033
+ const chainType = useChainType();
1034
+ return walletShared.CHAINS_MAP[chainType].ordinalsUrl;
1035
+ }
1036
+ function useWalletConfig() {
1037
+ const accountsState = useSettingsState();
1038
+ return accountsState.walletConfig;
1039
+ }
1040
+ function useVersionInfo() {
1041
+ const accountsState = useSettingsState();
1042
+ const walletConfig = accountsState.walletConfig;
1043
+ const newVersion = walletConfig.version;
1044
+ const skippedVersion = accountsState.skippedVersion;
1045
+ const currentVesion = walletShared.VERSION;
1046
+ let skipped = false;
1047
+ let latestVersion = "";
1048
+ if (!newVersion) {
1049
+ skipped = true;
1050
+ }
1051
+ if (newVersion == skippedVersion) {
1052
+ skipped = true;
1053
+ }
1054
+ if (newVersion) {
1055
+ if (compareVersions__default.default(currentVesion, newVersion) >= 0) {
1056
+ skipped = true;
1057
+ } else {
1058
+ latestVersion = newVersion;
1059
+ }
1060
+ }
1061
+ if (currentVesion === "0.0.0") {
1062
+ skipped = true;
1063
+ }
1064
+ return {
1065
+ currentVesion,
1066
+ newVersion,
1067
+ latestVersion,
1068
+ skipped
1069
+ };
1070
+ }
1071
+ function useSkipVersionCallback() {
1072
+ const wallet = useWallet();
1073
+ const dispatch = useAppDispatch();
1074
+ return react.useCallback((version) => {
1075
+ wallet.setSkippedVersion(version).then((v) => {
1076
+ dispatch(settingsActions.updateSettings({ skippedVersion: version }));
1077
+ });
1078
+ }, []);
1079
+ }
1080
+ function useAutoLockTimeId() {
1081
+ const state = useSettingsState();
1082
+ return state.autoLockTimeId;
1083
+ }
1084
+ function getAddressTips(address, chanEnum) {
1085
+ let ret = {
1086
+ homeTip: "",
1087
+ sendTip: ""
1088
+ };
1089
+ try {
1090
+ const chain = walletShared.CHAINS_MAP[chanEnum];
1091
+ const addressType = getAddressType(address, chain.networkType);
1092
+ if (chain.isFractal && addressType === walletTypes.AddressType.P2PKH) {
1093
+ ret = {
1094
+ homeTip: i18n.t("legacy_address_warning_3"),
1095
+ sendTip: i18n.t("legacy_address_warning_4")
1096
+ };
1097
+ }
1098
+ } catch (e) {
1099
+ console.log(e);
1100
+ }
1101
+ return ret;
1102
+ }
1103
+ function useAddressTips() {
1104
+ const chain = useChain();
1105
+ const account = useCurrentAccount();
1106
+ return getAddressTips(account.address, chain.enum);
1107
+ }
1108
+ function useCAT721NFTContentBaseUrl(version) {
1109
+ const chainType = useChainType();
1110
+ if (chainType === walletTypes.ChainType.FRACTAL_BITCOIN_MAINNET) {
1111
+ if (version === walletShared.CAT_VERSION.V1) {
1112
+ return "https://tracker-fractal-mainnet.catprotocol.org";
1113
+ } else {
1114
+ return "https://tracker2-fractal-mainnet.catprotocol.org";
1115
+ }
1116
+ } else if (chainType === walletTypes.ChainType.FRACTAL_BITCOIN_TESTNET) {
1117
+ return "https://tracker-fractal-testnet.catprotocol.org";
1118
+ } else {
1119
+ return "";
1120
+ }
1121
+ }
1122
+ function useBRC20MarketPlaceWebsite(ticker) {
1123
+ const chainType = useChainType();
1124
+ if (chainType === walletTypes.ChainType.BITCOIN_MAINNET) {
1125
+ if (ticker.length == 6) {
1126
+ return `${walletShared.CHAINS_MAP[chainType].unisatUrl}/market/brc20_prog?tick=${ticker}`;
1127
+ }
1128
+ }
1129
+ return `${walletShared.CHAINS_MAP[chainType].unisatUrl}/market/brc20?tick=${ticker}`;
1130
+ }
1131
+ function useRunesMarketPlaceWebsite(ticker) {
1132
+ const chainType = useChainType();
1133
+ return `${walletShared.CHAINS_MAP[chainType].unisatUrl}/runes/market?tick=${ticker}`;
1134
+ }
1135
+ function useCAT20MarketPlaceWebsite(tokenId) {
1136
+ const chainType = useChainType();
1137
+ return `${walletShared.CHAINS_MAP[chainType].unisatUrl}/dex/cat20/${tokenId}`;
1138
+ }
1139
+ function useBabylonConfig() {
1140
+ const chainType = useChainType();
1141
+ return types.BABYLON_CONFIG_MAP[chainType] || types.BABYLON_CONFIG_MAP[walletTypes.ChainType.BITCOIN_MAINNET];
1142
+ }
1143
+ function useIsMainnetChain() {
1144
+ const chainType = useChainType();
1145
+ return chainType === walletTypes.ChainType.BITCOIN_MAINNET || chainType === walletTypes.ChainType.FRACTAL_BITCOIN_MAINNET;
1146
+ }
1147
+ function useDeveloperMode() {
1148
+ const settings = useSettingsState();
1149
+ return settings.developerMode;
1150
+ }
1151
+ function useSetDeveloperModeCallback() {
1152
+ const dispatch = useAppDispatch();
1153
+ const wallet = useWallet();
1154
+ return react.useCallback(
1155
+ async (developerMode) => {
1156
+ await wallet.setDeveloperMode(developerMode);
1157
+ dispatch(
1158
+ settingsActions.updateSettings({
1159
+ developerMode
1160
+ })
1161
+ );
1162
+ },
1163
+ [dispatch, wallet]
1164
+ );
1165
+ }
1166
+ var PriceContext = react.createContext({});
1167
+ function usePrice() {
1168
+ const context = react.useContext(PriceContext);
1169
+ if (!context) {
1170
+ throw Error("Feature flag hooks can only be used by children of BridgeProvider.");
1171
+ } else {
1172
+ return context;
1173
+ }
1174
+ }
1175
+ var isRequestingCoinPrice = false;
1176
+ var refreshCoinPriceTime = 0;
1177
+ function PriceProvider({ children }) {
1178
+ const wallet = useWallet();
1179
+ const chainType = useChainType();
1180
+ const chain = useChain();
1181
+ const [isLoadingCoinPrice, setIsLoadingCoinPrice] = react.useState(false);
1182
+ const [coinPrice, setCoinPrice] = react.useState({
1183
+ btc: 0,
1184
+ fb: 0
1185
+ });
1186
+ const refreshCoinPrice = react.useCallback(() => {
1187
+ if (chain.showPrice === false) {
1188
+ return;
1189
+ }
1190
+ if (isRequestingCoinPrice) {
1191
+ return;
1192
+ }
1193
+ if (Date.now() - refreshCoinPriceTime < 30 * 1e3) {
1194
+ return;
1195
+ }
1196
+ isRequestingCoinPrice = true;
1197
+ setIsLoadingCoinPrice(true);
1198
+ wallet.getCoinPrice().then((res) => {
1199
+ refreshCoinPriceTime = Date.now();
1200
+ setCoinPrice(res);
1201
+ }).catch((e) => {
1202
+ setCoinPrice({
1203
+ btc: 0,
1204
+ fb: 0
1205
+ });
1206
+ }).finally(() => {
1207
+ setIsLoadingCoinPrice(false);
1208
+ isRequestingCoinPrice = false;
1209
+ });
1210
+ }, [chainType, chain]);
1211
+ react.useEffect(() => {
1212
+ refreshCoinPrice();
1213
+ }, [refreshCoinPrice]);
1214
+ const value = {
1215
+ isLoadingCoinPrice,
1216
+ coinPrice,
1217
+ refreshCoinPrice
1218
+ };
1219
+ return /* @__PURE__ */ jsxRuntime.jsx(PriceContext.Provider, { value, children });
1220
+ }
1221
+ var UI_TYPE = {
1222
+ Tab: "index",
1223
+ Pop: "popup",
1224
+ Notification: "notification",
1225
+ SidePanel: "sidepanel"
1226
+ };
1227
+ var getUiType = () => {
1228
+ const { pathname } = window.location;
1229
+ return Object.entries(UI_TYPE).reduce((m, [key, value]) => {
1230
+ m[`is${key}`] = pathname === `/${value}.html`;
1231
+ return m;
1232
+ }, {});
1233
+ };
1234
+ var useApproval = () => {
1235
+ const wallet = useWallet();
1236
+ const navigate = reactRouterDom.useNavigate();
1237
+ const getApproval = wallet.getApproval;
1238
+ const resolveApproval = async (data, stay = false, forceReject = false) => {
1239
+ const approval = await getApproval();
1240
+ if (approval) {
1241
+ wallet.resolveApproval(data, forceReject);
1242
+ }
1243
+ if (stay) {
1244
+ return;
1245
+ }
1246
+ setTimeout(() => {
1247
+ navigate("/");
1248
+ });
1249
+ };
1250
+ const rejectApproval = async (err, stay = false, isInternal = false) => {
1251
+ const approval = await getApproval();
1252
+ if (approval) {
1253
+ await wallet.rejectApproval(err, stay, isInternal);
1254
+ }
1255
+ if (!stay) {
1256
+ navigate("/");
1257
+ }
1258
+ };
1259
+ react.useEffect(() => {
1260
+ if (!getUiType().isNotification) {
1261
+ return () => {
1262
+ };
1263
+ }
1264
+ window.addEventListener("beforeunload", rejectApproval);
1265
+ return () => window.removeEventListener("beforeunload", rejectApproval);
1266
+ }, []);
1267
+ return [getApproval, resolveApproval, rejectApproval];
1268
+ };
1269
+
1270
+ // src/hooks/discovery.ts
1271
+ function useDiscoveryState() {
1272
+ return useAppSelector((state) => state.discovery);
1273
+ }
1274
+ function useAppList() {
1275
+ const state = useDiscoveryState();
1276
+ return state.appList;
1277
+ }
1278
+ function useBannerList() {
1279
+ const state = useDiscoveryState();
1280
+ return state.bannerList;
1281
+ }
1282
+ function useLastFetchInfo() {
1283
+ const state = useDiscoveryState();
1284
+ return {
1285
+ lastFetchTime: state.lastFetchTime,
1286
+ lasfFetchChainType: state.lastFetchChainType
1287
+ };
1288
+ }
1289
+ function useHasNewBanner() {
1290
+ const state = useDiscoveryState();
1291
+ return state.hasNewBanner;
1292
+ }
1293
+ function useGlobalState() {
1294
+ return useAppSelector((state) => state.global);
1295
+ }
1296
+ function useTab() {
1297
+ const globalState = useGlobalState();
1298
+ return globalState.tab;
1299
+ }
1300
+ function useSetTabCallback() {
1301
+ const dispatch = useAppDispatch();
1302
+ return react.useCallback(
1303
+ (tab) => {
1304
+ dispatch(
1305
+ globalActions["update"]({
1306
+ tab
1307
+ })
1308
+ );
1309
+ },
1310
+ [dispatch]
1311
+ );
1312
+ }
1313
+ function useBooted() {
1314
+ const globalState = useGlobalState();
1315
+ return globalState.isBooted;
1316
+ }
1317
+ function useIsUnlocked() {
1318
+ const globalState = useGlobalState();
1319
+ return globalState.isUnlocked;
1320
+ }
1321
+ function useIsReady() {
1322
+ const globalState = useGlobalState();
1323
+ return globalState.isReady;
1324
+ }
1325
+ function useUnlockCallback() {
1326
+ const dispatch = useAppDispatch();
1327
+ const wallet = useWallet();
1328
+ const [, resolveApproval] = useApproval();
1329
+ return react.useCallback(
1330
+ async (password) => {
1331
+ await wallet.unlock(password);
1332
+ dispatch(globalActions.update({ isUnlocked: true }));
1333
+ resolveApproval();
1334
+ },
1335
+ [dispatch, wallet]
1336
+ );
1337
+ }
1338
+ function useCreateAccountCallback() {
1339
+ const dispatch = useAppDispatch();
1340
+ const wallet = useWallet();
1341
+ return react.useCallback(
1342
+ async (mnemonics, hdPath, passphrase, addressType, accountCount) => {
1343
+ await wallet.createKeyringWithMnemonics(
1344
+ mnemonics,
1345
+ hdPath,
1346
+ passphrase,
1347
+ addressType,
1348
+ accountCount
1349
+ );
1350
+ dispatch(globalActions.update({ isUnlocked: true }));
1351
+ },
1352
+ [dispatch, wallet]
1353
+ );
1354
+ }
1355
+ function useImportAccountsFromKeystoneCallback() {
1356
+ const dispatch = useAppDispatch();
1357
+ const wallet = useWallet();
1358
+ return react.useCallback(
1359
+ async (urType, urCbor, addressType, accountCount, hdPath, filterPubkey, connectionType = "USB") => {
1360
+ await wallet.createKeyringWithKeystone(
1361
+ urType,
1362
+ urCbor,
1363
+ addressType,
1364
+ hdPath,
1365
+ accountCount,
1366
+ filterPubkey,
1367
+ connectionType
1368
+ );
1369
+ dispatch(globalActions.update({ isUnlocked: true }));
1370
+ },
1371
+ [dispatch, wallet]
1372
+ );
1373
+ }
1374
+ function useCreateColdWalletCallback() {
1375
+ const dispatch = useAppDispatch();
1376
+ const wallet = useWallet();
1377
+ return react.useCallback(
1378
+ async (xpub, addressType, alianName, hdPath, accountCount) => {
1379
+ await wallet.createKeyringWithColdWallet(xpub, addressType, alianName, hdPath, accountCount);
1380
+ dispatch(globalActions.update({ isUnlocked: true }));
1381
+ },
1382
+ [dispatch, wallet]
1383
+ );
1384
+ }
1385
+ var defaultI18nContext = {
1386
+ t: (key) => key,
1387
+ locale: i18n.FALLBACK_LOCALE,
1388
+ supportedLocales: [i18n.FALLBACK_LOCALE],
1389
+ localeNames: i18n.LOCALE_NAMES,
1390
+ changeLocale: async () => {
1391
+ }
1392
+ };
1393
+ var useI18n = () => {
1394
+ try {
1395
+ const context = react.useContext(I18nContext);
1396
+ if (!context) {
1397
+ console.warn("useI18n must be used within an I18nProvider, using default context instead");
1398
+ return defaultI18nContext;
1399
+ }
1400
+ return context;
1401
+ } catch (error) {
1402
+ console.error("Error in useI18n:", error);
1403
+ return defaultI18nContext;
1404
+ }
1405
+ };
1406
+ var getCurrentLocale = async () => {
1407
+ return await i18n.getCurrentLocaleAsync();
1408
+ };
1409
+ var getSpecialLocale = async () => {
1410
+ const currentLocale = await getCurrentLocale();
1411
+ const specialLocales = ["es", "ru", "fr", "ja"];
1412
+ const isSpecialLocale = specialLocales.includes(currentLocale);
1413
+ return { currentLocale, isSpecialLocale };
1414
+ };
1415
+ function useTools() {
1416
+ return {
1417
+ showLoading: (show) => {
1418
+ }
1419
+ };
1420
+ }
1421
+ function useTransactionsState() {
1422
+ return useAppSelector((state) => state.transactions);
1423
+ }
1424
+ function useBitcoinTx() {
1425
+ const transactionsState = useTransactionsState();
1426
+ return transactionsState.bitcoinTx;
1427
+ }
1428
+ function usePrepareSendBTCCallback() {
1429
+ const dispatch = useAppDispatch();
1430
+ const wallet = useWallet();
1431
+ const fromAddress = useAccountAddress();
1432
+ const utxos = useUtxos();
1433
+ const fetchUtxos = useFetchUtxosCallback();
1434
+ useCurrentAccount();
1435
+ useBTCUnit();
1436
+ const { t: t2 } = useI18n();
1437
+ return react.useCallback(
1438
+ async ({
1439
+ toAddressInfo,
1440
+ toAmount,
1441
+ feeRate,
1442
+ enableRBF,
1443
+ memo,
1444
+ memos,
1445
+ disableAutoAdjust
1446
+ }) => {
1447
+ let _utxos = utxos;
1448
+ if (_utxos.length === 0) {
1449
+ _utxos = await fetchUtxos();
1450
+ }
1451
+ const safeBalance = _utxos.filter((v) => v.inscriptions.length == 0).reduce((pre, cur) => pre + cur.satoshis, 0);
1452
+ if (safeBalance < toAmount) {
1453
+ throw new Error(t2("insufficient_balance"));
1454
+ }
1455
+ if (!feeRate) {
1456
+ const summary = await wallet.getFeeSummary();
1457
+ feeRate = summary.list[1].feeRate;
1458
+ }
1459
+ let res;
1460
+ if (safeBalance === toAmount && !disableAutoAdjust) {
1461
+ res = await wallet.sendAllBTC({
1462
+ to: toAddressInfo.address,
1463
+ btcUtxos: _utxos,
1464
+ enableRBF,
1465
+ feeRate
1466
+ });
1467
+ } else {
1468
+ res = await wallet.sendBTC({
1469
+ to: toAddressInfo.address,
1470
+ amount: toAmount,
1471
+ btcUtxos: _utxos,
1472
+ enableRBF,
1473
+ feeRate,
1474
+ memo,
1475
+ memos
1476
+ });
1477
+ }
1478
+ dispatch(
1479
+ transactionsActions.updateBitcoinTx({
1480
+ rawtx: res.rawtx,
1481
+ psbtHex: res.psbtHex,
1482
+ fromAddress,
1483
+ feeRate,
1484
+ enableRBF
1485
+ })
1486
+ );
1487
+ const rawTxInfo = {
1488
+ psbtHex: res.psbtHex,
1489
+ rawtx: res.rawtx,
1490
+ toAddressInfo,
1491
+ fee: res.fee
1492
+ };
1493
+ return rawTxInfo;
1494
+ },
1495
+ [dispatch, wallet, fromAddress, utxos, fetchUtxos]
1496
+ );
1497
+ }
1498
+ function usePrepareSendBypassHeadOffsetsCallback() {
1499
+ const dispatch = useAppDispatch();
1500
+ const wallet = useWallet();
1501
+ const fromAddress = useAccountAddress();
1502
+ useCurrentAccount();
1503
+ useBTCUnit();
1504
+ return react.useCallback(
1505
+ async ({
1506
+ toAddressInfo,
1507
+ toAmount,
1508
+ feeRate
1509
+ }) => {
1510
+ const res = await wallet.sendCoinBypassHeadOffsets(
1511
+ [
1512
+ {
1513
+ address: toAddressInfo.address,
1514
+ satoshis: toAmount
1515
+ }
1516
+ ],
1517
+ feeRate
1518
+ );
1519
+ dispatch(
1520
+ transactionsActions.updateBitcoinTx({
1521
+ rawtx: res.rawtx,
1522
+ psbtHex: res.psbtHex,
1523
+ fromAddress,
1524
+ feeRate
1525
+ })
1526
+ );
1527
+ const rawTxInfo = {
1528
+ psbtHex: res.psbtHex,
1529
+ rawtx: res.rawtx,
1530
+ toAddressInfo,
1531
+ fee: res.fee
1532
+ };
1533
+ return rawTxInfo;
1534
+ },
1535
+ [dispatch, wallet, fromAddress]
1536
+ );
1537
+ }
1538
+ function usePushBitcoinTxCallback() {
1539
+ const dispatch = useAppDispatch();
1540
+ const wallet = useWallet();
1541
+ const tools = useTools();
1542
+ return react.useCallback(
1543
+ async (rawtx) => {
1544
+ const ret = {
1545
+ success: false,
1546
+ txid: "",
1547
+ error: ""
1548
+ };
1549
+ try {
1550
+ tools.showLoading(true);
1551
+ const txid = await wallet.pushTx(rawtx);
1552
+ await baseUtils.timeUtils.sleep(3);
1553
+ tools.showLoading(false);
1554
+ dispatch(transactionsActions.updateBitcoinTx({ txid }));
1555
+ dispatch(accountActions.expireBalance());
1556
+ setTimeout(() => {
1557
+ dispatch(accountActions.expireBalance());
1558
+ }, 2e3);
1559
+ setTimeout(() => {
1560
+ dispatch(accountActions.expireBalance());
1561
+ }, 5e3);
1562
+ ret.success = true;
1563
+ ret.txid = txid;
1564
+ } catch (e) {
1565
+ ret.error = e.message;
1566
+ }
1567
+ return ret;
1568
+ },
1569
+ [dispatch, wallet]
1570
+ );
1571
+ }
1572
+ function useOrdinalsTx() {
1573
+ const transactionsState = useTransactionsState();
1574
+ return transactionsState.ordinalsTx;
1575
+ }
1576
+ function usePrepareSendOrdinalsInscriptionCallback() {
1577
+ const dispatch = useAppDispatch();
1578
+ const wallet = useWallet();
1579
+ const fromAddress = useAccountAddress();
1580
+ const utxos = useUtxos();
1581
+ const fetchUtxos = useFetchUtxosCallback();
1582
+ useCurrentAccount();
1583
+ return react.useCallback(
1584
+ async ({
1585
+ toAddressInfo,
1586
+ inscriptionId,
1587
+ feeRate,
1588
+ outputValue,
1589
+ enableRBF
1590
+ }) => {
1591
+ if (!feeRate) {
1592
+ const summary = await wallet.getFeeSummary();
1593
+ feeRate = summary.list[1].feeRate;
1594
+ }
1595
+ let btcUtxos = utxos;
1596
+ if (btcUtxos.length === 0) {
1597
+ btcUtxos = await fetchUtxos();
1598
+ }
1599
+ const res = await wallet.sendOrdinalsInscription({
1600
+ to: toAddressInfo.address,
1601
+ inscriptionId,
1602
+ feeRate,
1603
+ outputValue,
1604
+ enableRBF,
1605
+ btcUtxos
1606
+ });
1607
+ dispatch(
1608
+ transactionsActions.updateOrdinalsTx({
1609
+ rawtx: res.rawtx,
1610
+ psbtHex: res.psbtHex,
1611
+ fromAddress,
1612
+ // inscription,
1613
+ feeRate,
1614
+ outputValue,
1615
+ enableRBF
1616
+ })
1617
+ );
1618
+ const rawTxInfo = {
1619
+ psbtHex: res.psbtHex,
1620
+ rawtx: res.rawtx,
1621
+ toAddressInfo
1622
+ };
1623
+ return rawTxInfo;
1624
+ },
1625
+ [dispatch, wallet, fromAddress, utxos]
1626
+ );
1627
+ }
1628
+ function usePrepareSendOrdinalsInscriptionsCallback() {
1629
+ const dispatch = useAppDispatch();
1630
+ const wallet = useWallet();
1631
+ const fromAddress = useAccountAddress();
1632
+ const fetchUtxos = useFetchUtxosCallback();
1633
+ const utxos = useUtxos();
1634
+ useCurrentAccount();
1635
+ return react.useCallback(
1636
+ async ({
1637
+ toAddressInfo,
1638
+ inscriptionIds,
1639
+ feeRate,
1640
+ enableRBF
1641
+ }) => {
1642
+ if (!feeRate) {
1643
+ const summary = await wallet.getFeeSummary();
1644
+ feeRate = summary.list[1].feeRate;
1645
+ }
1646
+ let btcUtxos = utxos;
1647
+ if (btcUtxos.length === 0) {
1648
+ btcUtxos = await fetchUtxos();
1649
+ }
1650
+ const res = await wallet.sendOrdinalsInscriptions({
1651
+ to: toAddressInfo.address,
1652
+ inscriptionIds,
1653
+ feeRate,
1654
+ enableRBF,
1655
+ btcUtxos
1656
+ });
1657
+ dispatch(
1658
+ transactionsActions.updateOrdinalsTx({
1659
+ rawtx: res.rawtx,
1660
+ psbtHex: res.psbtHex,
1661
+ fromAddress,
1662
+ feeRate,
1663
+ enableRBF
1664
+ })
1665
+ );
1666
+ const rawTxInfo = {
1667
+ psbtHex: res.psbtHex,
1668
+ rawtx: res.rawtx,
1669
+ toAddressInfo
1670
+ };
1671
+ return rawTxInfo;
1672
+ },
1673
+ [dispatch, wallet, fromAddress, utxos]
1674
+ );
1675
+ }
1676
+ function useCreateSplitTxCallback() {
1677
+ const dispatch = useAppDispatch();
1678
+ const wallet = useWallet();
1679
+ const fromAddress = useAccountAddress();
1680
+ const utxos = useUtxos();
1681
+ const fetchUtxos = useFetchUtxosCallback();
1682
+ useCurrentAccount();
1683
+ return react.useCallback(
1684
+ async ({
1685
+ inscriptionId,
1686
+ feeRate,
1687
+ outputValue,
1688
+ enableRBF
1689
+ }) => {
1690
+ let btcUtxos = utxos;
1691
+ if (btcUtxos.length === 0) {
1692
+ btcUtxos = await fetchUtxos();
1693
+ }
1694
+ const res = await wallet.splitOrdinalsInscription({
1695
+ inscriptionId,
1696
+ feeRate,
1697
+ outputValue,
1698
+ enableRBF,
1699
+ btcUtxos
1700
+ });
1701
+ dispatch(
1702
+ transactionsActions.updateOrdinalsTx({
1703
+ rawtx: res.rawtx,
1704
+ psbtHex: res.psbtHex,
1705
+ fromAddress,
1706
+ // inscription,
1707
+ enableRBF,
1708
+ feeRate,
1709
+ outputValue
1710
+ })
1711
+ );
1712
+ const rawTxInfo = {
1713
+ psbtHex: res.psbtHex,
1714
+ rawtx: res.rawtx,
1715
+ toAddressInfo: {
1716
+ address: fromAddress
1717
+ }
1718
+ };
1719
+ return { rawTxInfo, splitedCount: res.splitedCount };
1720
+ },
1721
+ [dispatch, wallet, fromAddress, utxos]
1722
+ );
1723
+ }
1724
+ function usePushOrdinalsTxCallback() {
1725
+ const dispatch = useAppDispatch();
1726
+ const wallet = useWallet();
1727
+ const tools = useTools();
1728
+ return react.useCallback(
1729
+ async (rawtx) => {
1730
+ const ret = {
1731
+ success: false,
1732
+ txid: "",
1733
+ error: ""
1734
+ };
1735
+ try {
1736
+ tools.showLoading(true);
1737
+ const txid = await wallet.pushTx(rawtx);
1738
+ await baseUtils.timeUtils.sleep(3);
1739
+ tools.showLoading(false);
1740
+ dispatch(transactionsActions.updateOrdinalsTx({ txid }));
1741
+ dispatch(accountActions.expireBalance());
1742
+ setTimeout(() => {
1743
+ dispatch(accountActions.expireBalance());
1744
+ }, 2e3);
1745
+ setTimeout(() => {
1746
+ dispatch(accountActions.expireBalance());
1747
+ }, 5e3);
1748
+ ret.success = true;
1749
+ ret.txid = txid;
1750
+ } catch (e) {
1751
+ console.log(e);
1752
+ ret.error = e.message;
1753
+ }
1754
+ return ret;
1755
+ },
1756
+ [dispatch, wallet]
1757
+ );
1758
+ }
1759
+ function useUtxos() {
1760
+ const transactionsState = useTransactionsState();
1761
+ return transactionsState.utxos;
1762
+ }
1763
+ function useFetchUtxosCallback() {
1764
+ const dispatch = useAppDispatch();
1765
+ const wallet = useWallet();
1766
+ const account = useCurrentAccount();
1767
+ return react.useCallback(async () => {
1768
+ const data = await wallet.getBTCUtxos();
1769
+ dispatch(transactionsActions.setUtxos(data));
1770
+ return data;
1771
+ }, [wallet, account]);
1772
+ }
1773
+ function useSpendUnavailableUtxos() {
1774
+ const transactionsState = useTransactionsState();
1775
+ return transactionsState.spendUnavailableUtxos;
1776
+ }
1777
+ function useSetSpendUnavailableUtxosCallback() {
1778
+ const dispatch = useAppDispatch();
1779
+ return react.useCallback(
1780
+ (utxos) => {
1781
+ dispatch(transactionsActions.setSpendUnavailableUtxos(utxos));
1782
+ },
1783
+ [dispatch]
1784
+ );
1785
+ }
1786
+ function useSafeBalance() {
1787
+ const utxos = useUtxos();
1788
+ return react.useMemo(() => {
1789
+ const satoshis = utxos.filter((v) => v.inscriptions.length === 0).reduce((pre, cur) => pre + cur.satoshis, 0);
1790
+ return baseUtils.numUtils.satoshisToAmount(satoshis);
1791
+ }, [utxos]);
1792
+ }
1793
+ function useAssetUtxosRunes() {
1794
+ const transactionsState = useTransactionsState();
1795
+ return transactionsState.assetUtxos_runes;
1796
+ }
1797
+ function useFetchAssetUtxosRunesCallback() {
1798
+ const dispatch = useAppDispatch();
1799
+ const wallet = useWallet();
1800
+ const account = useCurrentAccount();
1801
+ return react.useCallback(
1802
+ async (rune) => {
1803
+ const data = await wallet.getAssetUtxosRunes(rune);
1804
+ dispatch(transactionsActions.setAssetUtxosRunes(data));
1805
+ return data;
1806
+ },
1807
+ [wallet, account]
1808
+ );
1809
+ }
1810
+ function usePrepareSendRunesCallback() {
1811
+ const dispatch = useAppDispatch();
1812
+ const wallet = useWallet();
1813
+ const fromAddress = useAccountAddress();
1814
+ const utxos = useUtxos();
1815
+ const fetchUtxos = useFetchUtxosCallback();
1816
+ const assetUtxosRunes = useAssetUtxosRunes();
1817
+ const fetchAssetUtxosRunes = useFetchAssetUtxosRunesCallback();
1818
+ const account = useCurrentAccount();
1819
+ return react.useCallback(
1820
+ async ({
1821
+ toAddressInfo,
1822
+ runeid,
1823
+ runeAmount,
1824
+ outputValue,
1825
+ feeRate,
1826
+ enableRBF
1827
+ }) => {
1828
+ if (!feeRate) {
1829
+ const summary = await wallet.getFeeSummary();
1830
+ feeRate = summary.list[1].feeRate;
1831
+ }
1832
+ let btcUtxos = utxos;
1833
+ if (btcUtxos.length === 0) {
1834
+ btcUtxos = await fetchUtxos();
1835
+ }
1836
+ let assetUtxos = assetUtxosRunes;
1837
+ if (assetUtxos.length == 0) {
1838
+ assetUtxos = await fetchAssetUtxosRunes(runeid);
1839
+ }
1840
+ const res = await wallet.sendRunes({
1841
+ to: toAddressInfo.address,
1842
+ runeid,
1843
+ runeAmount,
1844
+ outputValue,
1845
+ feeRate,
1846
+ enableRBF,
1847
+ btcUtxos,
1848
+ assetUtxos
1849
+ });
1850
+ dispatch(
1851
+ transactionsActions.updateRunesTx({
1852
+ rawtx: res.rawtx,
1853
+ psbtHex: res.psbtHex,
1854
+ fromAddress,
1855
+ feeRate,
1856
+ enableRBF,
1857
+ runeid,
1858
+ runeAmount,
1859
+ outputValue
1860
+ })
1861
+ );
1862
+ const rawTxInfo = {
1863
+ psbtHex: res.psbtHex,
1864
+ rawtx: res.rawtx,
1865
+ toAddressInfo
1866
+ };
1867
+ return rawTxInfo;
1868
+ },
1869
+ [dispatch, wallet, fromAddress, utxos, assetUtxosRunes, fetchAssetUtxosRunes, account]
1870
+ );
1871
+ }
1872
+ function useRunesTx() {
1873
+ const transactionsState = useTransactionsState();
1874
+ return transactionsState.runesTx;
1875
+ }
1876
+ function usePrepareSendAlkanesCallback() {
1877
+ const wallet = useWallet();
1878
+ const account = useCurrentAccount();
1879
+ const callback = react.useCallback(
1880
+ async (toAddressInfo, alkaneid, amount, feeRate, enableRBF = false) => {
1881
+ return await wallet.sendAlkanes({
1882
+ to: toAddressInfo.address,
1883
+ alkaneid,
1884
+ amount,
1885
+ feeRate,
1886
+ enableRBF
1887
+ });
1888
+ },
1889
+ [wallet, account]
1890
+ );
1891
+ return callback;
1892
+ }
1893
+ function useUIState() {
1894
+ return useAppSelector((state) => state.ui);
1895
+ }
1896
+ function useAssetTabKey() {
1897
+ const uiState = useUIState();
1898
+ return uiState.assetTabKey;
1899
+ }
1900
+ function useOrdinalsAssetTabKey() {
1901
+ const uiState = useUIState();
1902
+ return uiState.ordinalsAssetTabKey;
1903
+ }
1904
+ function useCATAssetTabKey() {
1905
+ const uiState = useUIState();
1906
+ return uiState.catAssetTabKey;
1907
+ }
1908
+ function useAlkanesAssetTabKey() {
1909
+ const uiState = useUIState();
1910
+ return uiState.alkanesAssetTabKey;
1911
+ }
1912
+ function useUiTxCreateScreen() {
1913
+ const uiState = useUIState();
1914
+ return uiState.uiTxCreateScreen;
1915
+ }
1916
+ function useUpdateUiTxCreateScreen() {
1917
+ const dispatch = useAppDispatch();
1918
+ return ({
1919
+ toInfo,
1920
+ inputAmount,
1921
+ enableRBF,
1922
+ feeRate
1923
+ }) => {
1924
+ dispatch(uiActions.updateTxCreateScreen({ toInfo, inputAmount, enableRBF, feeRate }));
1925
+ };
1926
+ }
1927
+ function useResetUiTxCreateScreen() {
1928
+ const dispatch = useAppDispatch();
1929
+ return () => {
1930
+ dispatch(uiActions.resetTxCreateScreen());
1931
+ };
1932
+ }
1933
+ function useSupportedAssets() {
1934
+ const chainType = useChainType();
1935
+ const currentAddress = useCurrentAddress();
1936
+ useNetworkType();
1937
+ useCurrentAccount();
1938
+ const assetTabKeys = [];
1939
+ const assets = {
1940
+ ordinals: false,
1941
+ runes: false,
1942
+ CAT20: false,
1943
+ alkanes: false
1944
+ };
1945
+ assets.ordinals = true;
1946
+ assetTabKeys.push(0 /* ORDINALS */);
1947
+ assets.runes = true;
1948
+ assetTabKeys.push(2 /* RUNES */);
1949
+ if (chainType === walletTypes.ChainType.FRACTAL_BITCOIN_MAINNET || chainType === walletTypes.ChainType.FRACTAL_BITCOIN_TESTNET) {
1950
+ const addressType = getAddressType(currentAddress);
1951
+ if (addressType == walletTypes.AddressType.P2TR || addressType == walletTypes.AddressType.P2WPKH) {
1952
+ assets.CAT20 = true;
1953
+ assetTabKeys.push(3 /* CAT */);
1954
+ }
1955
+ }
1956
+ if (chainType === walletTypes.ChainType.BITCOIN_SIGNET || chainType === walletTypes.ChainType.BITCOIN_MAINNET) {
1957
+ assets.alkanes = true;
1958
+ assetTabKeys.push(4 /* ALKANES */);
1959
+ }
1960
+ return {
1961
+ tabKeys: assetTabKeys,
1962
+ assets,
1963
+ key: assetTabKeys.join(",")
1964
+ };
1965
+ }
1966
+ var useIsInExpandView = () => {
1967
+ if (typeof window === "undefined") {
1968
+ return false;
1969
+ }
1970
+ return react.useMemo(() => {
1971
+ if (window.innerWidth > 156 * 3) {
1972
+ return true;
1973
+ } else {
1974
+ return false;
1975
+ }
1976
+ }, [window.innerWidth]);
1977
+ };
1978
+ var useUtxoTools = (chain) => {
1979
+ const openUtxoTools = () => {
1980
+ window.open(`${chain.unisatUrl}/utxo?tab=all`);
1981
+ };
1982
+ return {
1983
+ openUtxoTools
1984
+ };
1985
+ };
1986
+
1987
+ // src/utils/eventBus.ts
1988
+ var EventBus = class {
1989
+ constructor() {
1990
+ this.events = {};
1991
+ this.emit = (type, params) => {
1992
+ const listeners = this.events[type];
1993
+ if (listeners) {
1994
+ listeners.forEach((fn) => {
1995
+ fn(params);
1996
+ });
1997
+ }
1998
+ };
1999
+ this.once = (type, fn) => {
2000
+ const listeners = this.events[type];
2001
+ const func = (...params) => {
2002
+ fn(...params);
2003
+ this.events[type] = this.events[type].filter((item) => item !== func);
2004
+ };
2005
+ if (listeners) {
2006
+ this.events[type].push(func);
2007
+ } else {
2008
+ this.events[type] = [func];
2009
+ }
2010
+ };
2011
+ this.addEventListener = (type, fn) => {
2012
+ const listeners = this.events[type];
2013
+ if (listeners) {
2014
+ this.events[type].push(fn);
2015
+ } else {
2016
+ this.events[type] = [fn];
2017
+ }
2018
+ };
2019
+ this.removeEventListener = (type, fn) => {
2020
+ const listeners = this.events[type];
2021
+ if (listeners) {
2022
+ this.events[type] = this.events[type].filter((item) => item !== fn);
2023
+ }
2024
+ };
2025
+ this.removeAllEventListeners = (type) => {
2026
+ this.events[type] = [];
2027
+ };
2028
+ }
2029
+ };
2030
+ var eventBus_default = new EventBus();
2031
+
2032
+ // src/updater/accounts.ts
2033
+ function AccountUpdater() {
2034
+ const dispatch = useAppDispatch();
2035
+ const wallet = useWallet();
2036
+ const currentAccount = useCurrentAccount();
2037
+ const isUnlocked = useIsUnlocked();
2038
+ const selfRef = react.useRef({
2039
+ preAccountKey: "",
2040
+ loadingBalance: false,
2041
+ loadingHistory: false
2042
+ });
2043
+ const self = selfRef.current;
2044
+ const reloadAccounts = useReloadAccounts();
2045
+ const onCurrentChange = react.useCallback(async () => {
2046
+ if (isUnlocked && currentAccount && currentAccount.key != self.preAccountKey) {
2047
+ self.preAccountKey = currentAccount.key;
2048
+ reloadAccounts();
2049
+ }
2050
+ }, [dispatch, currentAccount, wallet, isUnlocked]);
2051
+ react.useEffect(() => {
2052
+ onCurrentChange();
2053
+ }, [currentAccount && currentAccount.key, isUnlocked]);
2054
+ const fetchBalance = useFetchBalanceCallback();
2055
+ react.useEffect(() => {
2056
+ if (self.loadingBalance) {
2057
+ return;
2058
+ }
2059
+ if (!isUnlocked) {
2060
+ return;
2061
+ }
2062
+ self.loadingBalance = true;
2063
+ fetchBalance().finally(() => {
2064
+ self.loadingBalance = false;
2065
+ });
2066
+ }, [fetchBalance, wallet, isUnlocked, self]);
2067
+ react.useEffect(() => {
2068
+ const accountChangeHandler = (account) => {
2069
+ if (account && account.address) {
2070
+ dispatch(accountActions.setCurrent(account));
2071
+ }
2072
+ };
2073
+ eventBus_default.addEventListener("accountsChanged", accountChangeHandler);
2074
+ return () => {
2075
+ eventBus_default.removeEventListener("accountsChanged", accountChangeHandler);
2076
+ };
2077
+ }, [dispatch]);
2078
+ react.useEffect(() => {
2079
+ const chaintChangeHandler = (params) => {
2080
+ dispatch(
2081
+ settingsActions.updateSettings({
2082
+ chainType: params.type
2083
+ })
2084
+ );
2085
+ reloadAccounts();
2086
+ };
2087
+ eventBus_default.addEventListener("chainChanged", chaintChangeHandler);
2088
+ return () => {
2089
+ eventBus_default.removeEventListener("chainChanged", chaintChangeHandler);
2090
+ };
2091
+ }, [dispatch]);
2092
+ react.useEffect(() => {
2093
+ const lockHandler = () => {
2094
+ dispatch(globalActions.update({ isUnlocked: false }));
2095
+ };
2096
+ eventBus_default.addEventListener("lock", lockHandler);
2097
+ return () => {
2098
+ eventBus_default.removeEventListener("lock", lockHandler);
2099
+ };
2100
+ }, [dispatch]);
2101
+ react.useEffect(() => {
2102
+ const unlockHandler = () => {
2103
+ dispatch(globalActions.update({ isUnlocked: true }));
2104
+ };
2105
+ eventBus_default.addEventListener("unlock", unlockHandler);
2106
+ return () => {
2107
+ eventBus_default.removeEventListener("unlock", unlockHandler);
2108
+ };
2109
+ }, [dispatch]);
2110
+ return null;
2111
+ }
2112
+
2113
+ // src/index.ts
2114
+ var PERSISTED_KEYS = ["ui", "discovery"];
2115
+ var store = toolkit.configureStore({
2116
+ reducer: {
2117
+ accounts: accounts_default,
2118
+ transactions: transactions_default,
2119
+ settings: settings_default,
2120
+ global: global_default,
2121
+ keyrings: keyrings_default,
2122
+ ui: ui_default,
2123
+ discovery: discovery_default
2124
+ },
2125
+ middleware: (getDefaultMiddleware) => getDefaultMiddleware({ thunk: true }).concat(reduxLocalstorageSimple.save({ states: PERSISTED_KEYS, debounce: 1e3 })),
2126
+ preloadedState: reduxLocalstorageSimple.load({ states: PERSISTED_KEYS, disableWarnings: true })
2127
+ });
2128
+ store.dispatch(updateVersion());
2129
+ react$1.setupListeners(store.dispatch);
2130
+ var src_default = store;
2131
+
2132
+ exports.AccountUpdater = AccountUpdater;
2133
+ exports.I18nProvider = I18nProvider;
2134
+ exports.PriceProvider = PriceProvider;
2135
+ exports.WalletProvider = WalletProvider;
2136
+ exports.default = src_default;
2137
+ exports.getAddressTips = getAddressTips;
2138
+ exports.getCurrentLocale = getCurrentLocale;
2139
+ exports.getSpecialLocale = getSpecialLocale;
2140
+ exports.getUiType = getUiType;
2141
+ exports.useAddressExplorerUrl = useAddressExplorerUrl;
2142
+ exports.useAddressTips = useAddressTips;
2143
+ exports.useAlkanesAssetTabKey = useAlkanesAssetTabKey;
2144
+ exports.useAppDispatch = useAppDispatch;
2145
+ exports.useAppList = useAppList;
2146
+ exports.useAppSelector = useAppSelector;
2147
+ exports.useApproval = useApproval;
2148
+ exports.useAssetTabKey = useAssetTabKey;
2149
+ exports.useAssetUtxosRunes = useAssetUtxosRunes;
2150
+ exports.useAutoLockTimeId = useAutoLockTimeId;
2151
+ exports.useBRC20MarketPlaceWebsite = useBRC20MarketPlaceWebsite;
2152
+ exports.useBTCUnit = useBTCUnit;
2153
+ exports.useBabylonConfig = useBabylonConfig;
2154
+ exports.useBannerList = useBannerList;
2155
+ exports.useBitcoinTx = useBitcoinTx;
2156
+ exports.useBooted = useBooted;
2157
+ exports.useCAT20MarketPlaceWebsite = useCAT20MarketPlaceWebsite;
2158
+ exports.useCAT20TokenInfoExplorerUrl = useCAT20TokenInfoExplorerUrl;
2159
+ exports.useCAT721NFTContentBaseUrl = useCAT721NFTContentBaseUrl;
2160
+ exports.useCATAssetTabKey = useCATAssetTabKey;
2161
+ exports.useChain = useChain;
2162
+ exports.useChainType = useChainType;
2163
+ exports.useChangeChainTypeCallback = useChangeChainTypeCallback;
2164
+ exports.useChangeLocaleCallback = useChangeLocaleCallback;
2165
+ exports.useChangeNetworkTypeCallback = useChangeNetworkTypeCallback;
2166
+ exports.useCreateAccountCallback = useCreateAccountCallback;
2167
+ exports.useCreateColdWalletCallback = useCreateColdWalletCallback;
2168
+ exports.useCreateSplitTxCallback = useCreateSplitTxCallback;
2169
+ exports.useCurrentKeyring = useCurrentKeyring;
2170
+ exports.useDeveloperMode = useDeveloperMode;
2171
+ exports.useDiscoveryState = useDiscoveryState;
2172
+ exports.useFetchAssetUtxosRunesCallback = useFetchAssetUtxosRunesCallback;
2173
+ exports.useFetchUtxosCallback = useFetchUtxosCallback;
2174
+ exports.useGetTxExplorerUrlCallback = useGetTxExplorerUrlCallback;
2175
+ exports.useGlobalState = useGlobalState;
2176
+ exports.useHasNewBanner = useHasNewBanner;
2177
+ exports.useI18n = useI18n;
2178
+ exports.useImportAccountsFromKeystoneCallback = useImportAccountsFromKeystoneCallback;
2179
+ exports.useIsInExpandView = useIsInExpandView;
2180
+ exports.useIsMainnetChain = useIsMainnetChain;
2181
+ exports.useIsReady = useIsReady;
2182
+ exports.useIsUnlocked = useIsUnlocked;
2183
+ exports.useKeyrings = useKeyrings;
2184
+ exports.useKeyringsState = useKeyringsState;
2185
+ exports.useLastFetchInfo = useLastFetchInfo;
2186
+ exports.useLocale = useLocale;
2187
+ exports.useNetworkType = useNetworkType;
2188
+ exports.useOrdinalsAssetTabKey = useOrdinalsAssetTabKey;
2189
+ exports.useOrdinalsTx = useOrdinalsTx;
2190
+ exports.useOrdinalsWebsite = useOrdinalsWebsite;
2191
+ exports.usePrepareSendAlkanesCallback = usePrepareSendAlkanesCallback;
2192
+ exports.usePrepareSendBTCCallback = usePrepareSendBTCCallback;
2193
+ exports.usePrepareSendBypassHeadOffsetsCallback = usePrepareSendBypassHeadOffsetsCallback;
2194
+ exports.usePrepareSendOrdinalsInscriptionCallback = usePrepareSendOrdinalsInscriptionCallback;
2195
+ exports.usePrepareSendOrdinalsInscriptionsCallback = usePrepareSendOrdinalsInscriptionsCallback;
2196
+ exports.usePrepareSendRunesCallback = usePrepareSendRunesCallback;
2197
+ exports.usePrice = usePrice;
2198
+ exports.usePushBitcoinTxCallback = usePushBitcoinTxCallback;
2199
+ exports.usePushOrdinalsTxCallback = usePushOrdinalsTxCallback;
2200
+ exports.useResetUiTxCreateScreen = useResetUiTxCreateScreen;
2201
+ exports.useRunesMarketPlaceWebsite = useRunesMarketPlaceWebsite;
2202
+ exports.useRunesTx = useRunesTx;
2203
+ exports.useSafeBalance = useSafeBalance;
2204
+ exports.useSetDeveloperModeCallback = useSetDeveloperModeCallback;
2205
+ exports.useSetSpendUnavailableUtxosCallback = useSetSpendUnavailableUtxosCallback;
2206
+ exports.useSetTabCallback = useSetTabCallback;
2207
+ exports.useSettingsState = useSettingsState;
2208
+ exports.useSkipVersionCallback = useSkipVersionCallback;
2209
+ exports.useSpendUnavailableUtxos = useSpendUnavailableUtxos;
2210
+ exports.useSupportedAssets = useSupportedAssets;
2211
+ exports.useTab = useTab;
2212
+ exports.useTransactionsState = useTransactionsState;
2213
+ exports.useTxExplorerUrl = useTxExplorerUrl;
2214
+ exports.useUIState = useUIState;
2215
+ exports.useUiTxCreateScreen = useUiTxCreateScreen;
2216
+ exports.useUnisatWebsite = useUnisatWebsite;
2217
+ exports.useUnlockCallback = useUnlockCallback;
2218
+ exports.useUpdateUiTxCreateScreen = useUpdateUiTxCreateScreen;
2219
+ exports.useUtxoTools = useUtxoTools;
2220
+ exports.useUtxos = useUtxos;
2221
+ exports.useVersionInfo = useVersionInfo;
2222
+ exports.useWallet = useWallet;
2223
+ exports.useWalletConfig = useWalletConfig;
2224
+ //# sourceMappingURL=out.js.map
2225
+ //# sourceMappingURL=index.js.map