@omnisat/lasereyes 0.0.22 → 0.0.24

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/index.d.ts CHANGED
@@ -77,6 +77,7 @@ declare const WALLETS: {
77
77
  };
78
78
 
79
79
  type LaserEyesContextType = {
80
+ isInitializing: boolean;
80
81
  connected: boolean;
81
82
  isConnecting: boolean;
82
83
  publicKey: string;
package/dist/index.js CHANGED
@@ -288,6 +288,7 @@ var initialWalletContext = {
288
288
  hasLeather: false,
289
289
  hasPhantom: false,
290
290
  hasWizz: false,
291
+ isInitializing: true,
291
292
  connected: false,
292
293
  isConnecting: false,
293
294
  publicKey: "",
@@ -514,6 +515,7 @@ var LaserEyesProvider = ({
514
515
  const self = selfRef.current;
515
516
  const [library, setLibrary] = (0, import_react.useState)(null);
516
517
  const [provider, setProvider] = (0, import_react.useState)();
518
+ const [isInitializing, setIsInitializing] = (0, import_react.useState)(true);
517
519
  const [connected, setConnected] = (0, import_react.useState)(false);
518
520
  const [isConnecting, setIsConnecting] = (0, import_react.useState)(false);
519
521
  const [accounts, setAccounts] = (0, import_react.useState)([]);
@@ -545,52 +547,138 @@ var LaserEyesProvider = ({
545
547
  });
546
548
  }
547
549
  }, [config, library]);
550
+ const checkInitializationComplete = () => {
551
+ if (hasUnisat !== void 0 && hasXverse !== void 0 && hasOyl !== void 0 && hasMagicEden !== void 0 && hasOkx !== void 0 && hasLeather !== void 0 && hasPhantom !== void 0 && hasWizz !== void 0) {
552
+ setIsInitializing(false);
553
+ }
554
+ };
548
555
  (0, import_react.useEffect)(() => {
549
- const unisatLib = window == null ? void 0 : window.unisat;
550
- setHasUnisat(!!unisatLib);
556
+ const observer = new MutationObserver(() => {
557
+ const unisatLib = window == null ? void 0 : window.unisat;
558
+ if (unisatLib) {
559
+ setHasUnisat(true);
560
+ observer.disconnect();
561
+ }
562
+ });
563
+ observer.observe(document, { childList: true, subtree: true });
564
+ return () => {
565
+ observer.disconnect();
566
+ };
551
567
  }, []);
552
568
  (0, import_react.useEffect)(() => {
553
- var _a;
554
- const xverseLib = (_a = window == null ? void 0 : window.XverseProviders) == null ? void 0 : _a.BitcoinProvider;
555
- setHasXverse(!!xverseLib);
569
+ const observer = new MutationObserver(() => {
570
+ var _a;
571
+ const xverseLib = (_a = window == null ? void 0 : window.XverseProviders) == null ? void 0 : _a.BitcoinProvider;
572
+ if (xverseLib) {
573
+ setHasXverse(true);
574
+ observer.disconnect();
575
+ }
576
+ });
577
+ observer.observe(document, { childList: true, subtree: true });
578
+ return () => {
579
+ observer.disconnect();
580
+ };
556
581
  }, []);
557
582
  (0, import_react.useEffect)(() => {
558
- const oylLib = window == null ? void 0 : window.oyl;
559
- setHasOyl(!!oylLib);
583
+ const observer = new MutationObserver(() => {
584
+ const oylLib = window == null ? void 0 : window.oyl;
585
+ if (oylLib) {
586
+ setHasOyl(true);
587
+ observer.disconnect();
588
+ }
589
+ });
590
+ observer.observe(document, { childList: true, subtree: true });
591
+ return () => {
592
+ observer.disconnect();
593
+ };
560
594
  }, []);
561
595
  (0, import_react.useEffect)(() => {
562
- const magicEdenLib = window == null ? void 0 : window.magicEden;
563
- setHasMagicEden(!!magicEdenLib);
596
+ const observer = new MutationObserver(() => {
597
+ const magicEdenLib = window == null ? void 0 : window.magicEden;
598
+ if (magicEdenLib) {
599
+ setHasMagicEden(true);
600
+ observer.disconnect();
601
+ }
602
+ });
603
+ observer.observe(document, { childList: true, subtree: true });
604
+ return () => {
605
+ observer.disconnect();
606
+ };
564
607
  }, []);
565
608
  (0, import_react.useEffect)(() => {
566
- }, []);
609
+ const observer = new MutationObserver(() => {
610
+ var _a, _b;
611
+ let foundOkx;
612
+ if (network === TESTNET) {
613
+ foundOkx = (_a = window == null ? void 0 : window.okxwallet) == null ? void 0 : _a.bitcoinTestnet;
614
+ } else if (network === MAINNET) {
615
+ foundOkx = (_b = window == null ? void 0 : window.okxwallet) == null ? void 0 : _b.bitcoin;
616
+ }
617
+ if (foundOkx) {
618
+ setHasOkx(true);
619
+ observer.disconnect();
620
+ }
621
+ });
622
+ observer.observe(document, { childList: true, subtree: true });
623
+ return () => {
624
+ observer.disconnect();
625
+ };
626
+ }, [network]);
567
627
  (0, import_react.useEffect)(() => {
568
- var _a, _b;
569
- let foundOkx;
570
- if (network === TESTNET) {
571
- foundOkx = (_a = window.okxwallet) == null ? void 0 : _a.bitcoinTestnet;
572
- } else if (network === MAINNET) {
573
- foundOkx = (_b = window.okxwallet) == null ? void 0 : _b.bitcoin;
574
- }
575
- setHasOkx(!!foundOkx);
628
+ const observer = new MutationObserver(() => {
629
+ const leatherLib = window == null ? void 0 : window.LeatherProvider;
630
+ if (leatherLib) {
631
+ setHasLeather(true);
632
+ observer.disconnect();
633
+ }
634
+ });
635
+ observer.observe(document, { childList: true, subtree: true });
636
+ return () => {
637
+ observer.disconnect();
638
+ };
576
639
  }, []);
