@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
@@ -8,6 +8,10 @@ interface WalletConnector {
8
8
  type: 'embedded' | 'extension' | 'mobile' | 'injected' | 'walletconnect';
9
9
  connect: () => Promise<void>;
10
10
  getProvider?: () => Promise<any>;
11
+ switchChain?: (params: {
12
+ chainId?: number;
13
+ addEthereumChainParameter?: any;
14
+ }) => Promise<void>;
11
15
  }
12
16
  interface ConnectModalSetup {
13
17
  /**
@@ -312,10 +316,44 @@ declare global {
312
316
  }
313
317
 
314
318
  /**
315
- * Wagmi Connector Adapter
316
- * Converts wagmi/viem connectors to our WalletConnector format
319
+ * Wagmi Service
320
+ * Centralized service for wagmi interactions with proxy pattern
317
321
  */
318
322
 
323
+ /**
324
+ * Wagmi connection state from getConnection/watchConnection
325
+ */
326
+ type WagmiConnection = {
327
+ address?: string;
328
+ addresses?: readonly string[];
329
+ chainId?: number;
330
+ chain?: any;
331
+ connector?: any;
332
+ status: 'connecting' | 'reconnecting' | 'connected' | 'disconnected';
333
+ isConnecting?: boolean;
334
+ isReconnecting?: boolean;
335
+ isConnected?: boolean;
336
+ isDisconnected?: boolean;
337
+ };
338
+ /**
339
+ * Wagmi Service Class
340
+ * Provides centralized access to wagmi core functions
341
+ */
342
+ declare class WagmiService {
343
+ private setup;
344
+ private wagmiCore;
345
+ configure(setup: ConnectModalSetup): void;
346
+ getSetup(): ConnectModalSetup | null;
347
+ /**
348
+ * Ensure wagmi/core is loaded and return initialized state
349
+ * Returns { core, config } if ready, null otherwise
350
+ */
351
+ private init;
352
+ getConnection(): Promise<any>;
353
+ watchConnection(callback: (connection: WagmiConnection) => void): Promise<(() => void) | null>;
354
+ disconnect(): Promise<boolean>;
355
+ }
356
+ declare const wagmiService: WagmiService;
319
357
  /**
320
358
  * Convert a wagmi connector to our WalletConnector format
321
359
  * @param connector - Wagmi connector instance
@@ -343,10 +381,10 @@ declare function fromWagmiConnectors(connectors: WagmiConnector[], connectFn: (o
343
381
  *
344
382
  * @example
345
383
  * ```typescript
346
- * import { setupConnectModal } from '@lukso/up-connector'
384
+ * import { setupWagmi } from '@lukso/up-connector'
347
385
  * import { wagmiConfig } from './wagmi-config'
348
386
  *
349
- * setupConnectModal({
387
+ * setupWagmi({
350
388
  * wagmiConfig,
351
389
  * chainId: 42, // Optional: LUKSO mainnet
352
390
  * embeddedWalletConnect: async () => {
@@ -355,35 +393,53 @@ declare function fromWagmiConnectors(connectors: WagmiConnector[], connectFn: (o
355
393
  * })
356
394
  * ```
357
395
  */
358
- declare function setupConnectModal(setup: ConnectModalSetup): void;
396
+ declare function setupWagmi(setup: ConnectModalSetup): void;
359
397
  /**
360
398
  * Get the current wagmi setup (for internal use by connector)
361
399
  */
362
400
  declare function getWagmiSetup(): ConnectModalSetup | null;
363
401
  /**
364
- * Get current wagmi account state
402
+ * Get current wagmi connection state
365
403
  * Returns null if wagmi is not set up
404
+ *
405
+ * @example
406
+ * ```typescript
407
+ * import { getConnection } from '@lukso/up-connector'
408
+ *
409
+ * const connection = await getConnection()
410
+ * if (connection?.status === 'connected') {
411
+ * console.log(connection.address, connection.chainId)
412
+ * }
413
+ * ```
366
414
  */
367
- declare function getWagmiAccount(): Promise<{
368
- isConnected: boolean;
369
- address?: string;
370
- chainId?: number;
371
- connector?: any;
372
- } | null>;
415
+ declare function getConnection(): Promise<any>;
373
416
  /**
374
- * Subscribe to wagmi connection changes
417
+ * Watch for wagmi connection changes
375
418
  * Returns unsubscribe function
419
+ *
420
+ * @example
421
+ * ```typescript
422
+ * import { watchConnection } from '@lukso/up-connector'
423
+ *
424
+ * const unwatch = await watchConnection((connection) => {
425
+ * console.log('Connection changed:', connection.status, connection.address)
426
+ * })
427
+ *
428
+ * // Later: unwatch()
429
+ * ```
376
430
  */
377
- declare function watchWagmiAccount(callback: (account: {
378
- isConnected: boolean;
379
- address?: string;
380
- chainId?: number;
381
- connector?: any;
382
- }) => void): Promise<(() => void) | null>;
431
+ declare function watchConnection(callback: (connection: WagmiConnection) => void): Promise<(() => void) | null>;
383
432
  /**
384
433
  * Disconnect from wagmi
385
434
  * Returns true if disconnect was successful
435
+ *
436
+ * @example
437
+ * ```typescript
438
+ * import { disconnect } from '@lukso/up-connector'
439
+ *
440
+ * await disconnect()
441
+ * ```
386
442
  */
387
- declare function disconnectWagmi(): Promise<boolean>;
443
+ declare function disconnect(): Promise<boolean>;
388
444
 
389
- export { ConnectModal as C, type WalletConnector as W, type WagmiConnector as a, type ConnectionModalView as b, type ConnectModalSetup as c, type ConnectModalTheme as d, disconnectWagmi as e, getWagmiSetup as f, getWagmiAccount as g, fromWagmiConnector as h, fromWagmiConnectors as i, type Wallet as j, setupConnectModal as s, watchWagmiAccount as w };
445
+ export { ConnectModal as C, type WalletConnector as W, type WagmiConnector as a, type ConnectionModalView as b, type ConnectModalSetup as c, type ConnectModalTheme as d, type WagmiConnection as e, disconnect as f, getConnection as g, getWagmiSetup as h, watchConnection as i, fromWagmiConnector as j, fromWagmiConnectors as k, type Wallet as l, setupWagmi as s, wagmiService as w };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lukso/up-connector",
3
- "version": "0.5.1",
3
+ "version": "0.6.0-dev.5ea12c5",
4
4
  "description": "Universal Profile connector with draggable avatar and connection modal",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -76,16 +76,16 @@
76
76
  },
