Skip to content

Commit

Permalink
feat: auto select veworld if in-app-browser
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenvechain committed Feb 15, 2024
1 parent 2f7cfd0 commit db9a0ac
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
21 changes: 19 additions & 2 deletions packages/dapp-kit-ui/src/components/buttons/connect-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion packages/dapp-kit/src/classes/wallet-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/dapp-kit/src/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ declare global {
interface Window {
vechain?: {
newConnexSigner: (genesisId: string) => Connex.Signer;
isInAppBrowser?: boolean;
};
connex?: unknown;
}
Expand Down

0 comments on commit db9a0ac

Please sign in to comment.