@kwespay/widget 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { EthereumProvider } from '@walletconnect/ethereum-provider';
1
+ import '@walletconnect/ethereum-provider';
2
2
 
3
3
  const SUPPORTED_CURRENCIES = {
4
4
  USD: "USD",
@@ -324,8 +324,6 @@ class WalletService {
324
324
  });
325
325
  }
326
326
 
327
- // ── Device detection ────────────────────────────────────────────────────────
328
-
329
327
  isMobile() {
330
328
  return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
331
329
  navigator.userAgent
@@ -336,7 +334,7 @@ class WalletService {
336
334
  return /iPhone|iPad|iPod/i.test(navigator.userAgent);
337
335
  }
338
336
 
339
- // ── Chain reading ───────────────────────────────────────────────────────────
337
+
340
338
 
341
339
  /**
342
340
  * Live active chain from the wallet via eth_chainId RPC.
@@ -388,12 +386,7 @@ class WalletService {
388
386
  return [...ids];
389
387
  }
390
388
 
391
- /**
392
- * Quick liveness check — sends eth_chainId and returns true if it
393
- * resolves. A stale or disconnected WC session will throw here.
394
- *
395
- * @returns {Promise<boolean>}
396
- */
389
+
397
390
  async isSessionAlive() {
398
391
  if (!this.selectedProvider) return false;
399
392
  try {
@@ -404,7 +397,6 @@ class WalletService {
404
397
  }
405
398
  }
406
399
 
407
- // ── EIP-6963 injected wallet discovery ─────────────────────────────────────
408
400
 
409
401
  discoverInjectedWallets() {
410
402
  return new Promise((resolve) => {
@@ -447,7 +439,6 @@ class WalletService {
447
439
  });
448
440
  }
449
441
 
450
- // ── Injected wallet connection ──────────────────────────────────────────────
451
442
 
452
443
  async connectInjected(index) {
453
444
  const entry = this.injectedProviders[index];
@@ -491,10 +482,13 @@ class WalletService {
491
482
  return this._connectionResult();
492
483
  }
493
484
 
494
- // ── WalletConnect ───────────────────────────────────────────────────────────
485
+
495
486
 
496
487
  async initWalletConnect(onUri, onConnected, onDisconnected) {
497
488
  // Tear down any existing provider before creating a new one
489
+ const { EthereumProvider } = await import(
490
+ '@walletconnect/ethereum-provider'
491
+ );
498
492
  if (this.wcProvider) {
499
493
  try {
500
494
  await this.wcProvider.disconnect();
@@ -532,12 +526,11 @@ class WalletService {
532
526
  this._onWCConnected = onConnected;
533
527
  this._onWCDisconnected = onDisconnected;
534
528
 
535
- // ── display_uri — deep-link / QR is ready ─────────────────────────────────
529
+
536
530
  provider.on("display_uri", (uri) => {
537
531
  if (this._onWCUri) this._onWCUri(uri);
538
532
  });
539
533
 
540
- // ── connect — session fully established ───────────────────────────────────
541
534
  provider.on("connect", async () => {
542
535
  const session = provider.session;
543
536
  const accounts = session?.namespaces?.eip155?.accounts ?? [];
@@ -549,7 +542,7 @@ class WalletService {
549
542
  return;
550
543
  }
551
544
 
552
- // Parse address from CAIP-10: "eip155:<chainId>:<address>"
545
+
553
546
  const address = accounts[0].split(":")[2];
554
547
 
555
548
  this.wcProvider = provider;
@@ -571,15 +564,14 @@ class WalletService {
571
564
  if (this._onWCConnected) this._onWCConnected();
572
565
  });
573
566
 
574
- // ── disconnect ────────────────────────────────────────────────────────────
567
+
575
568
  provider.on("disconnect", () => {
576
569
  console.log("[WalletService] WC session disconnected");
577
570
  this._cleanupWC();
578
571
  if (this._onWCDisconnected) this._onWCDisconnected();
579
572
  });
580
573
 
581
- // ── chainChanged — informational only ─────────────────────────────────────
582
- // We never cache this value. getActiveChainId() always does a live RPC read.
574
+
583
575
  provider.on("chainChanged", (chainId) => {
584
576
  if (this._wcSessionReady) {
585
577
  console.log(
@@ -589,7 +581,7 @@ class WalletService {
589
581
  }
590
582
  });
591
583
 
592
- // ── session_request_sent — foreground wallet on mobile ────────────────────
584
+
593
585
  this._wcSessionRequestSentHandler = () => {
594
586
  if (!this.isMobile()) return;
595
587
  console.log(
@@ -603,17 +595,8 @@ class WalletService {
603
595
  return provider;
604
596
  }
605
597
 
606
- /**
607
- * Start the WalletConnect handshake.
608
- *
609
- * targetChainId is passed as optionalNamespaces so the wallet starts
610
- * the session on the correct chain. Without this hint, MetaMask defaults
611
- * to its last-used WC chain (usually Mainnet) regardless of the wallet's
612
- * current active chain — causing WRONG_NETWORK errors even when the user
613
- * is visually on the right network.
614
- *
615
- * @param {number} targetChainId The chain the payment will be made on
616
- */
598
+
599
+
617
600
  async connectWalletConnect(targetChainId) {
618
601
  if (!this.wcProvider)
619
602
  throw new Error("[WalletService] Call initWalletConnect first");
@@ -645,10 +628,7 @@ class WalletService {
645
628
  });
646
629
  }
647
630
 
648
- /**
649
- * Open the wallet app on mobile to bring it to the foreground.
650
- * Uses redirect URIs from the WC session peer metadata.
651
- */
631
+
652
632
  _openWalletForApproval() {
653
633
  const session = this.wcProvider?.session;
654
634
  const native = session?.peer?.metadata?.redirect?.native;
@@ -670,7 +650,7 @@ class WalletService {
670
650
  }
671
651
  }
672
652
 
673
- // ── Network switching — desktop / injected only ─────────────────────────────
653
+
674
654
 
675
655
  async switchNetwork(
676
656
  chainId,
@@ -717,7 +697,6 @@ class WalletService {
717
697
  }
718
698
  }
719
699
 
720
- // ── Provider event listeners ────────────────────────────────────────────────
721
700
 
722
701
  _attachProviderListeners(provider) {
723
702
  this._accountsChangedHandler = (accounts) => {
@@ -739,7 +718,7 @@ class WalletService {
739
718
  provider.on("chainChanged", this._chainChangedHandler);
740
719
  }
741
720
 
742
- // ── Disconnect / cleanup ────────────────────────────────────────────────────
721
+
743
722
 
744
723
  async disconnect() {
745
724
  if (this.selectedProvider) {
@@ -797,7 +776,6 @@ class WalletService {
797
776
  this._wcSessionRequestSentHandler = null;
798
777
  }
799
778
 
800
- // ── Helpers ─────────────────────────────────────────────────────────────────
801
779
 
802
780
  _connectionResult() {
803
781
  return {
@@ -6778,4 +6756,3 @@ class KwesPayWidget {
6778
6756
  */
6779
6757
 
6780
6758
  export { KwesPayWidget as default };
6781
- //# sourceMappingURL=kwespay-widget.esm.js.map