77
77
  "dependencies": {
78
78
  "@lit/task": "^1.0.3",
79
- "@lukso/up-provider": "npm:@lukso-network/up-provider@0.3.5-main.c50af46",
79
+ "@lukso/up-provider": "0.3.7",
80
80
  "@lukso/web-components": "^1.171.2",
81
81
  "debug": "^4.4.3",
82
82
  "lit": "^3.3.1",
83
83
  "ws": "^8.18.3",
84
84
  "zxcvbn": "^4.4.2",
85
- "@lukso/core": "1.0.0",
86
- "@lukso/passkey-auth": "1.1.1",
87
- "@lukso/transaction-view-core": "0.4.1",
88
- "@lukso/transaction-view-headless": "0.3.1"
85
+ "@lukso/core": "1.1.0-dev.5ea12c5",
86
+ "@lukso/passkey-auth": "1.2.0-dev.5ea12c5",
87
+ "@lukso/transaction-view-core": "0.5.0-dev.5ea12c5",
88
+ "@lukso/transaction-view-headless": "0.4.0-dev.5ea12c5"
89
89
  },
90
90
  "peerDependencies": {
91
91
  "@wagmi/connectors": "^7.0.0",
@@ -154,6 +154,6 @@
154
154
  "deploy:prepare": "./deploy.sh",
155
155
  "test": "vitest",
156
156
  "test:run": "vitest run",
157
- "check": "tsc --noEmit"
157
+ "typecheck": "tsc --noEmit"
158
158
  }
