@hsuite/native-connect-angular 1.0.0 → 2.1.1

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 (188) hide show
  1. package/coverage/coverage-summary.json +53 -49
  2. package/coverage/index.html +100 -100
  3. package/coverage/lcov-report/index.html +100 -100
  4. package/coverage/lcov-report/lib/components/account-selector/account-actions/account-actions.component.ts.html +1 -1
  5. package/coverage/lcov-report/lib/components/account-selector/account-actions/index.html +1 -1
  6. package/coverage/lcov-report/lib/components/account-selector/account-filter/account-filter.component.ts.html +1 -1
  7. package/coverage/lcov-report/lib/components/account-selector/account-filter/index.html +1 -1
  8. package/coverage/lcov-report/lib/components/account-selector/account-formatting.service.ts.html +13 -19
  9. package/coverage/lcov-report/lib/components/account-selector/account-grouping.service.ts.html +1 -1
  10. package/coverage/lcov-report/lib/components/account-selector/account-list/account-list.component.ts.html +1 -1
  11. package/coverage/lcov-report/lib/components/account-selector/account-list/index.html +1 -1
  12. package/coverage/lcov-report/lib/components/account-selector/account-selector.component.ts.html +1 -1
  13. package/coverage/lcov-report/lib/components/account-selector/account-selector.service.ts.html +1 -1
  14. package/coverage/lcov-report/lib/components/account-selector/index.html +5 -5
  15. package/coverage/lcov-report/lib/components/wallet-account-display/index.html +1 -1
  16. package/coverage/lcov-report/lib/components/wallet-account-display/wallet-account-display.component.ts.html +10 -10
  17. package/coverage/lcov-report/lib/components/wallet-connect-button/index.html +21 -21
  18. package/coverage/lcov-report/lib/components/wallet-connect-button/wallet-connect-button.component.ts.html +475 -451
  19. package/coverage/lcov-report/lib/components/wallet-connect-prompt/index.html +1 -1
  20. package/coverage/lcov-report/lib/components/wallet-connect-prompt/wallet-connect-prompt.component.ts.html +1 -1
  21. package/coverage/lcov-report/lib/components/wallet-connected-guard/index.html +1 -1
  22. package/coverage/lcov-report/lib/components/wallet-connected-guard/wallet-connected-guard.component.ts.html +1 -1
  23. package/coverage/lcov-report/lib/components/wallet-connection-modal/connection-method-step/connection-method-step.component.ts.html +148 -148
  24. package/coverage/lcov-report/lib/components/wallet-connection-modal/connection-method-step/index.html +17 -17
  25. package/coverage/lcov-report/lib/components/wallet-connection-modal/index.html +21 -21
  26. package/coverage/lcov-report/lib/components/wallet-connection-modal/qr-pairing-step/index.html +17 -17
  27. package/coverage/lcov-report/lib/components/wallet-connection-modal/qr-pairing-step/qr-pairing-step.component.ts.html +838 -838
  28. package/coverage/lcov-report/lib/components/wallet-connection-modal/wallet-connection-modal.component.ts.html +1230 -987
  29. package/coverage/lcov-report/lib/components/wallet-session-display/index.html +1 -1
  30. package/coverage/lcov-report/lib/components/wallet-session-display/wallet-session-display.component.ts.html +1 -1
  31. package/coverage/lcov-report/lib/components/wallet-transaction-status/index.html +1 -1
  32. package/coverage/lcov-report/lib/components/wallet-transaction-status/wallet-transaction-status.component.ts.html +1 -1
  33. package/coverage/lcov-report/lib/directives/index.html +1 -1
  34. package/coverage/lcov-report/lib/directives/wallet-connected.directive.ts.html +1 -1
  35. package/coverage/lcov-report/lib/directives/wallet-context.directive.ts.html +1 -1
  36. package/coverage/lcov-report/lib/directives/wallet-events.directive.ts.html +1 -1
  37. package/coverage/lcov-report/lib/hsuite-wallet.module.ts.html +1 -1
  38. package/coverage/lcov-report/lib/index.html +1 -1
  39. package/coverage/lcov-report/lib/models/connection-config.model.ts.html +1 -1
  40. package/coverage/lcov-report/lib/models/index.html +7 -7
  41. package/coverage/lcov-report/lib/models/provider-types.ts.html +11 -5
  42. package/coverage/lcov-report/lib/providers/base-wallet-provider.ts.html +1 -1
  43. package/coverage/lcov-report/lib/providers/hsuite-native/channel-client.service.ts.html +9 -6
  44. package/coverage/lcov-report/lib/providers/hsuite-native/index.html +10 -10
  45. package/coverage/lcov-report/lib/providers/hsuite-native-provider.ts.html +1 -1
  46. package/coverage/lcov-report/lib/providers/index.html +1 -1
  47. package/coverage/lcov-report/lib/providers/p2p-native/index.html +7 -7
  48. package/coverage/lcov-report/lib/providers/p2p-native/p2p-native.provider.ts.html +1 -1
  49. package/coverage/lcov-report/lib/providers/p2p-native/p2p-session-manager.ts.html +7 -4
  50. package/coverage/lcov-report/lib/providers/wallet-error-handler.ts.html +1 -1
  51. package/coverage/lcov-report/lib/providers/walletconnect/core/index.html +10 -10
  52. package/coverage/lcov-report/lib/providers/walletconnect/core/session-health.ts.html +1 -1
  53. package/coverage/lcov-report/lib/providers/walletconnect/core/walletconnect-client-manager.ts.html +1 -1
  54. package/coverage/lcov-report/lib/providers/walletconnect/core/walletconnect-provider.ts.html +10 -7
  55. package/coverage/lcov-report/lib/providers/walletconnect/core/walletconnect-session-store.ts.html +1 -1
  56. package/coverage/lcov-report/lib/providers/walletconnect/core/walletconnect-signing-orchestrator.ts.html +1 -1
  57. package/coverage/lcov-report/lib/providers/walletconnect/signers/hedera-signer.ts.html +1 -1
  58. package/coverage/lcov-report/lib/providers/walletconnect/signers/index.html +1 -1
  59. package/coverage/lcov-report/lib/providers/walletconnect/signers/signer-factory.ts.html +49 -49
  60. package/coverage/lcov-report/lib/providers/walletconnect/signers/xrpl-signer.ts.html +1 -1
  61. package/coverage/lcov-report/lib/services/hsuite-auth.interceptor.ts.html +568 -0
  62. package/coverage/lcov-report/lib/services/index.html +50 -20
  63. package/coverage/lcov-report/lib/services/logger.service.ts.html +4 -4
  64. package/coverage/lcov-report/lib/services/smart-session.service.ts.html +1264 -0
  65. package/coverage/lcov-report/lib/services/transaction-builders/active-account-source.ts.html +250 -0
  66. package/coverage/lcov-report/lib/services/transaction-builders/base-transaction-builder.service.ts.html +1 -1
  67. package/coverage/lcov-report/lib/services/transaction-builders/hedera-amount-utils.ts.html +1 -1
  68. package/coverage/lcov-report/lib/services/transaction-builders/hedera-transaction-builder.service.ts.html +318 -318
  69. package/coverage/lcov-report/lib/services/transaction-builders/index.html +24 -9
  70. package/coverage/lcov-report/lib/services/transaction-builders/xrpl-transaction-builder.service.ts.html +1 -1
  71. package/coverage/lcov-report/lib/services/transaction.service.ts.html +7 -10
  72. package/coverage/lcov-report/lib/services/unified-wallet.service.ts.html +9 -12
  73. package/coverage/lcov-report/lib/services/wallet-context.service.ts.html +1 -1
  74. package/coverage/lcov-report/lib/services/wallet-event-bus.service.ts.html +1 -1
  75. package/coverage/lcov-report/lib/services/wallet-providers.service.ts.html +4 -7
  76. package/coverage/lcov-report/lib/transports/chrome-extension-transport.ts.html +1 -1
  77. package/coverage/lcov-report/lib/transports/index.html +1 -1
  78. package/coverage/lcov-report/lib/utils/index.html +36 -21
  79. package/coverage/lcov-report/lib/utils/ledger-icons.util.ts.html +254 -161
  80. package/coverage/lcov-report/lib/utils/ledger-ui-registry.ts.html +676 -0
  81. package/coverage/lcov.info +3236 -2122
  82. package/coverage/lib/components/account-selector/account-actions/account-actions.component.ts.html +1 -1
  83. package/coverage/lib/components/account-selector/account-actions/index.html +1 -1
  84. package/coverage/lib/components/account-selector/account-filter/account-filter.component.ts.html +1 -1
  85. package/coverage/lib/components/account-selector/account-filter/index.html +1 -1
  86. package/coverage/lib/components/account-selector/account-formatting.service.ts.html +13 -19
  87. package/coverage/lib/components/account-selector/account-grouping.service.ts.html +1 -1
  88. package/coverage/lib/components/account-selector/account-list/account-list.component.ts.html +1 -1
  89. package/coverage/lib/components/account-selector/account-list/index.html +1 -1
  90. package/coverage/lib/components/account-selector/account-selector.component.ts.html +1 -1
  91. package/coverage/lib/components/account-selector/account-selector.service.ts.html +1 -1
  92. package/coverage/lib/components/account-selector/index.html +5 -5
  93. package/coverage/lib/components/wallet-account-display/index.html +1 -1
  94. package/coverage/lib/components/wallet-account-display/wallet-account-display.component.ts.html +10 -10
  95. package/coverage/lib/components/wallet-connect-button/index.html +21 -21
  96. package/coverage/lib/components/wallet-connect-button/wallet-connect-button.component.ts.html +475 -451
  97. package/coverage/lib/components/wallet-connect-prompt/index.html +1 -1
  98. package/coverage/lib/components/wallet-connect-prompt/wallet-connect-prompt.component.ts.html +1 -1
  99. package/coverage/lib/components/wallet-connected-guard/index.html +1 -1
  100. package/coverage/lib/components/wallet-connected-guard/wallet-connected-guard.component.ts.html +1 -1
  101. package/coverage/lib/components/wallet-connection-modal/connection-method-step/connection-method-step.component.ts.html +148 -148
  102. package/coverage/lib/components/wallet-connection-modal/connection-method-step/index.html +17 -17
  103. package/coverage/lib/components/wallet-connection-modal/index.html +21 -21
  104. package/coverage/lib/components/wallet-connection-modal/qr-pairing-step/index.html +17 -17
  105. package/coverage/lib/components/wallet-connection-modal/qr-pairing-step/qr-pairing-step.component.ts.html +838 -838
  106. package/coverage/lib/components/wallet-connection-modal/wallet-connection-modal.component.ts.html +1230 -987
  107. package/coverage/lib/components/wallet-session-display/index.html +1 -1
  108. package/coverage/lib/components/wallet-session-display/wallet-session-display.component.ts.html +1 -1
  109. package/coverage/lib/components/wallet-transaction-status/index.html +1 -1
  110. package/coverage/lib/components/wallet-transaction-status/wallet-transaction-status.component.ts.html +1 -1
  111. package/coverage/lib/directives/index.html +1 -1
  112. package/coverage/lib/directives/wallet-connected.directive.ts.html +1 -1
  113. package/coverage/lib/directives/wallet-context.directive.ts.html +1 -1
  114. package/coverage/lib/directives/wallet-events.directive.ts.html +1 -1
  115. package/coverage/lib/hsuite-wallet.module.ts.html +1 -1
  116. package/coverage/lib/index.html +1 -1
  117. package/coverage/lib/models/connection-config.model.ts.html +1 -1
  118. package/coverage/lib/models/index.html +7 -7
  119. package/coverage/lib/models/provider-types.ts.html +11 -5
  120. package/coverage/lib/providers/base-wallet-provider.ts.html +1 -1
  121. package/coverage/lib/providers/hsuite-native/channel-client.service.ts.html +9 -6
  122. package/coverage/lib/providers/hsuite-native/index.html +10 -10
  123. package/coverage/lib/providers/hsuite-native-provider.ts.html +1 -1
  124. package/coverage/lib/providers/index.html +1 -1
  125. package/coverage/lib/providers/p2p-native/index.html +7 -7
  126. package/coverage/lib/providers/p2p-native/p2p-native.provider.ts.html +1 -1
  127. package/coverage/lib/providers/p2p-native/p2p-session-manager.ts.html +7 -4
  128. package/coverage/lib/providers/wallet-error-handler.ts.html +1 -1
  129. package/coverage/lib/providers/walletconnect/core/index.html +10 -10
  130. package/coverage/lib/providers/walletconnect/core/session-health.ts.html +1 -1
  131. package/coverage/lib/providers/walletconnect/core/walletconnect-client-manager.ts.html +1 -1
  132. package/coverage/lib/providers/walletconnect/core/walletconnect-provider.ts.html +10 -7
  133. package/coverage/lib/providers/walletconnect/core/walletconnect-session-store.ts.html +1 -1
  134. package/coverage/lib/providers/walletconnect/core/walletconnect-signing-orchestrator.ts.html +1 -1
  135. package/coverage/lib/providers/walletconnect/signers/hedera-signer.ts.html +1 -1
  136. package/coverage/lib/providers/walletconnect/signers/index.html +1 -1
  137. package/coverage/lib/providers/walletconnect/signers/signer-factory.ts.html +49 -49
  138. package/coverage/lib/providers/walletconnect/signers/xrpl-signer.ts.html +1 -1
  139. package/coverage/lib/services/hsuite-auth.interceptor.ts.html +568 -0
  140. package/coverage/lib/services/index.html +50 -20
  141. package/coverage/lib/services/logger.service.ts.html +4 -4
  142. package/coverage/lib/services/smart-session.service.ts.html +1264 -0
  143. package/coverage/lib/services/transaction-builders/active-account-source.ts.html +250 -0
  144. package/coverage/lib/services/transaction-builders/base-transaction-builder.service.ts.html +1 -1
  145. package/coverage/lib/services/transaction-builders/hedera-amount-utils.ts.html +1 -1
  146. package/coverage/lib/services/transaction-builders/hedera-transaction-builder.service.ts.html +318 -318
  147. package/coverage/lib/services/transaction-builders/index.html +24 -9
  148. package/coverage/lib/services/transaction-builders/xrpl-transaction-builder.service.ts.html +1 -1
  149. package/coverage/lib/services/transaction.service.ts.html +7 -10
  150. package/coverage/lib/services/unified-wallet.service.ts.html +9 -12
  151. package/coverage/lib/services/wallet-context.service.ts.html +1 -1
  152. package/coverage/lib/services/wallet-event-bus.service.ts.html +1 -1
  153. package/coverage/lib/services/wallet-providers.service.ts.html +4 -7
  154. package/coverage/lib/transports/chrome-extension-transport.ts.html +1 -1
  155. package/coverage/lib/transports/index.html +1 -1
  156. package/coverage/lib/utils/index.html +36 -21
  157. package/coverage/lib/utils/ledger-icons.util.ts.html +254 -161
  158. package/coverage/lib/utils/ledger-ui-registry.ts.html +676 -0
  159. package/dist/fesm2022/hsuite-native-connect-angular.mjs +939 -328
  160. package/dist/fesm2022/hsuite-native-connect-angular.mjs.map +1 -1
  161. package/dist/index.d.ts +489 -33
  162. package/package.json +4 -4
  163. package/src/index.ts +26 -0
  164. package/src/lib/components/account-selector/account-formatting.service.ts +8 -10
  165. package/src/lib/components/wallet-account-display/wallet-account-display.component.ts +9 -9
  166. package/src/lib/components/wallet-connect-button/wallet-connect-button.component.spec.ts +89 -0
  167. package/src/lib/components/wallet-connect-button/wallet-connect-button.component.ts +8 -0
  168. package/src/lib/components/wallet-connection-modal/wallet-connection-modal.component.html +1 -6
  169. package/src/lib/components/wallet-connection-modal/wallet-connection-modal.component.spec.ts +173 -0
  170. package/src/lib/components/wallet-connection-modal/wallet-connection-modal.component.ts +118 -37
  171. package/src/lib/models/provider-types.ts +3 -1
  172. package/src/lib/models/unified-account.model.ts +4 -1
  173. package/src/lib/providers/hsuite-native/channel-client.service.ts +1 -0
  174. package/src/lib/providers/p2p-native/p2p-session-manager.ts +1 -0
  175. package/src/lib/providers/walletconnect/core/walletconnect-provider.ts +2 -1
  176. package/src/lib/services/hsuite-auth.interceptor.ts +159 -0
  177. package/src/lib/services/smart-session.service.ts +378 -0
  178. package/src/lib/services/transaction-builders/active-account-source.spec.ts +75 -0
  179. package/src/lib/services/transaction-builders/active-account-source.ts +55 -0
  180. package/src/lib/services/transaction-builders/hedera-transaction-builder.service.ts +4 -4
  181. package/src/lib/services/transaction-builders/index.ts +1 -0
  182. package/src/lib/services/transaction.service.ts +7 -4
  183. package/src/lib/services/unified-wallet.service.spec.ts +1 -1
  184. package/src/lib/services/unified-wallet.service.ts +2 -3
  185. package/src/lib/services/wallet-providers.service.ts +0 -1
  186. package/src/lib/utils/index.ts +1 -0
  187. package/src/lib/utils/ledger-icons.util.ts +61 -30
  188. package/src/lib/utils/ledger-ui-registry.ts +197 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hsuite/native-connect-angular",