577
640
  (0, import_react.useEffect)(() => {
578
- const leatherLib = window == null ? void 0 : window.LeatherProvider;
579
- setHasLeather(!!leatherLib);
641
+ const observer = new MutationObserver(() => {
642
+ var _a;
643
+ const phantomLib = (_a = window == null ? void 0 : window.phantom) == null ? void 0 : _a.bitcoin;
644
+ if (phantomLib && phantomLib.isPhantom) {
645
+ setHasPhantom(true);
646
+ observer.disconnect();
647
+ } else {
648
+ setHasPhantom(false);
649
+ observer.disconnect();
650
+ }
651
+ });
652
+ observer.observe(document, { childList: true, subtree: true });
653
+ return () => {
654
+ observer.disconnect();
655
+ };
580
656
  }, []);
581
657
  (0, import_react.useEffect)(() => {
582
- var _a;
583
- const phantomLib = (_a = window == null ? void 0 : window.phantom) == null ? void 0 : _a.bitcoin;
584
- if (phantomLib && phantomLib.isPhantom) {
585
- setHasPhantom(!!phantomLib);
586
- } else {
587
- setHasPhantom(false);
588
- }
658
+ const observer = new MutationObserver(() => {
659
+ const wizzLib = window == null ? void 0 : window.wizz;
660
+ if (wizzLib) {
661
+ setHasWizz(true);
662
+ observer.disconnect();
663
+ }
664
+ });
665
+ observer.observe(document, { childList: true, subtree: true });
666
+ return () => {
667
+ observer.disconnect();
668
+ };
589
669
  }, []);
590
670
  (0, import_react.useEffect)(() => {
591
- const wissLib = window == null ? void 0 : window.wizz;
592
- setHasWizz(!!wissLib);
593
- }, []);
671
+ checkInitializationComplete();
672
+ }, [
673
+ hasUnisat,
674
+ hasXverse,
675
+ hasOyl,
676
+ hasMagicEden,
677
+ hasOkx,
678
+ hasLeather,
679
+ hasPhantom,
680
+ hasWizz
681
+ ]);
594
682
  (0, import_react.useEffect)(() => {
595
683
  setBalance(void 0);
596
684
  }, [network]);
