@lukso/up-connector 0.5.1 → 0.6.0-dev.5ea12c5

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.
Files changed (73) hide show
  1. package/dist/auto-setup.cjs +3 -3
  2. package/dist/auto-setup.js +2 -2
  3. package/dist/{avatar-CmUCtW_w.d.cts → avatar-CQkubMTK.d.cts} +0 -1
  4. package/dist/{avatar-CmUCtW_w.d.ts → avatar-CQkubMTK.d.ts} +0 -1
  5. package/dist/avatar.cjs +2 -2
  6. package/dist/avatar.d.cts +1 -1
  7. package/dist/avatar.d.ts +1 -1
  8. package/dist/avatar.js +1 -1
  9. package/dist/backup-modal.cjs +2 -2
  10. package/dist/backup-modal.js +1 -1
  11. package/dist/{chunk-M4UJAKZ2.cjs → chunk-3IJAXTQI.cjs} +3 -3
  12. package/dist/chunk-3IJAXTQI.cjs.map +1 -0
  13. package/dist/{chunk-ORJK2YGG.cjs → chunk-7LQ5EB2X.cjs} +22 -24
  14. package/dist/chunk-7LQ5EB2X.cjs.map +1 -0
  15. package/dist/{chunk-3SGSPHOZ.js → chunk-A5RRWZ7W.js} +6 -10
  16. package/dist/chunk-A5RRWZ7W.js.map +1 -0
  17. package/dist/{chunk-IAKQFHFD.cjs → chunk-CKVXLOXK.cjs} +6 -10
  18. package/dist/chunk-CKVXLOXK.cjs.map +1 -0
  19. package/dist/{chunk-NWCNJSG3.js → chunk-DQ663HKR.js} +7 -3
  20. package/dist/chunk-DQ663HKR.js.map +1 -0
  21. package/dist/{chunk-CN2BMW6Y.cjs → chunk-GCYDV7FB.cjs} +159 -101
  22. package/dist/chunk-GCYDV7FB.cjs.map +1 -0
  23. package/dist/{chunk-6N35TCFT.js → chunk-GKAVIDXP.js} +21 -23
  24. package/dist/chunk-GKAVIDXP.js.map +1 -0
  25. package/dist/{chunk-5P7EGEE5.js → chunk-QZ55O6GN.js} +4 -4
  26. package/dist/chunk-QZ55O6GN.js.map +1 -0
  27. package/dist/{chunk-3ME6PKYE.js → chunk-SAQWNAQ6.js} +138 -80
  28. package/dist/chunk-SAQWNAQ6.js.map +1 -0
  29. package/dist/{chunk-7ETKG6KR.cjs → chunk-ZRA7ZVHJ.cjs} +7 -3
  30. package/dist/chunk-ZRA7ZVHJ.cjs.map +1 -0
  31. package/dist/connect-modal/index.cjs +4 -2
  32. package/dist/connect-modal/index.cjs.map +1 -1
  33. package/dist/connect-modal/index.d.cts +1 -1
  34. package/dist/connect-modal/index.d.ts +1 -1
  35. package/dist/connect-modal/index.js +11 -9
  36. package/dist/index.cjs +39 -32
  37. package/dist/index.cjs.map +1 -1
  38. package/dist/index.d.cts +5 -5
  39. package/dist/index.d.ts +5 -5
  40. package/dist/index.js +40 -33
  41. package/dist/index.js.map +1 -1
  42. package/dist/restore-modal.cjs +2 -2
  43. package/dist/restore-modal.d.cts +2 -2
  44. package/dist/restore-modal.d.ts +2 -2
  45. package/dist/restore-modal.js +1 -1
  46. package/dist/{wagmi-BLnqILO_.d.cts → wagmi-DgjkdmGk.d.cts} +77 -21
  47. package/dist/{wagmi-BLnqILO_.d.ts → wagmi-DgjkdmGk.d.ts} +77 -21
  48. package/package.json +7 -7
  49. package/src/auto-setup.ts +0 -1
  50. package/src/avatar.ts +20 -23
  51. package/src/backup-modal.ts +6 -2
  52. package/src/connect-modal/components/connection-view.ts +4 -1
  53. package/src/connect-modal/components/eoa-connection-view.ts +4 -0
  54. package/src/connect-modal/connect-modal.types.ts +4 -0
  55. package/src/connect-modal/index.ts +6 -4
  56. package/src/connect-modal/services/wagmi.ts +176 -76
  57. package/src/connect-modal/styles/styles.css +1 -1
  58. package/src/connect-modal/utils/chainParams.ts +32 -0
  59. package/src/connector.ts +22 -20
  60. package/src/index.ts +6 -4
  61. package/src/popup-instance.ts +3 -4
  62. package/src/restore-modal.ts +5 -3
  63. package/src/styles/styles.css +1 -1
  64. package/dist/chunk-3ME6PKYE.js.map +0 -1
  65. package/dist/chunk-3SGSPHOZ.js.map +0 -1
  66. package/dist/chunk-5P7EGEE5.js.map +0 -1
  67. package/dist/chunk-6N35TCFT.js.map +0 -1
  68. package/dist/chunk-7ETKG6KR.cjs.map +0 -1
  69. package/dist/chunk-CN2BMW6Y.cjs.map +0 -1
  70. package/dist/chunk-IAKQFHFD.cjs.map +0 -1
  71. package/dist/chunk-M4UJAKZ2.cjs.map +0 -1
  72. package/dist/chunk-NWCNJSG3.js.map +0 -1
  73. package/dist/chunk-ORJK2YGG.cjs.map +0 -1