3
- "version": "1.0.0",
3
+ "version": "2.1.1",
4
4
  "license": "PolyForm-Noncommercial-1.0.0",
5
5
  "description": "Angular integration SDK for HSuite Wallet - provides direct SDK integration without wrappers",
6
6
  "type": "module",
@@ -23,9 +23,9 @@
23
23
  "dependencies": {
24
24
  "@hashgraph/proto": "^2.25.0",
25
25
  "@hashgraph/sdk": "^2.76.0",
26
- "@hsuite/native-connect-sdk": "^1.0.0",
27
- "@hsuite/native-connect-types": "^1.0.0",
28
- "@hsuite/native-connect-ui": "^1.0.0",
26
+ "@hsuite/native-connect-sdk": "^2.1.1",
27
+ "@hsuite/native-connect-types": "^2.1.1",
28
+ "@hsuite/native-connect-ui": "^2.1.1",
29
29
  "@walletconnect/modal": "^2.7.0",
30
30
  "@walletconnect/sign-client": "^2.23.0",
31
31
  "@walletconnect/types": "^2.23.0",
package/src/index.ts CHANGED
@@ -78,12 +78,28 @@ export { WalletEventBus } from './lib/services/wallet-event-bus.service';
78
78
  export { WalletContextService } from './lib/services/wallet-context.service';
79
79
  export { TransactionService } from './lib/services/transaction.service';
80
80
  export { LoggerService } from './lib/services/logger.service';
81
+ export {
82
+ SmartSessionService,
83
+ SMART_SESSION_CONFIG,
84
+ type SmartSessionConfig,
85
+ type SmartHostHealth,
86
+ type SmartHostChallenge,
87
+ type SmartHostVerifyRequest,
88
+ type SmartHostVerifyResponse,
89
+ } from './lib/services/smart-session.service';
90
+ export {
91
+ HsuiteAuthInterceptor,
92
+ hsuiteAuthInterceptor,
93
+ HSUITE_AUTH_HEADER,
94
+ HSUITE_LEDGER_HEADER,
95
+ } from './lib/services/hsuite-auth.interceptor';
81
96
 
82
97
  // Transaction Builders (for dApps to construct transactions)
83
98
  export {
84
99
  HederaTransactionBuilderService,
85
100
  XrplTransactionBuilderService,
86
101
  scaleHederaAmountToBaseUnits,
102
+ ACTIVE_ACCOUNT_SOURCE,
87
103
  } from './lib/services/transaction-builders';
88
104
 
89
105
  // Transaction builder types (for dApps)
@@ -94,6 +110,7 @@ export type {
94
110
  TopicCreateOptions,
95
111
  TokenCreateOptions,
96
112
  AccountCreateOptions,
113
+ ActiveAccountSource,
97
114
  } from './lib/services/transaction-builders';
98
115
 
99
116
  // Transports
@@ -200,4 +217,13 @@ export {
200
217
  DEFAULT_LEDGER_ICONS,
201
218
  LEDGER_COLORS,
202
219
  LEDGER_NAMES,
220
+ LEDGER_ICON_NAMES,
221
+ registerLedgerIcons,
203
222
  } from './lib/utils';
223
+ // Registry-driven ledger presentation (open/extensible; the single source of
224
+ // truth the helpers above derive from).
225
+ export { LedgerUIRegistry } from './lib/utils';
226
+ export type { LedgerUiDescriptor } from './lib/utils';
227
+ // Canonical, open ledger identity — re-exported from the shared types package so
228
+ // consumers get the single source of truth, not a narrowing local duplicate.
229
+ export type { LedgerId } from '@hsuite/native-connect-types';
@@ -18,6 +18,8 @@
18
18
 
19
19
  import { Injectable } from '@angular/core';
20
20
 
21
+ import { LedgerUIRegistry } from '../../utils/ledger-ui-registry';
22
+
21
23
  /**
22
24
  * Account formatting service.
23
25
  *
@@ -46,11 +48,11 @@ export class AccountFormattingService {
46
48
  * @returns Display name
47
49
  */
48
50
  getLedgerName(ledgerId: string): string {
49
- const names: Record<string, string> = {
50
- hedera: 'Hedera',
51
- xrpl: 'XRPL',
52
- };
53
- return names[ledgerId?.toLowerCase()] || ledgerId?.toUpperCase() || 'Unknown';
51
+ return (
52
+ LedgerUIRegistry.get(ledgerId?.toLowerCase())?.shortName ||
53
+ ledgerId?.toUpperCase() ||
54
+ 'Unknown'
55
+ );
54
56
  }
55
57
 
56
58
  /**
@@ -60,11 +62,7 @@ export class AccountFormattingService {
60
62
  * @returns Ionic color name
61
63
  */
62
64
  getLedgerColor(ledgerId: string): string {
63
- const colors: Record<string, string> = {
64
- hedera: 'success',
65
- xrpl: 'tertiary',
66
- };
67
- return colors[ledgerId?.toLowerCase()] || 'medium';
65
+ return LedgerUIRegistry.get(ledgerId?.toLowerCase())?.badgeColor || 'medium';
68
66
  }
69
67
 
70
68
  /**
@@ -16,12 +16,14 @@
16
16
  * and responsive styling. Eliminates repetitive account display boilerplate.
17
17
  */
18
18
 
19
- import { Component, Input, computed, inject } from '@angular/core';
20
19
  import { CommonModule } from '@angular/common';
20
+ import { Component, Input, computed, inject } from '@angular/core';
21
21
  import { IonText, IonBadge, IonIcon } from '@ionic/angular/standalone';
22
22
  import { addIcons } from 'ionicons';
23
23
  import { walletOutline, personOutline, peopleOutline } from 'ionicons/icons';
24
+
24
25
  import { WalletContextService } from '../../services/wallet-context.service';
26
+ import { LedgerUIRegistry } from '../../utils/ledger-ui-registry';
25
27
 
26
28
  /**
27
29
  * Pre-built component for displaying active account
@@ -112,26 +114,24 @@ export class WalletAccountDisplayComponent {
112
114
  return null;
113
115
  });
114
116
 
117
+ /**
118
+ *
119
+ */
115
120
  constructor() {
116
121
  addIcons({ walletOutline, personOutline, peopleOutline });
117
122
  }
118
123
 
119
124
  /**
120
125
  * Get color for ledger badge
126
+ * @param ledgerId
121
127
  */
122
128
  protected getLedgerColor(ledgerId: string): string {
123
- switch (ledgerId.toLowerCase()) {
124
- case 'hedera':
125
- return 'success';
126
- case 'xrpl':
127
- return 'tertiary';
128
- default:
129
- return 'primary';
130
- }
129
+ return LedgerUIRegistry.get(ledgerId.toLowerCase())?.badgeColor ?? 'primary';
131
130
  }
132
131
 
133
132
  /**
134
133
  * Format network ID for display
134
+ * @param networkId
135
135
  */
136
136
  protected formatNetwork(networkId: string): string {
137
137
  const parts = networkId.split(':');
@@ -0,0 +1,89 @@
1
+ /**
2
+ * HSuite Native Connect
3
+ * Copyright 2024-2025 HSuite (https://hsuite.finance)
4
+ *
5
+ * SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0
6
+ *
7
+ * This file is part of HSuite Native Connect. For commercial licensing,
8
+ * visit https://hsuite.finance/licensing
9
+ */
10
+
11
+ /**
12
+ * @fileoverview Unit tests for WalletConnectButtonComponent.
13
+ *
14
+ * Focused on threading the `network` pinning input through to the connection
15
+ * modal, so the convenience button exposes the same capability as opening the
16
+ * modal directly.
17
+ */
18
+
19
+ import { describe, it, expect, beforeEach, vi } from 'vitest';
20
+ import { TestBed } from '@angular/core/testing';
21
+ import { ModalController } from '@ionic/angular/standalone';
22
+
23
+ // Mock the logger so the SDK does not need real configuration during tests.
24
+ vi.mock('@hsuite/native-connect-sdk', () => ({
25
+ getLogger: vi.fn(() => ({
26
+ debug: vi.fn(),
27
+ info: vi.fn(),
28
+ warn: vi.fn(),
29
+ error: vi.fn(),
30
+ scoped: vi.fn(() => ({
31
+ debug: vi.fn(),
32
+ info: vi.fn(),
33
+ warn: vi.fn(),
34
+ error: vi.fn(),
35
+ })),
36
+ })),
37
+ }));
38
+
39
+ import { UnifiedWalletService } from '../../services/unified-wallet.service';
40
+
41
+ import { WalletConnectButtonComponent } from './wallet-connect-button.component';
42
+
43
+ describe('WalletConnectButtonComponent — network pinning', () => {
44
+ let component: WalletConnectButtonComponent;
45
+ let modalController: { create: ReturnType<typeof vi.fn> };
46
+ let modal: { present: ReturnType<typeof vi.fn>; onDidDismiss: ReturnType<typeof vi.fn> };
47
+
48
+ beforeEach(() => {
49
+ modal = {
50
+ present: vi.fn().mockResolvedValue(undefined),
51
+ onDidDismiss: vi.fn().mockResolvedValue({ data: { connected: false } }),
52
+ };
53
+ modalController = { create: vi.fn().mockResolvedValue(modal) };
54
+ const wallet = {
55
+ allAccounts: vi.fn().mockReturnValue([]),
56
+ isAnyConnected: vi.fn().mockReturnValue(false),
57
+ };
58
+
59
+ TestBed.configureTestingModule({
60
+ providers: [
61
+ { provide: ModalController, useValue: modalController },
62
+ { provide: UnifiedWalletService, useValue: wallet },
63
+ ],
64
+ });
65
+
66
+ component = TestBed.runInInjectionContext(() => new WalletConnectButtonComponent());
67
+ });
68
+
69
+ it('forwards the pinned network to the connection modal', async () => {
70
+ component.network = 'mainnet';
71
+
72
+ await component.connect();
73
+
74
+ expect(modalController.create).toHaveBeenCalledWith(
75
+ expect.objectContaining({
76
+ componentProps: expect.objectContaining({ network: 'mainnet' }),
77
+ }),
78
+ );
79
+ });
80
+
81
+ it('passes no network by default so the user chooses it', async () => {
82
+ await component.connect();
83
+
84
+ const props = (
85
+ modalController.create.mock.calls[0][0] as { componentProps: { network?: string } }
86
+ ).componentProps;
87
+ expect(props.network).toBeUndefined();
88
+ });
89
+ });
@@ -69,6 +69,13 @@ export class WalletConnectButtonComponent {
69
69
  */
70
70
  @Input() walletUrl = DEFAULT_WALLET_URL;
71
71
 
72
+ /**
73
+ * Pins the connection network and hides the network-selection step in the
74
+ * modal. When set to `'mainnet'` or `'testnet'`, the dApp decides the network
75
+ * and the user never sees the picker. When omitted, the user chooses.
76
+ */
77
+ @Input() network?: 'mainnet' | 'testnet';
78
+
72
79
  /**
73
80
  * Whether to show session information when connected
74
81
  * @default true
@@ -160,6 +167,7 @@ export class WalletConnectButtonComponent {
160
167
  appName: this.appName,
161
168
  appDescription: this.appDescription,
162
169
  walletUrl: this.walletUrl,
170
+ network: this.network,
163
171
  },
164
172
  });
165
173
 
@@ -2,12 +2,7 @@
2
2
  <div class="modal-inner-content wallet-connection-modal">
3
3
  <div class="header">
4
4
  <div class="title">
5
- <ion-button
6
- *ngIf="currentStep() > 1 && currentStep() !== ConnectionStep.ConnectionProgress"
7
- (click)="back()"
8
- fill="clear"
9
- class="back-btn"
10
- >
5
+ <ion-button *ngIf="canGoBack()" (click)="back()" fill="clear" class="back-btn">
11
6
  <ion-icon slot="icon-only" name="arrow-back-outline"></ion-icon>
12
7
  </ion-button>
13
8
  <p>{{ stepTitle() }}</p>
@@ -0,0 +1,173 @@
1
+ /**
2
+ * HSuite Native Connect
3
+ * Copyright 2024-2025 HSuite (https://hsuite.finance)
4
+ *
5
+ * SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0
6
+ *
7
+ * This file is part of HSuite Native Connect. For commercial licensing,
8
+ * visit https://hsuite.finance/licensing
9
+ */
10
+
11
+ /**
12
+ * @fileoverview Unit tests for WalletConnectionModalComponent.
13
+ *
14
+ * Focused on the `network` pinning capability: a host dApp can fix the
15
+ * connection network ('mainnet' | 'testnet') so the user is never shown the
16
+ * network-selection step. When the input is absent the modal behaves exactly
17
+ * as before (user picks the network as step 1).
18
+ */
19
+
20
+ import { describe, it, expect, beforeEach, vi } from 'vitest';
21
+ import { TestBed } from '@angular/core/testing';
22
+ import { ModalController, Platform } from '@ionic/angular';
23
+
24
+ // Mock the logger so the SDK does not need real configuration during tests.
25
+ vi.mock('@hsuite/native-connect-sdk', () => ({
26
+ getLogger: vi.fn(() => ({
27
+ debug: vi.fn(),
28
+ info: vi.fn(),
29
+ warn: vi.fn(),
30
+ error: vi.fn(),
31
+ scoped: vi.fn(() => ({
32
+ debug: vi.fn(),
33
+ info: vi.fn(),
34
+ warn: vi.fn(),
35
+ error: vi.fn(),
36
+ })),
37
+ })),
38
+ }));
39
+
40
+ import { P2PNativeProvider } from '../../providers/p2p-native/p2p-native.provider';
41
+ import { UnifiedWalletService } from '../../services/unified-wallet.service';
42
+
43
+ import { WalletConnectionModalComponent } from './wallet-connection-modal.component';
44
+
45
+ /** ConnectionStep display values mirrored from the component (1-based). */
46
+ const NETWORK_SELECTION_STEP = 1;
47
+ const PROTOCOL_SELECTION_STEP = 2;
48
+
49
+ describe('WalletConnectionModalComponent — network pinning', () => {
50
+ let component: WalletConnectionModalComponent;
51
+ let modalController: { dismiss: ReturnType<typeof vi.fn>; create: ReturnType<typeof vi.fn> };
52
+ let unifiedWalletService: { connect: ReturnType<typeof vi.fn> };
53
+
54
+ beforeEach(() => {
55
+ modalController = {
56
+ dismiss: vi.fn().mockResolvedValue(undefined),
57
+ create: vi.fn(),
58
+ };
59
+ unifiedWalletService = {
60
+ connect: vi.fn().mockResolvedValue(undefined),
61
+ };
62
+ const platform = { is: vi.fn().mockReturnValue(false) };
63
+ const p2pNativeProvider = {
64
+ onPeerConnected: vi.fn(),
65
+ createPairingOffer: vi.fn(),
66
+ waitForSessionApproval: vi.fn(),
67
+ };
68
+
69
+ TestBed.configureTestingModule({
70
+ providers: [
71
+ { provide: Platform, useValue: platform },
72
+ { provide: P2PNativeProvider, useValue: p2pNativeProvider },
73
+ ],
74
+ });
75
+
76
+ // Construct directly inside an injection context so the component's
77
+ // `inject(Platform)` / `inject(P2PNativeProvider)` field initializers
78
+ // resolve, without compiling the external template/styles (this package
79
+ // has no Angular template-resolving test plugin configured).
80
+ component = TestBed.runInInjectionContext(
81
+ () =>
82
+ new WalletConnectionModalComponent(
83
+ modalController as unknown as ModalController,
84
+ unifiedWalletService as unknown as UnifiedWalletService,
85
+ ),
86
+ );
87
+ });
88
+
89
+ describe('default behavior (no network input)', () => {
90
+ it('starts on the network-selection step so the user chooses the network', () => {
91
+ component.ngOnInit();
92
+
93
+ expect(component.currentStep()).toBe(NETWORK_SELECTION_STEP);
94
+ expect(component.selectedNetwork()).toBe('testnet');
95
+ });
96
+
97
+ it('allows going back from protocol selection to network selection', () => {
98
+ component.ngOnInit();
99
+ // Advance from network selection to protocol selection the way the UI does.
100
+ component.selectNetworkAndProceed('testnet');
101
+ expect(component.currentStep()).toBe(PROTOCOL_SELECTION_STEP);
102
+
103
+ component.back();
104
+
105
+ expect(component.currentStep()).toBe(NETWORK_SELECTION_STEP);
106
+ });
107
+
108
+ it('keeps "Network" as the first step in the progress indicator', () => {
109
+ component.ngOnInit();
110
+ component.selectProtocol('hsuite-native');
111
+ component.selectConnectionMethod('desktop');
112
+
113
+ expect(component.stepConfig().labels).toEqual(['Network', 'Protocol', 'Method']);
114
+ expect(component.stepConfig().total).toBe(3);
115
+ });
116
+ });
117
+
118
+ describe('pinned network (network = "mainnet")', () => {
119
+ beforeEach(() => {
120
+ component.network = 'mainnet';
121
+ component.ngOnInit();
122
+ });
123
+
124
+ it('skips the network-selection step and starts on protocol selection', () => {
125
+ expect(component.currentStep()).toBe(PROTOCOL_SELECTION_STEP);
126
+ });
127
+
128
+ it('pins the selected network to the provided value', () => {
129
+ expect(component.selectedNetwork()).toBe('mainnet');
130
+ });
131
+
132
+ it('does not allow navigating back to the network-selection step', () => {
133
+ component.back();
134
+
135
+ expect(component.currentStep()).toBe(PROTOCOL_SELECTION_STEP);
136
+ });
137
+
138
+ it('hides the back affordance on the first reachable step', () => {
139
+ expect(component.canGoBack()).toBe(false);
140
+ });
141
+
142
+ it('drops "Network" from the progress indicator and renumbers', () => {
143
+ component.selectProtocol('hsuite-native');
144
+ component.selectConnectionMethod('desktop');
145
+
146
+ expect(component.stepConfig().labels).toEqual(['Protocol', 'Method']);
147
+ expect(component.stepConfig().total).toBe(2);
148
+ expect(component.displayStep()).toBe(1);
149
+ });
150
+
151
+ it('forwards the pinned network to the SDK connect call', async () => {
152
+ component.selectProtocolAndProceed('hsuite-native');
153
+ component.selectConnectionMethod('desktop');
154
+
155
+ await component.next();
156
+
157
+ expect(unifiedWalletService.connect).toHaveBeenCalledWith(
158
+ 'hsuite-native',
159
+ expect.objectContaining({ networkId: 'mainnet' }),
160
+ );
161
+ });
162
+ });
163
+
164
+ describe('pinned network (network = "testnet")', () => {
165
+ it('skips selection and pins testnet', () => {
166
+ component.network = 'testnet';
167
+ component.ngOnInit();
168
+
169
+ expect(component.currentStep()).toBe(PROTOCOL_SELECTION_STEP);
170
+ expect(component.selectedNetwork()).toBe('testnet');
171
+ });
172
+ });
173
+ });