@@ -1661,6 +1749,7 @@ var LaserEyesProvider = ({
1661
1749
  provider,
1662
1750
  balance,
1663
1751
  network,
1752
+ isInitializing,
1664
1753
  connected,
1665
1754
  isConnecting,
1666
1755
  hasUnisat,
package/dist/index.mjs CHANGED
@@ -203,6 +203,7 @@ var initialWalletContext = {
203
203
  hasLeather: false,
204
204
  hasPhantom: false,
205
205
  hasWizz: false,
206
+ isInitializing: true,
206
207
  connected: false,
207
208
  isConnecting: false,
208
209
  publicKey: "",
@@ -436,6 +437,7 @@ var LaserEyesProvider = ({
436
437
  const self = selfRef.current;
437
438
  const [library, setLibrary] = useState(null);
438
439
  const [provider, setProvider] = useState();
440
+ const [isInitializing, setIsInitializing] = useState(true);
439
441
  const [connected, setConnected] = useState(false);
440
442
  const [isConnecting, setIsConnecting] = useState(false);
441
443
  const [accounts, setAccounts] = useState([]);
@@ -467,52 +469,138 @@ var LaserEyesProvider = ({
467
469
  });
468
470
  }
469
471
  }, [config, library]);
472
+ const checkInitializationComplete = () => {
473
+ if (hasUnisat !== void 0 && hasXverse !== void 0 && hasOyl !== void 0 && hasMagicEden !== void 0 && hasOkx !== void 0 && hasLeather !== void 0 && hasPhantom !== void 0 && hasWizz !== void 0) {
474
+ setIsInitializing(false);
475
+ }
476
+ };
470
477
  useEffect(() => {
471
- const unisatLib = window == null ? void 0 : window.unisat;
472
- setHasUnisat(!!unisatLib);
478
+ const observer = new MutationObserver(() => {
479
+ const unisatLib = window == null ? void 0 : window.unisat;
480
+ if (unisatLib) {
481
+ setHasUnisat(true);
482
+ observer.disconnect();
483
+ }
484
+ });
485
+ observer.observe(document, { childList: true, subtree: true });
486
+ return () => {
487
+ observer.disconnect();
488
+ };
473
489
  }, []);
474
490
  useEffect(() => {
475
- var _a;
476
- const xverseLib = (_a = window == null ? void 0 : window.XverseProviders) == null ? void 0 : _a.BitcoinProvider;
477
- setHasXverse(!!xverseLib);
491
+ const observer = new MutationObserver(() => {
492
+ var _a;
493
+ const xverseLib = (_a = window == null ? void 0 : window.XverseProviders) == null ? void 0 : _a.BitcoinProvider;
494
+ if (xverseLib) {
495
+ setHasXverse(true);
496
+ observer.disconnect();
497
+ }
498
+ });
499
+ observer.observe(document, { childList: true, subtree: true });
500
+ return () => {
501
+ observer.disconnect();
502
+ };
478
503
  }, []);
479
504
  useEffect(() => {
480
- const oylLib = window == null ? void 0 : window.oyl;
481
- setHasOyl(!!oylLib);
505
+ const observer = new MutationObserver(() => {
506
+ const oylLib = window == null ? void 0 : window.oyl;
507
+ if (oylLib) {
508
+ setHasOyl(true);
509
+ observer.disconnect();
510
+ }
511
+ });
512
+ observer.observe(document, { childList: true, subtree: true });
513
+ return () => {
514
+ observer.disconnect();
515
+ };
482
516
  }, []);
483
517
  useEffect(() => {
484
- const magicEdenLib = window == null ? void 0 : window.magicEden;
485
- setHasMagicEden(!!magicEdenLib);
518
+ const observer = new MutationObserver(() => {
519
+ const magicEdenLib = window == null ? void 0 : window.magicEden;
520
+ if (magicEdenLib) {
521
+ setHasMagicEden(true);
522
+ observer.disconnect();
523
+ }
524
+ });
525
+ observer.observe(document, { childList: true, subtree: true });
526
+ return () => {
527
+ observer.disconnect();
528
+ };
486
529
  }, []);
487
530
  useEffect(() => {
488
- }, []);
531
+ const observer = new MutationObserver(() => {
532
+ var _a, _b;
533
+ let foundOkx;
534
+ if (network === TESTNET) {
535
+ foundOkx = (_a = window == null ? void 0 : window.okxwallet) == null ? void 0 : _a.bitcoinTestnet;
536
+ } else if (network === MAINNET) {
537
+ foundOkx = (_b = window == null ? void 0 : window.okxwallet) == null ? void 0 : _b.bitcoin;
538
+ }
539
+ if (foundOkx) {
540
+ setHasOkx(true);
541
+ observer.disconnect();
542
+ }
543
+ });
544
+ observer.observe(document, { childList: true, subtree: true });
545
+ return () => {
546
+ observer.disconnect();
547
+ };
548
+ }, [network]);
489
549
  useEffect(() => {
490
- var _a, _b;
491
- let foundOkx;
492
- if (network === TESTNET) {
493
- foundOkx = (_a = window.okxwallet) == null ? void 0 : _a.bitcoinTestnet;
494
- } else if (network === MAINNET) {
495
- foundOkx = (_b = window.okxwallet) == null ? void 0 : _b.bitcoin;
496
- }
497
- setHasOkx(!!foundOkx);
550
+ const observer = new MutationObserver(() => {
551
+ const leatherLib = window == null ? void 0 : window.LeatherProvider;
552
+ if (leatherLib) {
553
+ setHasLeather(true);
554
+ observer.disconnect();
555
+ }
556
+ });
557
+ observer.observe(document, { childList: true, subtree: true });
558
+ return () => {
559
+ observer.disconnect();
560
+ };
498
561
  }, []);