@@ -20,14 +20,89 @@ var ConnectModalBase = class extends LitElement {
20
20
 
21
21
  // src/connect-modal/connect-modal.ts
22
22
  import { withDeviceService as withDeviceService3 } from "@lukso/core/mixins";
23
- import debug3 from "debug";
23
+ import debug4 from "debug";
24
24
  import { html as html5 } from "lit";
25
25
  import { property as property4, state as state2 } from "lit/decorators.js";
26
26
 
27
27
  // src/connect-modal/services/wagmi.ts
28
+ import { getChainById } from "@lukso/core/chains";
28
29
  import { slug } from "@lukso/core/utils";
30
+ import debug from "debug";
31
+
32
+ // src/connect-modal/utils/chainParams.ts
33
+ function constructAddEthereumChainParameter(chain) {
34
+ return {
35
+ chainName: chain.name,
36
+ nativeCurrency: {
37
+ name: chain.nativeCurrency.name,
38
+ symbol: chain.nativeCurrency.symbol,
39
+ decimals: chain.nativeCurrency.decimals
40
+ },
41
+ rpcUrls: [...chain.rpcUrls.default.http],
42
+ blockExplorerUrls: chain.blockExplorers?.default.url ? [chain.blockExplorers.default.url] : void 0
43
+ };
44
+ }
45
+
46
+ // src/connect-modal/services/wagmi.ts
47
+ var logInfo = debug("connect-modal:info");
29
48
  var UP_EXTENSION_ID = "cloud.universalprofile";
30
- var globalWagmiSetup = null;
49
+ var WagmiService = class {
50
+ constructor() {
51
+ this.setup = null;
52
+ this.wagmiCore = null;
53
+ }
54
+ configure(setup) {
55
+ this.setup = setup;
56
+ }
57
+ getSetup() {
58
+ return this.setup;
59
+ }
60
+ /**
61
+ * Ensure wagmi/core is loaded and return initialized state
62
+ * Returns { core, config } if ready, null otherwise
63
+ */
64
+ async init() {
65
+ if (!this.setup) return null;
66
+ if (!this.wagmiCore) {
67
+ try {
68
+ this.wagmiCore = await import("@wagmi/core");
69
+ } catch {
70
+ return null;
71
+ }
72
+ }
73
+ return { core: this.wagmiCore, config: this.setup.wagmiConfig };
74
+ }
75
+ async getConnection() {
76
+ const wagmi = await this.init();
77
+ if (!wagmi) return null;
78
+ try {
79
+ return wagmi.core.getConnection(wagmi.config);
80
+ } catch {
81
+ return null;
82
+ }
83
+ }
84
+ async watchConnection(callback) {
85
+ const wagmi = await this.init();
86
+ if (!wagmi) return null;
87
+ try {
88
+ return wagmi.core.watchConnection(wagmi.config, { onChange: callback });
89
+ } catch {
90
+ return null;
91
+ }
92
+ }
93
+ async disconnect() {
94
+ const wagmi = await this.init();
95
+ if (!wagmi) return false;
96
+ try {
97
+ await wagmi.core.disconnect(wagmi.config);
98
+ return true;
99
+ } catch (error) {
100
+ console.warn("Failed to disconnect from wagmi", error);
101
+ return false;
102
+ }
103
+ }
104
+ };
105
+ var wagmiService = new WagmiService();
31
106
  function fromWagmiConnector(connector, connectFn, chainId) {
32
107
  let type = "injected";
33
108
  const rdns = connector.id;
@@ -48,7 +123,27 @@ function fromWagmiConnector(connector, connectFn, chainId) {
48
123
  connect: async () => {
49
124
  await connectFn({ connector, chainId });
50
125
  },
51
- getProvider: connector.getProvider ? () => connector.getProvider() : void 0
126
+ getProvider: connector.getProvider ? () => connector.getProvider() : void 0,
127
+ switchChain: connector.switchChain ? async (params) => {
128
+ if (!params.chainId) {
129
+ console.warn("No chainId provided for switchChain, skipping");
130
+ return;
131
+ }
132
+ let addEthereumChainParameter = params.addEthereumChainParameter;
133
+ if (!addEthereumChainParameter) {
134
+ const chain = getChainById(params.chainId);
135
+ if (chain) {
136
+ addEthereumChainParameter = constructAddEthereumChainParameter(chain);
137
+ }
138
+ }
139
+ await connector.switchChain({
140
+ chainId: params.chainId,
141
+ addEthereumChainParameter
142
+ });
143
+ logInfo(
144
+ `Switched to chainId ${params.chainId} via connector "${connector.name}"`
145
+ );
146
+ } : void 0
52
147
  };
53
148
  }
54
149
  function fromWagmiConnectors(connectors, connectFn, chainId, embeddedWalletId) {
@@ -102,62 +197,20 @@ function fromWagmiConnectors(connectors, connectFn, chainId, embeddedWalletId) {
102
197
  result.push(...others);
103
198
  return result;
104
199
  }
105
- function setupConnectModal(setup) {
106
- globalWagmiSetup = setup;
200
+ function setupWagmi(setup) {
201
+ wagmiService.configure(setup);
107
202
  }
108
203
  function getWagmiSetup() {
109
- return globalWagmiSetup;
204
+ return wagmiService.getSetup();
110
205
  }
111
- async function getWagmiAccount() {
112
- if (!globalWagmiSetup) {
113
- return null;
114
- }
115
- try {
116
- const { getConnection } = await import("@wagmi/core");
117
- const connection = getConnection(globalWagmiSetup.wagmiConfig);
118
- return {
119
- isConnected: connection.status === "connected",
120
- address: connection.address,
121
- chainId: connection.chainId,
122
- connector: connection.connector
123
- };
124
- } catch (_error) {
125
- return null;
126
- }
206
+ async function getConnection() {
207
+ return wagmiService.getConnection();
127
208
  }
128
- async function watchWagmiAccount(callback) {
129
- if (!globalWagmiSetup) {
130
- return null;
131
- }
132
- try {
133
- const { watchConnection } = await import("@wagmi/core");
134
- const unsubscribe = watchConnection(globalWagmiSetup.wagmiConfig, {
135
- onChange: (connection) => {
136
- callback({
137
- isConnected: connection.status === "connected",
138
- address: connection.address,
139
- chainId: connection.chainId,
140
- connector: connection.connector
141
- });
142
- }
143
- });
144
- return unsubscribe;
145
- } catch (_error) {
146
- return null;
147
- }
209
+ async function watchConnection(callback) {
210
+ return wagmiService.watchConnection(callback);
148
211
  }
149
- async function disconnectWagmi() {
150
- if (!globalWagmiSetup) {
151
- return false;
152
- }
153
- try {
154
- const { disconnect } = await import("@wagmi/core");
155
- await disconnect(globalWagmiSetup.wagmiConfig);
156
- return true;
157
- } catch (error) {
158
- console.warn("Failed to disconnect from wagmi", error);
159
- return false;
160
- }
212
+ async function disconnect() {
213
+ return wagmiService.disconnect();
161
214
  }
162
215
 
163
216
  // src/connect-modal/connect-modal.ts
@@ -166,7 +219,7 @@ import "@lukso/web-components/dist/components/lukso-modal";
166
219
  // src/connect-modal/components/eoa-connection-view.ts
167
220
  import { Task } from "@lit/task";
168
221
  import { withDeviceService, withIntlService } from "@lukso/core/mixins";
169
- import debug from "debug";
222
+ import debug2 from "debug";
170
223
  import { html as html2, nothing } from "lit";
171
224
  import { property, state } from "lit/decorators.js";
172
225
  import { keyed } from "lit/directives/keyed.js";
@@ -210,7 +263,7 @@ var renderPlaceholder = (style2) => html`<div class="${cn("bg-neutral-90 dark:bg
210
263
  import "@lukso/web-components/dist/components/lukso-button";
211
264
  import "@lukso/web-components/dist/components/lukso-icon";
212
265
  import "@lukso/web-components/dist/components/lukso-tag";
213
- var logInfo = debug("connect-modal:info");
266
+ var logInfo2 = debug2("connect-modal:info");
214
267
  var EoaConnectionView = class extends withIntlService(
215
268
  withDeviceService(ConnectModalBase)
216
269
  ) {
@@ -339,8 +392,10 @@ var EoaConnectionView = class extends withIntlService(
339
392
  const connector = wallet.connector;
340
393
  if (connector) {
341
394
  try {
342
- logInfo("Connecting via connector:", connector);
395
+ logInfo2("Connecting via connector:", connector);
343
396
  this.isConnecting = true;
397
+ const setup = getWagmiSetup();
398
+ await connector.switchChain?.({ chainId: setup?.chainId });
344
399
  await connector.connect();
345
400
  this.dispatchEvent(
346
401
  new CustomEvent("on-connect", {
@@ -369,13 +424,13 @@ var EoaConnectionView = class extends withIntlService(
369
424
  const connector = this.walletConnectConnector;
370
425
  if (connector) {
371
426
  try {
372
- logInfo("Connecting via WalletConnect connector:", connector);
427
+ logInfo2("Connecting via WalletConnect connector:", connector);
373
428
  this.isConnecting = true;
374
429
  const connectPromise = connector.connect();
375
430
  const provider = await connector.getProvider?.();
376
431
  if (provider) {
377
432
  const handleDisplayUri = (displayUri) => {
378
- logInfo("WalletConnect URI received:", displayUri);
433
+ logInfo2("WalletConnect URI received:", displayUri);
379
434
  const encodedUri = encodeURIComponent(displayUri);
380
435
  if (wallet.mobile?.native) {
381
436
  window.location.href = `${wallet.mobile.native}wc?uri=${encodedUri}`;
@@ -512,7 +567,7 @@ import "@lukso/web-components/dist/components/lukso-button";
512
567
  import "@lukso/web-components/dist/components/lukso-icon";
513
568
  import { browserInfo } from "@lukso/core/utils";
514
569
  import { cn as cn2 } from "@lukso/web-components/tools";
515
- import debug2 from "debug";
570
+ import debug3 from "debug";
516
571
 
517
572
  // src/connect-modal/utils/walletConnectDeepLinkUrl.ts
518
573
  var walletConnectDeepLinkUrl = (data, options) => {
@@ -539,7 +594,7 @@ var walletConnectDeepLinkUrl = (data, options) => {
539
594
  };
540
595
 
541
596
  // src/connect-modal/components/connection-view.ts
542
- var logInfo2 = debug2("connect-modal:info");
597
+ var logInfo3 = debug3("connect-modal:info");
543
598
  var ConnectionView = class extends withIntlService2(
544
599
  withDeviceService2(ConnectModalBase)
545
600
  ) {
@@ -554,7 +609,7 @@ var ConnectionView = class extends withIntlService2(
554
609
  this.handleConnectEmbedded = async () => {
555
610
  const connector = this.embeddedWalletConnector;
556
611
  try {
557
- logInfo2("Connecting via connector:", connector);
612
+ logInfo3("Connecting via connector:", connector);
558
613
  await connector?.connect();
559
614
  this.dispatchEvent(
560
615
  new CustomEvent("on-connect", {
@@ -584,9 +639,11 @@ var ConnectionView = class extends withIntlService2(
584
639
  }
585
640
  if (connector) {
586
641
  try {
587
- logInfo2("Connecting via connector:", connector);
642
+ logInfo3("Connecting via connector:", connector);
588
643
  this.isConnecting = true;
589
644
  this.connectingRdns = connector.rdns;
645
+ const setup = getWagmiSetup();
646
+ await connector.switchChain?.({ chainId: setup?.chainId });
590
647
  await connector.connect();
591
648
  this.dispatchEvent(
592
649
  new CustomEvent("on-connect", {
@@ -616,16 +673,16 @@ var ConnectionView = class extends withIntlService2(
616
673
  const connector = this.walletConnectConnector;
617
674
  if (connector) {
618
675
  try {
619
- logInfo2("Connecting via connector:", connector);
676
+ logInfo3("Connecting via connector:", connector);
620
677
  this.isConnecting = true;
621
678
  this.connectingRdns = connector.rdns;
622
679
  const connectPromise = connector.connect();
623
680
  const provider = await connector.getProvider?.();
624
681
  if (provider) {
625
682
  const handleDisplayUri = (displayUri) => {
626
- logInfo2("WalletConnect original URI:", displayUri);
683
+ logInfo3("WalletConnect original URI:", displayUri);
627
684
  const deepLink = walletConnectDeepLinkUrl(displayUri);
628
- logInfo2("Mobile App Deep Link:", deepLink);
685
+ logInfo3("Mobile App Deep Link:", deepLink);
629
686
  if (this.device.isMobile) {
630
687
  window.open(deepLink, "_blank");
631
688
  } else {
@@ -908,7 +965,7 @@ __decorateClass([
908
965
  customElements.define("qr-code-view", QrCodeView);
909
966
 
910
967
  // src/connect-modal/connect-modal.ts
911
- var logInfo3 = debug3("connect-modal:info");
968
+ var logInfo4 = debug4("connect-modal:info");
912
969
  var ConnectModal = class extends withDeviceService3(ConnectModalBase) {
913
970
  constructor() {
914
971
  super(...arguments);
@@ -986,9 +1043,9 @@ var ConnectModal = class extends withDeviceService3(ConnectModalBase) {
986
1043
  }
987
1044
  }
988
1045
  async loadConnectors() {
989
- const globalWagmiSetup2 = getWagmiSetup();
990
- logInfo3("Global wagmi setup:", globalWagmiSetup2);
991
- if (!globalWagmiSetup2) {
1046
+ const globalWagmiSetup = getWagmiSetup();
1047
+ logInfo4("Global wagmi setup:", globalWagmiSetup);
1048
+ if (!globalWagmiSetup) {
992
1049
  console.warn(
993
1050
  "No global wagmi setup found! Call setupConnectModal() first."
994
1051
  );
@@ -996,9 +1053,9 @@ var ConnectModal = class extends withDeviceService3(ConnectModalBase) {
996
1053
  return;
997
1054
  }
998
1055
  try {
999
- const { wagmiConfig, chainId, embeddedWalletId } = globalWagmiSetup2;
1056
+ const { wagmiConfig, chainId, embeddedWalletId } = globalWagmiSetup;
1000
1057
  const wagmiConnectors = wagmiConfig?.connectors || [];
1001
- logInfo3("Initial connectors:", wagmiConnectors);
1058
+ logInfo4("Initial connectors:", wagmiConnectors);
1002
1059
  const wagmiCore = await import("@wagmi/core").catch((error) => {
1003
1060
  throw new Error("@wagmi/core is required when using wagmi connectors", {
1004
1061
  cause: error
@@ -1015,7 +1072,7 @@ var ConnectModal = class extends withDeviceService3(ConnectModalBase) {
1015
1072
  chainId,
1016
1073
  embeddedWalletId
1017
1074
  );
1018
- logInfo3("Converted connectors:", this.connectors);
1075
+ logInfo4("Converted connectors:", this.connectors);
1019
1076
  } catch (error) {
1020
1077
  console.warn("Failed to load connectors", error);
1021
1078
  this.connectors = [];
@@ -1029,7 +1086,7 @@ var ConnectModal = class extends withDeviceService3(ConnectModalBase) {
1029
1086
  handleOnConnectSuccess(event) {
1030
1087
  event.stopPropagation();
1031
1088
  const connector = event.detail.connector;
1032
- logInfo3("Connection success:", connector);
1089
+ logInfo4("Connection success:", connector);
1033
1090
  this.open = false;
1034
1091
  this.dispatchEvent(
1035
1092
  new CustomEvent("on-connect", {
@@ -1047,7 +1104,7 @@ var ConnectModal = class extends withDeviceService3(ConnectModalBase) {
1047
1104
  handleOnConnectError(event) {
1048
1105
  event.stopPropagation();
1049
1106
  const error = event.detail.error;
1050
- logInfo3("Connection error:", error);
1107
+ logInfo4("Connection error:", error);
1051
1108
  this.dispatchEvent(
1052
1109
  new CustomEvent("on-error", {
1053
1110
  detail: { error },
@@ -1130,13 +1187,14 @@ customElements.define("connect-modal", ConnectModal);
1130
1187
 
1131
1188
  export {
1132
1189
  ConnectModalBase,
1190
+ wagmiService,
1133
1191
  fromWagmiConnector,
1134
1192
  fromWagmiConnectors,
1135
- setupConnectModal,
1193
+ setupWagmi,
1136
1194
  getWagmiSetup,
1137
- getWagmiAccount,
1138
- watchWagmiAccount,
1139
- disconnectWagmi,
1195
+ getConnection,
1196
+ watchConnection,
1197
+ disconnect,
1140
1198
  ConnectModal
1141
1199
  };
1142
- //# sourceMappingURL=chunk-3ME6PKYE.js.map
1200
+ //# sourceMappingURL=chunk-SAQWNAQ6.js.map