@hsuite/native-connect-angular 1.0.0
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/README.md +48 -0
- package/USAGE_EXAMPLES.md +476 -0
- package/assets/wallets/extension.svg +7 -0
- package/assets/wallets/hashpack.svg +6 -0
- package/assets/wallets/hsuite.svg +11 -0
- package/assets/wallets/kabila.svg +11 -0
- package/assets/wallets/walletconnect.svg +13 -0
- package/coverage/base.css +224 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/coverage-summary.json +50 -0
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +476 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +476 -0
- package/coverage/lcov-report/lib/components/account-selector/account-actions/account-actions.component.ts.html +868 -0
- package/coverage/lcov-report/lib/components/account-selector/account-actions/index.html +116 -0
- package/coverage/lcov-report/lib/components/account-selector/account-filter/account-filter.component.ts.html +1288 -0
- package/coverage/lcov-report/lib/components/account-selector/account-filter/index.html +116 -0
- package/coverage/lcov-report/lib/components/account-selector/account-formatting.service.ts.html +685 -0
- package/coverage/lcov-report/lib/components/account-selector/account-grouping.service.ts.html +766 -0
- package/coverage/lcov-report/lib/components/account-selector/account-list/account-list.component.ts.html +1495 -0
- package/coverage/lcov-report/lib/components/account-selector/account-list/index.html +116 -0
- package/coverage/lcov-report/lib/components/account-selector/account-selector.component.ts.html +1495 -0
- package/coverage/lcov-report/lib/components/account-selector/account-selector.service.ts.html +1588 -0
- package/coverage/lcov-report/lib/components/account-selector/index.html +161 -0
- package/coverage/lcov-report/lib/components/wallet-account-display/index.html +116 -0
- package/coverage/lcov-report/lib/components/wallet-account-display/wallet-account-display.component.ts.html +505 -0
- package/coverage/lcov-report/lib/components/wallet-connect-button/index.html +116 -0
- package/coverage/lcov-report/lib/components/wallet-connect-button/wallet-connect-button.component.ts.html +805 -0
- package/coverage/lcov-report/lib/components/wallet-connect-prompt/index.html +116 -0
- package/coverage/lcov-report/lib/components/wallet-connect-prompt/wallet-connect-prompt.component.ts.html +409 -0
- package/coverage/lcov-report/lib/components/wallet-connected-guard/index.html +116 -0
- package/coverage/lcov-report/lib/components/wallet-connected-guard/wallet-connected-guard.component.ts.html +304 -0
- package/coverage/lcov-report/lib/components/wallet-connection-modal/connection-method-step/connection-method-step.component.ts.html +436 -0
- package/coverage/lcov-report/lib/components/wallet-connection-modal/connection-method-step/index.html +116 -0
- package/coverage/lcov-report/lib/components/wallet-connection-modal/index.html +116 -0
- package/coverage/lcov-report/lib/components/wallet-connection-modal/qr-pairing-step/index.html +116 -0
- package/coverage/lcov-report/lib/components/wallet-connection-modal/qr-pairing-step/qr-pairing-step.component.ts.html +2287 -0
- package/coverage/lcov-report/lib/components/wallet-connection-modal/wallet-connection-modal.component.ts.html +2275 -0
- package/coverage/lcov-report/lib/components/wallet-session-display/index.html +116 -0
- package/coverage/lcov-report/lib/components/wallet-session-display/wallet-session-display.component.ts.html +676 -0
- package/coverage/lcov-report/lib/components/wallet-transaction-status/index.html +116 -0
- package/coverage/lcov-report/lib/components/wallet-transaction-status/wallet-transaction-status.component.ts.html +703 -0
- package/coverage/lcov-report/lib/directives/index.html +146 -0
- package/coverage/lcov-report/lib/directives/wallet-connected.directive.ts.html +670 -0
- package/coverage/lcov-report/lib/directives/wallet-context.directive.ts.html +547 -0
- package/coverage/lcov-report/lib/directives/wallet-events.directive.ts.html +781 -0
- package/coverage/lcov-report/lib/hsuite-wallet.module.ts.html +715 -0
- package/coverage/lcov-report/lib/index.html +116 -0
- package/coverage/lcov-report/lib/models/connection-config.model.ts.html +280 -0
- package/coverage/lcov-report/lib/models/index.html +131 -0
- package/coverage/lcov-report/lib/models/provider-types.ts.html +577 -0
- package/coverage/lcov-report/lib/providers/base-wallet-provider.ts.html +1138 -0
- package/coverage/lcov-report/lib/providers/hsuite-native/channel-client.service.ts.html +2671 -0
- package/coverage/lcov-report/lib/providers/hsuite-native/index.html +116 -0
- package/coverage/lcov-report/lib/providers/hsuite-native-provider.ts.html +2347 -0
- package/coverage/lcov-report/lib/providers/index.html +146 -0
- package/coverage/lcov-report/lib/providers/p2p-native/index.html +131 -0
- package/coverage/lcov-report/lib/providers/p2p-native/p2p-native.provider.ts.html +2254 -0
- package/coverage/lcov-report/lib/providers/p2p-native/p2p-session-manager.ts.html +2170 -0
- package/coverage/lcov-report/lib/providers/wallet-error-handler.ts.html +1132 -0
- package/coverage/lcov-report/lib/providers/walletconnect/core/index.html +176 -0
- package/coverage/lcov-report/lib/providers/walletconnect/core/session-health.ts.html +673 -0
- package/coverage/lcov-report/lib/providers/walletconnect/core/walletconnect-client-manager.ts.html +1177 -0
- package/coverage/lcov-report/lib/providers/walletconnect/core/walletconnect-provider.ts.html +2563 -0
- package/coverage/lcov-report/lib/providers/walletconnect/core/walletconnect-session-store.ts.html +904 -0
- package/coverage/lcov-report/lib/providers/walletconnect/core/walletconnect-signing-orchestrator.ts.html +982 -0
- package/coverage/lcov-report/lib/providers/walletconnect/signers/hedera-signer.ts.html +1915 -0
- package/coverage/lcov-report/lib/providers/walletconnect/signers/index.html +146 -0
- package/coverage/lcov-report/lib/providers/walletconnect/signers/signer-factory.ts.html +445 -0
- package/coverage/lcov-report/lib/providers/walletconnect/signers/xrpl-signer.ts.html +1519 -0
- package/coverage/lcov-report/lib/services/index.html +191 -0
- package/coverage/lcov-report/lib/services/logger.service.ts.html +463 -0
- package/coverage/lcov-report/lib/services/transaction-builders/base-transaction-builder.service.ts.html +1840 -0
- package/coverage/lcov-report/lib/services/transaction-builders/hedera-amount-utils.ts.html +337 -0
- package/coverage/lcov-report/lib/services/transaction-builders/hedera-transaction-builder.service.ts.html +3940 -0
- package/coverage/lcov-report/lib/services/transaction-builders/index.html +161 -0
- package/coverage/lcov-report/lib/services/transaction-builders/xrpl-transaction-builder.service.ts.html +2581 -0
- package/coverage/lcov-report/lib/services/transaction.service.ts.html +1123 -0
- package/coverage/lcov-report/lib/services/unified-wallet.service.ts.html +2641 -0
- package/coverage/lcov-report/lib/services/wallet-context.service.ts.html +637 -0
- package/coverage/lcov-report/lib/services/wallet-event-bus.service.ts.html +643 -0
- package/coverage/lcov-report/lib/services/wallet-providers.service.ts.html +496 -0
- package/coverage/lcov-report/lib/transports/chrome-extension-transport.ts.html +823 -0
- package/coverage/lcov-report/lib/transports/index.html +116 -0
- package/coverage/lcov-report/lib/utils/index.html +116 -0
- package/coverage/lcov-report/lib/utils/ledger-icons.util.ts.html +319 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +210 -0
- package/coverage/lcov.info +19252 -0
- package/coverage/lib/components/account-selector/account-actions/account-actions.component.ts.html +868 -0
- package/coverage/lib/components/account-selector/account-actions/index.html +116 -0
- package/coverage/lib/components/account-selector/account-filter/account-filter.component.ts.html +1288 -0
- package/coverage/lib/components/account-selector/account-filter/index.html +116 -0
- package/coverage/lib/components/account-selector/account-formatting.service.ts.html +685 -0
- package/coverage/lib/components/account-selector/account-grouping.service.ts.html +766 -0
- package/coverage/lib/components/account-selector/account-list/account-list.component.ts.html +1495 -0
- package/coverage/lib/components/account-selector/account-list/index.html +116 -0
- package/coverage/lib/components/account-selector/account-selector.component.ts.html +1495 -0
- package/coverage/lib/components/account-selector/account-selector.service.ts.html +1588 -0
- package/coverage/lib/components/account-selector/index.html +161 -0
- package/coverage/lib/components/wallet-account-display/index.html +116 -0
- package/coverage/lib/components/wallet-account-display/wallet-account-display.component.ts.html +505 -0
- package/coverage/lib/components/wallet-connect-button/index.html +116 -0
- package/coverage/lib/components/wallet-connect-button/wallet-connect-button.component.ts.html +805 -0
- package/coverage/lib/components/wallet-connect-prompt/index.html +116 -0
- package/coverage/lib/components/wallet-connect-prompt/wallet-connect-prompt.component.ts.html +409 -0
- package/coverage/lib/components/wallet-connected-guard/index.html +116 -0
- package/coverage/lib/components/wallet-connected-guard/wallet-connected-guard.component.ts.html +304 -0
- package/coverage/lib/components/wallet-connection-modal/connection-method-step/connection-method-step.component.ts.html +436 -0
- package/coverage/lib/components/wallet-connection-modal/connection-method-step/index.html +116 -0
- package/coverage/lib/components/wallet-connection-modal/index.html +116 -0
- package/coverage/lib/components/wallet-connection-modal/qr-pairing-step/index.html +116 -0
- package/coverage/lib/components/wallet-connection-modal/qr-pairing-step/qr-pairing-step.component.ts.html +2287 -0
- package/coverage/lib/components/wallet-connection-modal/wallet-connection-modal.component.ts.html +2275 -0
- package/coverage/lib/components/wallet-session-display/index.html +116 -0
- package/coverage/lib/components/wallet-session-display/wallet-session-display.component.ts.html +676 -0
- package/coverage/lib/components/wallet-transaction-status/index.html +116 -0
- package/coverage/lib/components/wallet-transaction-status/wallet-transaction-status.component.ts.html +703 -0
- package/coverage/lib/directives/index.html +146 -0
- package/coverage/lib/directives/wallet-connected.directive.ts.html +670 -0
- package/coverage/lib/directives/wallet-context.directive.ts.html +547 -0
- package/coverage/lib/directives/wallet-events.directive.ts.html +781 -0
- package/coverage/lib/hsuite-wallet.module.ts.html +715 -0
- package/coverage/lib/index.html +116 -0
- package/coverage/lib/models/connection-config.model.ts.html +280 -0
- package/coverage/lib/models/index.html +131 -0
- package/coverage/lib/models/provider-types.ts.html +577 -0
- package/coverage/lib/providers/base-wallet-provider.ts.html +1138 -0
- package/coverage/lib/providers/hsuite-native/channel-client.service.ts.html +2671 -0
- package/coverage/lib/providers/hsuite-native/index.html +116 -0
- package/coverage/lib/providers/hsuite-native-provider.ts.html +2347 -0
- package/coverage/lib/providers/index.html +146 -0
- package/coverage/lib/providers/p2p-native/index.html +131 -0
- package/coverage/lib/providers/p2p-native/p2p-native.provider.ts.html +2254 -0
- package/coverage/lib/providers/p2p-native/p2p-session-manager.ts.html +2170 -0
- package/coverage/lib/providers/wallet-error-handler.ts.html +1132 -0
- package/coverage/lib/providers/walletconnect/core/index.html +176 -0
- package/coverage/lib/providers/walletconnect/core/session-health.ts.html +673 -0
- package/coverage/lib/providers/walletconnect/core/walletconnect-client-manager.ts.html +1177 -0
- package/coverage/lib/providers/walletconnect/core/walletconnect-provider.ts.html +2563 -0
- package/coverage/lib/providers/walletconnect/core/walletconnect-session-store.ts.html +904 -0
- package/coverage/lib/providers/walletconnect/core/walletconnect-signing-orchestrator.ts.html +982 -0
- package/coverage/lib/providers/walletconnect/signers/hedera-signer.ts.html +1915 -0
- package/coverage/lib/providers/walletconnect/signers/index.html +146 -0
- package/coverage/lib/providers/walletconnect/signers/signer-factory.ts.html +445 -0
- package/coverage/lib/providers/walletconnect/signers/xrpl-signer.ts.html +1519 -0
- package/coverage/lib/services/index.html +191 -0
- package/coverage/lib/services/logger.service.ts.html +463 -0
- package/coverage/lib/services/transaction-builders/base-transaction-builder.service.ts.html +1840 -0
- package/coverage/lib/services/transaction-builders/hedera-amount-utils.ts.html +337 -0
- package/coverage/lib/services/transaction-builders/hedera-transaction-builder.service.ts.html +3940 -0
- package/coverage/lib/services/transaction-builders/index.html +161 -0
- package/coverage/lib/services/transaction-builders/xrpl-transaction-builder.service.ts.html +2581 -0
- package/coverage/lib/services/transaction.service.ts.html +1123 -0
- package/coverage/lib/services/unified-wallet.service.ts.html +2641 -0
- package/coverage/lib/services/wallet-context.service.ts.html +637 -0
- package/coverage/lib/services/wallet-event-bus.service.ts.html +643 -0
- package/coverage/lib/services/wallet-providers.service.ts.html +496 -0
- package/coverage/lib/transports/chrome-extension-transport.ts.html +823 -0
- package/coverage/lib/transports/index.html +116 -0
- package/coverage/lib/utils/index.html +116 -0
- package/coverage/lib/utils/ledger-icons.util.ts.html +319 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +210 -0
- package/dist/README.md +48 -0
- package/dist/fesm2022/hsuite-native-connect-angular.mjs +14592 -0
- package/dist/fesm2022/hsuite-native-connect-angular.mjs.map +1 -0
- package/dist/index.d.ts +6949 -0
- package/examples/minimal-connect.ts +178 -0
- package/examples/multi-protocol.ts +495 -0
- package/examples/transaction-signing.ts +361 -0
- package/jest.config.json +45 -0
- package/karma.conf.js +42 -0
- package/ng-package.json +20 -0
- package/package.json +60 -0
- package/src/index.ts +203 -0
- package/src/lib/components/account-selector/account-actions/account-actions.component.ts +261 -0
- package/src/lib/components/account-selector/account-filter/account-filter.component.ts +401 -0
- package/src/lib/components/account-selector/account-formatting.service.ts +200 -0
- package/src/lib/components/account-selector/account-grouping.service.ts +227 -0
- package/src/lib/components/account-selector/account-list/account-list.component.ts +470 -0
- package/src/lib/components/account-selector/account-selector.component.html +135 -0
- package/src/lib/components/account-selector/account-selector.component.scss +2039 -0
- package/src/lib/components/account-selector/account-selector.component.ts +470 -0
- package/src/lib/components/account-selector/account-selector.service.ts +501 -0
- package/src/lib/components/wallet-account-display/wallet-account-display.component.html +34 -0
- package/src/lib/components/wallet-account-display/wallet-account-display.component.scss +99 -0
- package/src/lib/components/wallet-account-display/wallet-account-display.component.ts +140 -0
- package/src/lib/components/wallet-connect-button/wallet-connect-button.component.html +14 -0
- package/src/lib/components/wallet-connect-button/wallet-connect-button.component.scss +272 -0
- package/src/lib/components/wallet-connect-button/wallet-connect-button.component.ts +240 -0
- package/src/lib/components/wallet-connect-prompt/wallet-connect-prompt.component.html +24 -0
- package/src/lib/components/wallet-connect-prompt/wallet-connect-prompt.component.scss +50 -0
- package/src/lib/components/wallet-connect-prompt/wallet-connect-prompt.component.ts +108 -0
- package/src/lib/components/wallet-connected-guard/wallet-connected-guard.component.html +24 -0
- package/src/lib/components/wallet-connected-guard/wallet-connected-guard.component.ts +73 -0
- package/src/lib/components/wallet-connection-modal/connection-method-step/connection-method-step.component.html +56 -0
- package/src/lib/components/wallet-connection-modal/connection-method-step/connection-method-step.component.scss +218 -0
- package/src/lib/components/wallet-connection-modal/connection-method-step/connection-method-step.component.ts +117 -0
- package/src/lib/components/wallet-connection-modal/qr-pairing-step/qr-pairing-step.component.html +94 -0
- package/src/lib/components/wallet-connection-modal/qr-pairing-step/qr-pairing-step.component.scss +272 -0
- package/src/lib/components/wallet-connection-modal/qr-pairing-step/qr-pairing-step.component.ts +734 -0
- package/src/lib/components/wallet-connection-modal/wallet-connection-modal.component.html +197 -0
- package/src/lib/components/wallet-connection-modal/wallet-connection-modal.component.scss +678 -0
- package/src/lib/components/wallet-connection-modal/wallet-connection-modal.component.ts +730 -0
- package/src/lib/components/wallet-session-display/wallet-session-display.component.html +110 -0
- package/src/lib/components/wallet-session-display/wallet-session-display.component.scss +179 -0
- package/src/lib/components/wallet-session-display/wallet-session-display.component.ts +197 -0
- package/src/lib/components/wallet-transaction-status/wallet-transaction-status.component.html +65 -0
- package/src/lib/components/wallet-transaction-status/wallet-transaction-status.component.scss +254 -0
- package/src/lib/components/wallet-transaction-status/wallet-transaction-status.component.ts +206 -0
- package/src/lib/directives/wallet-connected.directive.ts +195 -0
- package/src/lib/directives/wallet-context.directive.ts +154 -0
- package/src/lib/directives/wallet-events.directive.ts +232 -0
- package/src/lib/hsuite-wallet.module.ts +210 -0
- package/src/lib/models/connection-config.model.ts +65 -0
- package/src/lib/models/provider-types.ts +164 -0
- package/src/lib/models/unified-account.model.ts +76 -0
- package/src/lib/models/wallet-context.model.ts +121 -0
- package/src/lib/models/wallet-events.model.ts +158 -0
- package/src/lib/providers/base-wallet-provider.ts +351 -0
- package/src/lib/providers/hsuite-native/channel-client.service.spec.ts +73 -0
- package/src/lib/providers/hsuite-native/channel-client.service.ts +862 -0
- package/src/lib/providers/hsuite-native/index.ts +8 -0
- package/src/lib/providers/hsuite-native-provider.ts +754 -0
- package/src/lib/providers/mobile-native/mobile-native.provider.spec.ts +19 -0
- package/src/lib/providers/p2p-native/index.ts +30 -0
- package/src/lib/providers/p2p-native/p2p-native.provider.spec.ts +523 -0
- package/src/lib/providers/p2p-native/p2p-native.provider.ts +723 -0
- package/src/lib/providers/p2p-native/p2p-session-manager.ts +695 -0
- package/src/lib/providers/wallet-error-handler.ts +349 -0
- package/src/lib/providers/walletconnect/core/base-signer.interface.ts +122 -0
- package/src/lib/providers/walletconnect/core/session-health.ts +196 -0
- package/src/lib/providers/walletconnect/core/walletconnect-client-manager.ts +364 -0
- package/src/lib/providers/walletconnect/core/walletconnect-provider.integration.spec.ts +348 -0
- package/src/lib/providers/walletconnect/core/walletconnect-provider.ts +826 -0
- package/src/lib/providers/walletconnect/core/walletconnect-session-store.ts +273 -0
- package/src/lib/providers/walletconnect/core/walletconnect-signing-orchestrator.ts +299 -0
- package/src/lib/providers/walletconnect/core/walletconnect-types.ts +48 -0
- package/src/lib/providers/walletconnect/index.ts +33 -0
- package/src/lib/providers/walletconnect/signers/hedera-signer.spec.ts +367 -0
- package/src/lib/providers/walletconnect/signers/hedera-signer.ts +610 -0
- package/src/lib/providers/walletconnect/signers/signer-factory.spec.ts +62 -0
- package/src/lib/providers/walletconnect/signers/signer-factory.ts +120 -0
- package/src/lib/providers/walletconnect/signers/xrpl-signer.spec.ts +296 -0
- package/src/lib/providers/walletconnect/signers/xrpl-signer.ts +478 -0
- package/src/lib/services/logger.service.ts +126 -0
- package/src/lib/services/transaction-builders/base-transaction-builder.service.ts +585 -0
- package/src/lib/services/transaction-builders/hedera-amount-utils.ts +84 -0
- package/src/lib/services/transaction-builders/hedera-transaction-builder.service.spec.ts +741 -0
- package/src/lib/services/transaction-builders/hedera-transaction-builder.service.ts +1285 -0
- package/src/lib/services/transaction-builders/index.ts +54 -0
- package/src/lib/services/transaction-builders/xrpl-transaction-builder.service.spec.ts +937 -0
- package/src/lib/services/transaction-builders/xrpl-transaction-builder.service.ts +832 -0
- package/src/lib/services/transaction.service.ts +346 -0
- package/src/lib/services/unified-wallet.service.spec.ts +1382 -0
- package/src/lib/services/unified-wallet.service.ts +852 -0
- package/src/lib/services/wallet-context.service.ts +184 -0
- package/src/lib/services/wallet-event-bus.service.ts +186 -0
- package/src/lib/services/wallet-providers.service.ts +137 -0
- package/src/lib/transports/chrome-extension-transport.ts +246 -0
- package/src/lib/utils/index.ts +14 -0
- package/src/lib/utils/ledger-icons.util.ts +78 -0
- package/test/test-setup.ts +21 -0
- package/test-setup.ts +63 -0
- package/tsconfig.build.json +11 -0
- package/tsconfig.json +29 -0
- package/tsconfig.spec.json +15 -0
- package/vitest.config.ts +48 -0
|
@@ -0,0 +1,178 @@
|
|
|
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
|
+
* @file minimal-connect.ts
|
|
13
|
+
* @description Minimal example of connecting to HSuite Wallet using the Angular SDK
|
|
14
|
+
*
|
|
15
|
+
* This example demonstrates the simplest way to connect to HSuite Wallet
|
|
16
|
+
* from an Angular dApp. It shows:
|
|
17
|
+
* - Injecting the UnifiedWalletService
|
|
18
|
+
* - Connecting via HSuite Native protocol
|
|
19
|
+
* - Displaying connected accounts
|
|
20
|
+
*
|
|
21
|
+
* Copy this file into your Angular component to get started quickly.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { Component, inject, effect } from '@angular/core';
|
|
25
|
+
import { UnifiedWalletService } from '@hsuite/native-connect-angular';
|
|
26
|
+
|
|
27
|
+
@Component({
|
|
28
|
+
selector: 'app-minimal-connect',
|
|
29
|
+
template: `
|
|
30
|
+
<div class="wallet-demo">
|
|
31
|
+
<h2>HSuite Wallet Connection</h2>
|
|
32
|
+
|
|
33
|
+
<!-- Connection Button -->
|
|
34
|
+
@if (!isConnected()) {
|
|
35
|
+
<button (click)="connect()">Connect to HSuite Wallet</button>
|
|
36
|
+
} @else {
|
|
37
|
+
<button (click)="disconnect()">Disconnect</button>
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
<!-- Connected Account Display -->
|
|
41
|
+
@if (activeAccount()) {
|
|
42
|
+
<div class="account-info">
|
|
43
|
+
<h3>Connected Account</h3>
|
|
44
|
+
<p><strong>Address:</strong> {{ activeAccount()?.address }}</p>
|
|
45
|
+
<p><strong>Network:</strong> {{ activeAccount()?.networkId }}</p>
|
|
46
|
+
<p><strong>Ledger:</strong> {{ activeAccount()?.ledgerId }}</p>
|
|
47
|
+
</div>
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
<!-- All Accounts -->
|
|
51
|
+
@if (allAccounts().length > 1) {
|
|
52
|
+
<div class="all-accounts">
|
|
53
|
+
<h3>All Accounts ({{ allAccounts().length }})</h3>
|
|
54
|
+
@for (account of allAccounts(); track account.address) {
|
|
55
|
+
<div class="account-item">{{ account.address }} - {{ account.networkId }}</div>
|
|
56
|
+
}
|
|
57
|
+
</div>
|
|
58
|
+
}
|
|
59
|
+
</div>
|
|
60
|
+
`,
|
|
61
|
+
styles: [
|
|
62
|
+
`
|
|
63
|
+
.wallet-demo {
|
|
64
|
+
padding: 20px;
|
|
65
|
+
max-width: 500px;
|
|
66
|
+
margin: 0 auto;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
button {
|
|
70
|
+
padding: 12px 24px;
|
|
71
|
+
font-size: 16px;
|
|
72
|
+
cursor: pointer;
|
|
73
|
+
background: var(--ion-color-primary, #3880ff);
|
|
74
|
+
color: white;
|
|
75
|
+
border: none;
|
|
76
|
+
border-radius: 8px;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
button:hover {
|
|
80
|
+
opacity: 0.9;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.account-info,
|
|
84
|
+
.all-accounts {
|
|
85
|
+
margin-top: 20px;
|
|
86
|
+
padding: 16px;
|
|
87
|
+
background: var(--ion-color-light, #f4f4f4);
|
|
88
|
+
border-radius: 8px;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.account-item {
|
|
92
|
+
padding: 8px;
|
|
93
|
+
border-bottom: 1px solid var(--ion-color-medium, #ccc);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.account-item:last-child {
|
|
97
|
+
border-bottom: none;
|
|
98
|
+
}
|
|
99
|
+
`,
|
|
100
|
+
],
|
|
101
|
+
})
|
|
102
|
+
export class MinimalConnectComponent {
|
|
103
|
+
// Inject the unified wallet service
|
|
104
|
+
private readonly wallet = inject(UnifiedWalletService);
|
|
105
|
+
|
|
106
|
+
// Expose reactive signals to template
|
|
107
|
+
readonly isConnected = this.wallet.isConnected;
|
|
108
|
+
readonly activeAccount = this.wallet.activeAccount;
|
|
109
|
+
readonly allAccounts = this.wallet.allAccounts;
|
|
110
|
+
|
|
111
|
+
constructor() {
|
|
112
|
+
// Optional: React to connection changes
|
|
113
|
+
effect(() => {
|
|
114
|
+
const connected = this.isConnected();
|
|
115
|
+
console.log('Connection status changed:', connected);
|
|
116
|
+
|
|
117
|
+
if (connected) {
|
|
118
|
+
const account = this.activeAccount();
|
|
119
|
+
console.log('Connected with account:', account?.address);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Connect to HSuite Wallet using Native protocol
|
|
126
|
+
*
|
|
127
|
+
* The wallet URL should point to your HSuite Wallet instance.
|
|
128
|
+
* For development, this is typically http://localhost:8100
|
|
129
|
+
*/
|
|
130
|
+
async connect(): Promise<void> {
|
|
131
|
+
try {
|
|
132
|
+
await this.wallet.connectNative({
|
|
133
|
+
walletUrl: 'http://localhost:8100', // Your wallet URL
|
|
134
|
+
appId: 'my-dapp', // Unique dApp identifier
|
|
135
|
+
appName: 'My dApp', // Display name
|
|
136
|
+
ledgerId: 'hedera', // Ledger: 'hedera' or 'xrpl'
|
|
137
|
+
networkId: 'hedera:testnet', // Network: testnet, mainnet, etc.
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
console.log('Connected successfully!');
|
|
141
|
+
} catch (error) {
|
|
142
|
+
console.error('Connection failed:', error);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Disconnect from wallet
|
|
148
|
+
*/
|
|
149
|
+
async disconnect(): Promise<void> {
|
|
150
|
+
try {
|
|
151
|
+
await this.wallet.disconnect();
|
|
152
|
+
console.log('Disconnected successfully!');
|
|
153
|
+
} catch (error) {
|
|
154
|
+
console.error('Disconnect failed:', error);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Module-based apps: Add to your module imports
|
|
161
|
+
*
|
|
162
|
+
* @NgModule({
|
|
163
|
+
* declarations: [MinimalConnectComponent],
|
|
164
|
+
* imports: [CommonModule]
|
|
165
|
+
* })
|
|
166
|
+
* export class MyModule {}
|
|
167
|
+
*/
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Standalone apps: Import directly
|
|
171
|
+
*
|
|
172
|
+
* @Component({
|
|
173
|
+
* standalone: true,
|
|
174
|
+
* imports: [MinimalConnectComponent],
|
|
175
|
+
* template: '<app-minimal-connect />'
|
|
176
|
+
* })
|
|
177
|
+
* export class AppComponent {}
|
|
178
|
+
*/
|
|
@@ -0,0 +1,495 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file multi-protocol.ts
|
|
3
|
+
* @description Example of using both HSuite Native and WalletConnect protocols
|
|
4
|
+
*
|
|
5
|
+
* This example demonstrates:
|
|
6
|
+
* - Connecting via HSuite Native protocol (direct, fast)
|
|
7
|
+
* - Connecting via WalletConnect v2 (QR code, interoperable)
|
|
8
|
+
* - Unified account management across protocols
|
|
9
|
+
* - Switching between connected providers
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { Component, inject, signal } from '@angular/core';
|
|
13
|
+
import { UnifiedWalletService, WalletEventBus } from '@hsuite/native-connect-angular';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Connection method selection
|
|
17
|
+
*/
|
|
18
|
+
type ConnectionMethod = 'native' | 'walletconnect' | null;
|
|
19
|
+
|
|
20
|
+
@Component({
|
|
21
|
+
selector: 'app-multi-protocol',
|
|
22
|
+
template: `
|
|
23
|
+
<div class="protocol-demo">
|
|
24
|
+
<h2>Connect to Hedera Wallet</h2>
|
|
25
|
+
|
|
26
|
+
<!-- Connection Method Selector -->
|
|
27
|
+
@if (!isConnected()) {
|
|
28
|
+
<div class="connection-options">
|
|
29
|
+
<h3>Choose Connection Method</h3>
|
|
30
|
+
|
|
31
|
+
<!-- HSuite Native Option -->
|
|
32
|
+
<button
|
|
33
|
+
class="connection-option"
|
|
34
|
+
[class.selected]="selectedMethod() === 'native'"
|
|
35
|
+
(click)="selectMethod('native')"
|
|
36
|
+
>
|
|
37
|
+
<div class="option-icon">🔗</div>
|
|
38
|
+
<div class="option-info">
|
|
39
|
+
<h4>HSuite Native</h4>
|
|
40
|
+
<p>Direct connection to HSuite Wallet</p>
|
|
41
|
+
<ul>
|
|
42
|
+
<li>✓ Fastest connection</li>
|
|
43
|
+
<li>✓ No QR code needed</li>
|
|
44
|
+
<li>✓ Browser extension support</li>
|
|
45
|
+
</ul>
|
|
46
|
+
</div>
|
|
47
|
+
</button>
|
|
48
|
+
|
|
49
|
+
<!-- WalletConnect Option -->
|
|
50
|
+
<button
|
|
51
|
+
class="connection-option"
|
|
52
|
+
[class.selected]="selectedMethod() === 'walletconnect'"
|
|
53
|
+
(click)="selectMethod('walletconnect')"
|
|
54
|
+
>
|
|
55
|
+
<div class="option-icon">📱</div>
|
|
56
|
+
<div class="option-info">
|
|
57
|
+
<h4>WalletConnect</h4>
|
|
58
|
+
<p>Connect with any WalletConnect wallet</p>
|
|
59
|
+
<ul>
|
|
60
|
+
<li>✓ Mobile wallet support</li>
|
|
61
|
+
<li>✓ HashPack, Blade, etc.</li>
|
|
62
|
+
<li>✓ QR code pairing</li>
|
|
63
|
+
</ul>
|
|
64
|
+
</div>
|
|
65
|
+
</button>
|
|
66
|
+
|
|
67
|
+
<!-- Connect Button -->
|
|
68
|
+
@if (selectedMethod()) {
|
|
69
|
+
<div class="connect-action">
|
|
70
|
+
<button class="primary" (click)="connect()" [disabled]="isConnecting()">
|
|
71
|
+
@if (isConnecting()) {
|
|
72
|
+
Connecting...
|
|
73
|
+
} @else {
|
|
74
|
+
Connect with
|
|
75
|
+
{{ selectedMethod() === 'native' ? 'HSuite Wallet' : 'WalletConnect' }}
|
|
76
|
+
}
|
|
77
|
+
</button>
|
|
78
|
+
</div>
|
|
79
|
+
}
|
|
80
|
+
</div>
|
|
81
|
+
} @else {
|
|
82
|
+
<!-- Connected State -->
|
|
83
|
+
<div class="connected-state">
|
|
84
|
+
<div class="connection-badge">
|
|
85
|
+
<span class="protocol-badge">
|
|
86
|
+
{{ activeProvider() }}
|
|
87
|
+
</span>
|
|
88
|
+
Connected
|
|
89
|
+
</div>
|
|
90
|
+
|
|
91
|
+
<!-- Active Account -->
|
|
92
|
+
<div class="account-card">
|
|
93
|
+
<h4>Active Account</h4>
|
|
94
|
+
<p class="address">{{ activeAccount()?.address }}</p>
|
|
95
|
+
<p class="network">{{ activeAccount()?.networkId }}</p>
|
|
96
|
+
</div>
|
|
97
|
+
|
|
98
|
+
<!-- Account Switcher (if multiple accounts) -->
|
|
99
|
+
@if (allAccounts().length > 1) {
|
|
100
|
+
<div class="account-switcher">
|
|
101
|
+
<h4>Switch Account</h4>
|
|
102
|
+
@for (account of allAccounts(); track account.address) {
|
|
103
|
+
<button
|
|
104
|
+
class="account-option"
|
|
105
|
+
[class.active]="account.address === activeAccount()?.address"
|
|
106
|
+
(click)="switchAccount(account.address)"
|
|
107
|
+
>
|
|
108
|
+
{{ account.address }}
|
|
109
|
+
</button>
|
|
110
|
+
}
|
|
111
|
+
</div>
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
<!-- Multiple Providers -->
|
|
115
|
+
@if (connectedProviders().length > 1) {
|
|
116
|
+
<div class="provider-switcher">
|
|
117
|
+
<h4>Connected Providers</h4>
|
|
118
|
+
@for (provider of connectedProviders(); track provider) {
|
|
119
|
+
<span class="provider-tag">{{ provider }}</span>
|
|
120
|
+
}
|
|
121
|
+
</div>
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
<button class="disconnect" (click)="disconnect()">Disconnect</button>
|
|
125
|
+
</div>
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
<!-- Events Log -->
|
|
129
|
+
<div class="events-log">
|
|
130
|
+
<h3>Recent Events</h3>
|
|
131
|
+
@for (event of recentEvents(); track $index) {
|
|
132
|
+
<div class="event-item">
|
|
133
|
+
<span class="event-type">{{ event.type }}</span>
|
|
134
|
+
<span class="event-time">{{ event.time }}</span>
|
|
135
|
+
</div>
|
|
136
|
+
} @empty {
|
|
137
|
+
<p class="no-events">No events yet</p>
|
|
138
|
+
}
|
|
139
|
+
</div>
|
|
140
|
+
</div>
|
|
141
|
+
`,
|
|
142
|
+
styles: [
|
|
143
|
+
`
|
|
144
|
+
.protocol-demo {
|
|
145
|
+
padding: 20px;
|
|
146
|
+
max-width: 600px;
|
|
147
|
+
margin: 0 auto;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
.connection-options {
|
|
151
|
+
margin-top: 20px;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
.connection-option {
|
|
155
|
+
display: flex;
|
|
156
|
+
align-items: flex-start;
|
|
157
|
+
gap: 16px;
|
|
158
|
+
width: 100%;
|
|
159
|
+
padding: 16px;
|
|
160
|
+
margin-bottom: 12px;
|
|
161
|
+
background: var(--ion-color-light, #f4f4f4);
|
|
162
|
+
border: 2px solid transparent;
|
|
163
|
+
border-radius: 12px;
|
|
164
|
+
text-align: left;
|
|
165
|
+
cursor: pointer;
|
|
166
|
+
transition: all 0.2s;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.connection-option:hover {
|
|
170
|
+
background: var(--ion-color-light-shade, #e8e8e8);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
.connection-option.selected {
|
|
174
|
+
border-color: var(--ion-color-primary, #3880ff);
|
|
175
|
+
background: var(--ion-color-primary-tint, #e8f0ff);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
.option-icon {
|
|
179
|
+
font-size: 32px;
|
|
180
|
+
line-height: 1;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
.option-info h4 {
|
|
184
|
+
margin: 0 0 4px;
|
|
185
|
+
font-size: 18px;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
.option-info p {
|
|
189
|
+
margin: 0 0 8px;
|
|
190
|
+
color: var(--ion-color-medium, #666);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
.option-info ul {
|
|
194
|
+
margin: 0;
|
|
195
|
+
padding: 0;
|
|
196
|
+
list-style: none;
|
|
197
|
+
font-size: 14px;
|
|
198
|
+
color: var(--ion-color-medium, #666);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
.option-info li {
|
|
202
|
+
margin: 2px 0;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
.connect-action {
|
|
206
|
+
margin-top: 20px;
|
|
207
|
+
text-align: center;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
button.primary {
|
|
211
|
+
padding: 16px 32px;
|
|
212
|
+
font-size: 18px;
|
|
213
|
+
background: var(--ion-color-primary, #3880ff);
|
|
214
|
+
color: white;
|
|
215
|
+
border: none;
|
|
216
|
+
border-radius: 8px;
|
|
217
|
+
cursor: pointer;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
button.primary:disabled {
|
|
221
|
+
opacity: 0.6;
|
|
222
|
+
cursor: not-allowed;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
.connected-state {
|
|
226
|
+
margin-top: 20px;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
.connection-badge {
|
|
230
|
+
display: flex;
|
|
231
|
+
align-items: center;
|
|
232
|
+
gap: 8px;
|
|
233
|
+
font-size: 18px;
|
|
234
|
+
margin-bottom: 16px;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
.protocol-badge {
|
|
238
|
+
padding: 4px 12px;
|
|
239
|
+
background: var(--ion-color-success, green);
|
|
240
|
+
color: white;
|
|
241
|
+
border-radius: 4px;
|
|
242
|
+
font-size: 12px;
|
|
243
|
+
text-transform: uppercase;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
.account-card {
|
|
247
|
+
padding: 16px;
|
|
248
|
+
background: var(--ion-color-light, #f4f4f4);
|
|
249
|
+
border-radius: 12px;
|
|
250
|
+
margin-bottom: 16px;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
.account-card h4 {
|
|
254
|
+
margin: 0 0 8px;
|
|
255
|
+
font-size: 14px;
|
|
256
|
+
color: var(--ion-color-medium, #666);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
.account-card .address {
|
|
260
|
+
margin: 0;
|
|
261
|
+
font-family: monospace;
|
|
262
|
+
font-size: 16px;
|
|
263
|
+
word-break: break-all;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
.account-card .network {
|
|
267
|
+
margin: 4px 0 0;
|
|
268
|
+
font-size: 14px;
|
|
269
|
+
color: var(--ion-color-medium, #666);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
.account-switcher,
|
|
273
|
+
.provider-switcher {
|
|
274
|
+
margin-bottom: 16px;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
.account-option {
|
|
278
|
+
display: block;
|
|
279
|
+
width: 100%;
|
|
280
|
+
padding: 12px;
|
|
281
|
+
margin-bottom: 8px;
|
|
282
|
+
background: var(--ion-color-light, #f4f4f4);
|
|
283
|
+
border: 1px solid transparent;
|
|
284
|
+
border-radius: 8px;
|
|
285
|
+
text-align: left;
|
|
286
|
+
font-family: monospace;
|
|
287
|
+
cursor: pointer;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
.account-option.active {
|
|
291
|
+
border-color: var(--ion-color-primary, #3880ff);
|
|
292
|
+
background: var(--ion-color-primary-tint, #e8f0ff);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
.provider-tag {
|
|
296
|
+
display: inline-block;
|
|
297
|
+
padding: 4px 12px;
|
|
298
|
+
margin-right: 8px;
|
|
299
|
+
background: var(--ion-color-tertiary, #7044ff);
|
|
300
|
+
color: white;
|
|
301
|
+
border-radius: 16px;
|
|
302
|
+
font-size: 12px;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
button.disconnect {
|
|
306
|
+
width: 100%;
|
|
307
|
+
padding: 12px;
|
|
308
|
+
background: var(--ion-color-danger, #eb445a);
|
|
309
|
+
color: white;
|
|
310
|
+
border: none;
|
|
311
|
+
border-radius: 8px;
|
|
312
|
+
cursor: pointer;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
.events-log {
|
|
316
|
+
margin-top: 24px;
|
|
317
|
+
padding: 16px;
|
|
318
|
+
background: var(--ion-color-dark, #222);
|
|
319
|
+
color: var(--ion-color-light, #fff);
|
|
320
|
+
border-radius: 8px;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
.events-log h3 {
|
|
324
|
+
margin: 0 0 12px;
|
|
325
|
+
font-size: 14px;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
.event-item {
|
|
329
|
+
display: flex;
|
|
330
|
+
justify-content: space-between;
|
|
331
|
+
padding: 4px 0;
|
|
332
|
+
font-size: 12px;
|
|
333
|
+
font-family: monospace;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
.event-type {
|
|
337
|
+
color: var(--ion-color-success, #2dd36f);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
.event-time {
|
|
341
|
+
color: var(--ion-color-medium, #92949c);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
.no-events {
|
|
345
|
+
color: var(--ion-color-medium, #92949c);
|
|
346
|
+
font-size: 12px;
|
|
347
|
+
}
|
|
348
|
+
`,
|
|
349
|
+
],
|
|
350
|
+
})
|
|
351
|
+
export class MultiProtocolComponent {
|
|
352
|
+
private readonly wallet = inject(UnifiedWalletService);
|
|
353
|
+
private readonly eventBus = inject(WalletEventBus);
|
|
354
|
+
|
|
355
|
+
// UI State
|
|
356
|
+
readonly selectedMethod = signal<ConnectionMethod>(null);
|
|
357
|
+
readonly isConnecting = signal(false);
|
|
358
|
+
readonly recentEvents = signal<Array<{ type: string; time: string }>>([]);
|
|
359
|
+
|
|
360
|
+
// Wallet State
|
|
361
|
+
readonly isConnected = this.wallet.isConnected;
|
|
362
|
+
readonly activeAccount = this.wallet.activeAccount;
|
|
363
|
+
readonly allAccounts = this.wallet.allAccounts;
|
|
364
|
+
readonly connectedProviders = this.wallet.connectedProviders;
|
|
365
|
+
readonly activeProvider = this.wallet.activeProvider;
|
|
366
|
+
|
|
367
|
+
constructor() {
|
|
368
|
+
// Subscribe to wallet events for logging
|
|
369
|
+
this.subscribeToEvents();
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Subscribe to wallet events
|
|
374
|
+
*/
|
|
375
|
+
private subscribeToEvents(): void {
|
|
376
|
+
this.eventBus.connected.subscribe((_event) => {
|
|
377
|
+
this.addEvent('connected');
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
this.eventBus.disconnected.subscribe((_event) => {
|
|
381
|
+
this.addEvent('disconnected');
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
this.eventBus.accountChanged.subscribe((_event) => {
|
|
385
|
+
this.addEvent('account_changed');
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
this.eventBus.sessionCreated.subscribe((_event) => {
|
|
389
|
+
this.addEvent('session_created');
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Add event to log
|
|
395
|
+
*/
|
|
396
|
+
private addEvent(type: string): void {
|
|
397
|
+
const time = new Date().toLocaleTimeString();
|
|
398
|
+
this.recentEvents.update((events) => [{ type, time }, ...events.slice(0, 9)]);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Select connection method
|
|
403
|
+
*/
|
|
404
|
+
selectMethod(method: ConnectionMethod): void {
|
|
405
|
+
this.selectedMethod.set(method);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Connect using selected method
|
|
410
|
+
*/
|
|
411
|
+
async connect(): Promise<void> {
|
|
412
|
+
const method = this.selectedMethod();
|
|
413
|
+
if (!method) return;
|
|
414
|
+
|
|
415
|
+
this.isConnecting.set(true);
|
|
416
|
+
|
|
417
|
+
try {
|
|
418
|
+
if (method === 'native') {
|
|
419
|
+
// HSuite Native Connection
|
|
420
|
+
await this.wallet.connectNative({
|
|
421
|
+
walletUrl: 'http://localhost:8100',
|
|
422
|
+
appId: 'multi-protocol-demo',
|
|
423
|
+
appName: 'Multi-Protocol Demo',
|
|
424
|
+
ledgerId: 'hedera',
|
|
425
|
+
networkId: 'hedera:testnet',
|
|
426
|
+
});
|
|
427
|
+
} else {
|
|
428
|
+
// WalletConnect Connection
|
|
429
|
+
await this.wallet.connectWalletConnect({
|
|
430
|
+
projectId: 'YOUR_WALLETCONNECT_PROJECT_ID', // Get from cloud.walletconnect.com
|
|
431
|
+
ledgerId: 'hedera',
|
|
432
|
+
networkId: 'hedera:testnet',
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
this.addEvent(`connected_${method}`);
|
|
437
|
+
} catch (error) {
|
|
438
|
+
console.error('Connection failed:', error);
|
|
439
|
+
this.addEvent('connection_error');
|
|
440
|
+
} finally {
|
|
441
|
+
this.isConnecting.set(false);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Switch active account
|
|
447
|
+
*/
|
|
448
|
+
switchAccount(address: string): void {
|
|
449
|
+
const account = this.allAccounts().find((a) => a.address === address);
|
|
450
|
+
if (account) {
|
|
451
|
+
this.wallet.setActiveAccount(account);
|
|
452
|
+
this.addEvent('account_switched');
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Disconnect from wallet
|
|
458
|
+
*/
|
|
459
|
+
async disconnect(): Promise<void> {
|
|
460
|
+
await this.wallet.disconnect();
|
|
461
|
+
this.selectedMethod.set(null);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* Configuration for WalletConnect:
|
|
467
|
+
*
|
|
468
|
+
* 1. Get a Project ID from https://cloud.walletconnect.com
|
|
469
|
+
* 2. Add your dApp metadata (name, description, url, icons)
|
|
470
|
+
* 3. Configure supported chains (hedera, xrpl)
|
|
471
|
+
*
|
|
472
|
+
* Example environment.ts:
|
|
473
|
+
*
|
|
474
|
+
* export const environment = {
|
|
475
|
+
* walletConnectProjectId: 'abc123...',
|
|
476
|
+
* walletConnectMetadata: {
|
|
477
|
+
* name: 'My dApp',
|
|
478
|
+
* description: 'A cool Hedera dApp',
|
|
479
|
+
* url: 'https://mydapp.com',
|
|
480
|
+
* icons: ['https://mydapp.com/icon.png']
|
|
481
|
+
* }
|
|
482
|
+
* };
|
|
483
|
+
*/
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Provider Types:
|
|
487
|
+
*
|
|
488
|
+
* - 'hsuite-native': Direct connection to HSuite Wallet
|
|
489
|
+
* - 'walletconnect-v2': WalletConnect v2 protocol
|
|
490
|
+
*
|
|
491
|
+
* The UnifiedWalletService manages both providers and provides:
|
|
492
|
+
* - Unified account list from all providers
|
|
493
|
+
* - Single active account selection
|
|
494
|
+
* - Provider-agnostic signing
|
|
495
|
+
*/
|