From db9a0ac808b6eac0f8f0855c28364fe0b7ef0b41 Mon Sep 17 00:00:00 2001 From: Darren Kelly Date: Thu, 15 Feb 2024 15:56:27 +0000 Subject: [PATCH] feat: auto select veworld if in-app-browser --- .../src/components/buttons/connect-button.ts | 21 +++++++++++++++++-- .../dapp-kit/src/classes/wallet-manager.ts | 4 +++- packages/dapp-kit/src/types/types.d.ts | 1 + 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/packages/dapp-kit-ui/src/components/buttons/connect-button.ts b/packages/dapp-kit-ui/src/components/buttons/connect-button.ts index 46bd6c6b..87faeb65 100644 --- a/packages/dapp-kit-ui/src/components/buttons/connect-button.ts +++ b/packages/dapp-kit-ui/src/components/buttons/connect-button.ts @@ -7,6 +7,7 @@ import { defaultI18n, type I18n } from '../../constants'; import { useTranslate } from '../../utils'; import { DAppKitUI } from '../../client'; import { DarkLinkSvg, LightLinkSvg } from '../../assets/icons'; +import { DAppKitLogger } from '@vechain/dapp-kit'; @customElement('vdk-connect-button') export class ConnectButton extends LitElement { @@ -34,8 +35,24 @@ export class ConnectButton extends LitElement { @property() handleOpen = (): void => { - DAppKitUI.wallet.disconnect(); - DAppKitUI.modal.open(); + if (window.vechain?.isInAppBrowser) { + DAppKitUI.wallet.setSource('veworld'); + DAppKitUI.wallet + .connect() + .then(() => { + this.requestUpdate(); + }) + .catch((err): void => { + DAppKitLogger.error( + 'Connection Attempt', + 'error trying to connect', + err, + ); + }); + } else { + DAppKitUI.wallet.disconnect(); + DAppKitUI.modal.open(); + } }; @property() diff --git a/packages/dapp-kit/src/classes/wallet-manager.ts b/packages/dapp-kit/src/classes/wallet-manager.ts index 674ae52c..c7a38d98 100644 --- a/packages/dapp-kit/src/classes/wallet-manager.ts +++ b/packages/dapp-kit/src/classes/wallet-manager.ts @@ -20,7 +20,9 @@ class WalletManager { this.initPersistence(options.usePersistence ?? false); DAppKitLogger.debug('WalletManager', 'constructor', this.state); - if (options.useFirstDetectedSource) { + if (window.vechain?.isInAppBrowser === true) { + this.setSource('veworld'); + } else if (options.useFirstDetectedSource) { this.setFirstDetectedSource(); } } diff --git a/packages/dapp-kit/src/types/types.d.ts b/packages/dapp-kit/src/types/types.d.ts index eaf997b9..641da6f2 100644 --- a/packages/dapp-kit/src/types/types.d.ts +++ b/packages/dapp-kit/src/types/types.d.ts @@ -6,6 +6,7 @@ declare global { interface Window { vechain?: { newConnexSigner: (genesisId: string) => Connex.Signer; + isInAppBrowser?: boolean; }; connex?: unknown; }