159
159
  }
package/src/auto-setup.ts CHANGED
@@ -8,7 +8,6 @@
8
8
  */
9
9
 
10
10
  import type { Config } from '@wagmi/core'
11
- import type { ConnectModalSetup } from './connect-modal/index.js'
12
11
  import { setupConnectModal } from './connect-modal/index.js'
13
12
 
14
13
  /**
package/src/avatar.ts CHANGED
@@ -129,7 +129,6 @@ export class DraggableAvatar {
129
129
 
130
130
  // Animation state
131
131
  private isThrobbing = false
132
- private throbAnimation?: Animation
133
132
 
134
133
  constructor(options: AvatarOptions = {}) {
135
134
  this.options = { ...DEFAULT_AVATAR_OPTIONS, ...options }
@@ -212,7 +211,7 @@ export class DraggableAvatar {
212
211
 
213
212
  // Calculate sizes before template literal
214
213
  const avatarPixelSize = this.getPixelSize(this.options.avatarSize)
215
- const overhang = this.getIdenticonOverhang(this.options.avatarSize)
214
+ const _overhang = this.getIdenticonOverhang(this.options.avatarSize)
216
215
 
217
216
  // Debug: Log our calculations
218
217
 
@@ -620,9 +619,7 @@ export class DraggableAvatar {
620
619
  let minDistance = Infinity
621
620
 
622
621
  positions.forEach((pos) => {
623
- const distance = Math.sqrt(
624
- Math.pow(x - pos.x, 2) + Math.pow(y - pos.y, 2)
625
- )
622
+ const distance = Math.sqrt((x - pos.x) ** 2 + (y - pos.y) ** 2)
626
623
  if (distance < minDistance) {
627
624
  minDistance = distance
628
625
  closest = pos
@@ -652,19 +649,19 @@ export class DraggableAvatar {
652
649
  this.element.classList.add('hidden-left')
653
650
  this.element.style.left = `-${this.options.hideOffset}px`
654
651
  this.element.style.right = 'auto'
655
- this.element.style.top = position.y + 'px'
652
+ this.element.style.top = `${position.y}px`
656
653
  this.options.onHide?.()
657
654
  } else if (position.side === 'right') {
658
655
  this.element.classList.add('hidden-right')
659
656
  this.element.style.right = `-${this.options.hideOffset}px`
660
657
  this.element.style.left = 'auto'
661
- this.element.style.top = position.y + 'px'
658
+ this.element.style.top = `${position.y}px`
662
659
  this.options.onHide?.()
663
660
  }
664
661
  } else {
665
- this.element.style.left = position.x + 'px'
662
+ this.element.style.left = `${position.x}px`
666
663
  this.element.style.right = 'auto'
667
- this.element.style.top = position.y + 'px'
664
+ this.element.style.top = `${position.y}px`
668
665
  if (this.isHidden) {
669
666
  this.options.onShow?.()
670
667
  }
@@ -683,8 +680,8 @@ export class DraggableAvatar {
683
680
  if (!this.snapPreviews.has(pos.name)) {
684
681
  const preview = document.createElement('div')
685
682
  preview.className = 'up-avatar-preview'
686
- preview.style.left = pos.x + 'px'
687
- preview.style.top = pos.y + 'px'
683
+ preview.style.left = `${pos.x}px`
684
+ preview.style.top = `${pos.y}px`
688
685
  this.overlay.appendChild(preview)
689
686
  this.snapPreviews.set(pos.name, preview)
690
687
  }
@@ -698,7 +695,7 @@ export class DraggableAvatar {
698
695
  if (typeof document === 'undefined') return
699
696
 
700
697
  // Determine the active position key
701
- let activeKey = activePosition.name
698
+ const activeKey = activePosition.name
702
699
 
703
700
  // Update all previews
704
701
  this.snapPreviews.forEach((preview, key) => {
@@ -711,16 +708,16 @@ export class DraggableAvatar {
711
708
  if (activePosition.side === 'left') {
712
709
  preview.style.left = `-${this.options.hideOffset}px`
713
710
  preview.style.right = 'auto'
714
- preview.style.top = activePosition.y + 'px'
711
+ preview.style.top = `${activePosition.y}px`
715
712
  } else if (activePosition.side === 'right') {
716
713
  preview.style.right = `-${this.options.hideOffset}px`
717
714
  preview.style.left = 'auto'
718
- preview.style.top = activePosition.y + 'px'
715
+ preview.style.top = `${activePosition.y}px`
719
716
  }
720
717
  } else {
721
- preview.style.left = activePosition.x + 'px'
718
+ preview.style.left = `${activePosition.x}px`
722
719
  preview.style.right = 'auto'
723
- preview.style.top = activePosition.y + 'px'
720
+ preview.style.top = `${activePosition.y}px`
724
721
  }
725
722
  } else {
726
723
  // Dim the others
@@ -729,9 +726,9 @@ export class DraggableAvatar {
729
726
  // Reset to normal position (not hidden)
730
727
  const pos = this.getSnapPositions().find((p) => p.name === key)
731
728
  if (pos) {
732
- preview.style.left = pos.x + 'px'
729
+ preview.style.left = `${pos.x}px`
733
730
  preview.style.right = 'auto'
734
- preview.style.top = pos.y + 'px'
731
+ preview.style.top = `${pos.y}px`
735
732
  }
736
733
  }
737
734
  })
@@ -786,9 +783,9 @@ export class DraggableAvatar {
786
783
 
787
784
  // Always update position while dragging (for visual feedback)
788
785
  this.element.className = 'up-avatar dragging'
789
- this.element.style.left = currentX + 'px'
786
+ this.element.style.left = `${currentX}px`
790
787
  this.element.style.right = 'auto'
791
- this.element.style.top = currentY + 'px'
788
+ this.element.style.top = `${currentY}px`
792
789
 
793
790
  const closestPosition = this.findClosestSnapPosition(currentX, currentY)
794
791
  const shouldHideLeft = currentX < -this.options.hideThreshold
@@ -877,9 +874,9 @@ export class DraggableAvatar {
877
874
 
878
875
  // Always update position while dragging (for visual feedback)
879
876
  this.element.className = 'up-avatar dragging'
880
- this.element.style.left = currentX + 'px'
877
+ this.element.style.left = `${currentX}px`
881
878
  this.element.style.right = 'auto'
882
- this.element.style.top = currentY + 'px'
879
+ this.element.style.top = `${currentY}px`
883
880
 
884
881
  const closestPosition = this.findClosestSnapPosition(currentX, currentY)
885
882
  const shouldHideLeft = currentX < -this.options.hideThreshold
@@ -952,7 +949,7 @@ export class DraggableAvatar {
952
949
  if (this.currentPosition) {
953
950
  const positions = this.getSnapPositions()
954
951
  const newPosition =
955
- positions.find((p) => p.name === this.currentPosition!.name) ||
952
+ positions.find((p) => p.name === this.currentPosition?.name) ||
956
953
  positions[0]
957
954
  this.snapToPosition(newPosition, this.isHidden)
958
955
  }
@@ -171,7 +171,9 @@ export class BackupModal extends CoreLitElement {
171
171
  label="Password"
172
172
  placeholder="Enter a strong password"
173
173
  .value=${this.password}
174
- @on-input=${(e: CustomEvent) => (this.password = e.detail.value)}
174
+ @on-input=${(e: CustomEvent) => {
175
+ this.password = e.detail.value
176
+ }}
175
177
  is-full-width
176
178
  autofocus
177
179
  ></lukso-input>
@@ -216,7 +218,9 @@ export class BackupModal extends CoreLitElement {
216
218
  label="Confirm Password"
217
219
  placeholder="Re-enter your password"
218
220
  .value=${this.passwordConfirm}
219
- @on-input=${(e: CustomEvent) => (this.passwordConfirm = e.detail.value)}
221
+ @on-input=${(e: CustomEvent) => {
222
+ this.passwordConfirm = e.detail.value
223
+ }}
220
224
  is-full-width
221
225
  ></lukso-input>
222
226
 
@@ -20,6 +20,7 @@ import '@lukso/web-components/dist/components/lukso-icon'
20
20
  import { type BrowserInfo, browserInfo } from '@lukso/core/utils'
21
21
  import { cn } from '@lukso/web-components/tools'
22
22
  import debug from 'debug'
23
+ import { getWagmiSetup } from '../services/wagmi'
23
24
  import { walletConnectDeepLinkUrl } from '../utils/walletConnectDeepLinkUrl'
24
25
 
25
26
  const logInfo = debug('connect-modal:info')
@@ -109,13 +110,15 @@ export class ConnectionView extends withIntlService(
109
110
  return
110
111
  }
111
112
 
112
- // TBA: Switch extension to current chain
113
113
  if (connector) {
114
114
  try {
115
115
  logInfo('Connecting via connector:', connector)
116
116
  this.isConnecting = true
117
117
  this.connectingRdns = connector.rdns
118
118
 
119
+ const setup = getWagmiSetup()
120
+
121
+ await connector.switchChain?.({ chainId: setup?.chainId })
119
122
  await connector.connect()
120
123
 
121
124
  // Dispatch connect event
@@ -36,6 +36,7 @@ import type {
36
36
  import '@lukso/web-components/dist/components/lukso-button'
37
37
  import '@lukso/web-components/dist/components/lukso-icon'
38
38
  import '@lukso/web-components/dist/components/lukso-tag'
39
+ import { getWagmiSetup } from '../services/wagmi'
39
40
 
40
41
  const logInfo = debug('connect-modal:info')
41
42
 
@@ -207,6 +208,9 @@ export class EoaConnectionView extends withIntlService(
207
208
  logInfo('Connecting via connector:', connector)
208
209
  this.isConnecting = true
209
210
 
211
+ const setup = getWagmiSetup()
212
+
213
+ await connector.switchChain?.({ chainId: setup?.chainId })
210
214
  await connector.connect()
211
215
 
212
216
  // Dispatch connect event
@@ -6,6 +6,10 @@ export interface WalletConnector {
6
6
  type: 'embedded' | 'extension' | 'mobile' | 'injected' | 'walletconnect'
7
7
  connect: () => Promise<void>
8
8
  getProvider?: () => Promise<any>
9
+ switchChain?: (params: {
10
+ chainId?: number
11
+ addEthereumChainParameter?: any
12
+ }) => Promise<void>
9
13
  }
10
14
 
11
15
  export interface ConnectModalSetup {
@@ -14,10 +14,12 @@ export type {
14
14
  Wallet,
15
15
  WalletConnector,
16
16
  } from './connect-modal.types'
17
+ export type { WagmiConnection } from './services/wagmi'
17
18
  export {
18
- disconnectWagmi,
19
- getWagmiAccount,
19
+ disconnect,
20
+ getConnection,
20
21
  getWagmiSetup,
21
- setupConnectModal,
22
- watchWagmiAccount,
22
+ setupWagmi as setupConnectModal,
23
+ wagmi,
24
+ watchConnection,
23
25
  } from './services/wagmi'