499
562
  useEffect(() => {
500
- const leatherLib = window == null ? void 0 : window.LeatherProvider;
501
- setHasLeather(!!leatherLib);
563
+ const observer = new MutationObserver(() => {
564
+ var _a;
565
+ const phantomLib = (_a = window == null ? void 0 : window.phantom) == null ? void 0 : _a.bitcoin;
566
+ if (phantomLib && phantomLib.isPhantom) {
567
+ setHasPhantom(true);
568
+ observer.disconnect();
569
+ } else {
570
+ setHasPhantom(false);
571
+ observer.disconnect();
572
+ }
573
+ });
574
+ observer.observe(document, { childList: true, subtree: true });
575
+ return () => {
576
+ observer.disconnect();
577
+ };
502
578
  }, []);
503
579
  useEffect(() => {
504
- var _a;
505
- const phantomLib = (_a = window == null ? void 0 : window.phantom) == null ? void 0 : _a.bitcoin;
506
- if (phantomLib && phantomLib.isPhantom) {
507
- setHasPhantom(!!phantomLib);
508
- } else {
509
- setHasPhantom(false);
510
- }
580
+ const observer = new MutationObserver(() => {
581
+ const wizzLib = window == null ? void 0 : window.wizz;
582
+ if (wizzLib) {
583
+ setHasWizz(true);
584
+ observer.disconnect();
585
+ }
586
+ });
587
+ observer.observe(document, { childList: true, subtree: true });
588
+ return () => {
589
+ observer.disconnect();
590
+ };
511
591
  }, []);
512
592
  useEffect(() => {
513
- const wissLib = window == null ? void 0 : window.wizz;
514
- setHasWizz(!!wissLib);
515
- }, []);
593
+ checkInitializationComplete();
594
+ }, [
595
+ hasUnisat,
596
+ hasXverse,
597
+ hasOyl,
598
+ hasMagicEden,
599
+ hasOkx,
600
+ hasLeather,
601
+ hasPhantom,
602
+ hasWizz
603
+ ]);
516
604
  useEffect(() => {
517
605
  setBalance(void 0);
518
606
  }, [network]);
@@ -1583,6 +1671,7 @@ var LaserEyesProvider = ({
1583
1671
  provider,
1584
1672
  balance,
1585
1673
  network,
1674
+ isInitializing,
1586
1675
  connected,
1587
1676
  isConnecting,
1588
1677
  hasUnisat,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnisat/lasereyes",
3
- "version": "0.0.22",
3
+ "version": "0.0.24",
4
4
  "sideEffects": false,
5
5
  "private": false,
6
6
  "license": "MIT",