From 2f7cfd02f7a4692e35b56afcb05e8ed9cb2946d5 Mon Sep 17 00:00:00 2001 From: Davide Carpini Date: Mon, 12 Feb 2024 16:47:54 +0100 Subject: [PATCH] fix: deep linking for veworld extension (#195) * fix: deep linking for veworld extension * fix: tests * chore: increase version --- packages/dapp-kit-react/package.json | 2 +- packages/dapp-kit-ui/package.json | 2 +- .../modals/connect-modal/connect-modal.ts | 9 ++++++++ packages/dapp-kit-ui/src/constants/index.ts | 1 + packages/dapp-kit-ui/src/constants/veworld.ts | 1 + packages/dapp-kit/package.json | 2 +- .../dapp-kit/src/classes/wallet-manager.ts | 4 +--- .../dapp-kit/test/wallet-tests/sync.test.ts | 2 +- .../wallet-tests/veworld-extension.test.ts | 22 ------------------- 9 files changed, 16 insertions(+), 29 deletions(-) create mode 100644 packages/dapp-kit-ui/src/constants/veworld.ts diff --git a/packages/dapp-kit-react/package.json b/packages/dapp-kit-react/package.json index 79f524de..873bdf34 100644 --- a/packages/dapp-kit-react/package.json +++ b/packages/dapp-kit-react/package.json @@ -1,6 +1,6 @@ { "name": "@vechain/dapp-kit-react", - "version": "1.0.6", + "version": "1.0.7", "private": false, "homepage": "https://github.com/vechainfoundation/vechain-dapp-kit", "repository": "github:vechain/vechain-dapp-kit", diff --git a/packages/dapp-kit-ui/package.json b/packages/dapp-kit-ui/package.json index c039f426..4db1207f 100644 --- a/packages/dapp-kit-ui/package.json +++ b/packages/dapp-kit-ui/package.json @@ -1,6 +1,6 @@ { "name": "@vechain/dapp-kit-ui", - "version": "1.0.6", + "version": "1.0.7", "private": false, "description": "Vanilla JS DAppKit", "keywords": [ diff --git a/packages/dapp-kit-ui/src/components/modals/connect-modal/connect-modal.ts b/packages/dapp-kit-ui/src/components/modals/connect-modal/connect-modal.ts index 846eab5e..6bb7187b 100644 --- a/packages/dapp-kit-ui/src/components/modals/connect-modal/connect-modal.ts +++ b/packages/dapp-kit-ui/src/components/modals/connect-modal/connect-modal.ts @@ -9,6 +9,7 @@ import { defaultI18n, Font, WalletSources, + VEWORLD_WEBSITE, } from '../../../constants'; import { DarkChevronLeftSvg, @@ -97,6 +98,14 @@ export class ConnectModal extends LitElement { @property({ type: Function }) onSourceClick = (source?: SourceInfo): void => { if (source) { + if (source.id === 'veworld' && !window.vechain) { + const path = `${location.host}${location.pathname}${location.search}`; + window.open( + `${VEWORLD_WEBSITE}/?discoveryUrl=${path}`, + '_self', + ); + return; + } if (source.id !== 'wallet-connect') { this.setWaitingForTheSignature(true); this.requestForConnectionCertificate = true; diff --git a/packages/dapp-kit-ui/src/constants/index.ts b/packages/dapp-kit-ui/src/constants/index.ts index 7389832e..e8337817 100644 --- a/packages/dapp-kit-ui/src/constants/index.ts +++ b/packages/dapp-kit-ui/src/constants/index.ts @@ -6,3 +6,4 @@ export * from './stores'; export * from './font'; export * from './i18n'; export * from './z-index'; +export * from './veworld'; diff --git a/packages/dapp-kit-ui/src/constants/veworld.ts b/packages/dapp-kit-ui/src/constants/veworld.ts new file mode 100644 index 00000000..6676ad83 --- /dev/null +++ b/packages/dapp-kit-ui/src/constants/veworld.ts @@ -0,0 +1 @@ +export const VEWORLD_WEBSITE = 'https://veworld.com'; diff --git a/packages/dapp-kit/package.json b/packages/dapp-kit/package.json index 2a4d1c07..cb00fe17 100644 --- a/packages/dapp-kit/package.json +++ b/packages/dapp-kit/package.json @@ -1,6 +1,6 @@ { "name": "@vechain/dapp-kit", - "version": "1.0.6", + "version": "1.0.7", "private": false, "homepage": "https://github.com/vechainfoundation/vechain-dapp-kit", "repository": "github:vechain/vechain-dapp-kit", diff --git a/packages/dapp-kit/src/classes/wallet-manager.ts b/packages/dapp-kit/src/classes/wallet-manager.ts index 622df128..674ae52c 100644 --- a/packages/dapp-kit/src/classes/wallet-manager.ts +++ b/packages/dapp-kit/src/classes/wallet-manager.ts @@ -275,9 +275,7 @@ class WalletManager { private getAvailableSources = (): WalletSource[] => { const wallets: WalletSource[] = []; - if (window.vechain) { - wallets.push('veworld'); - } + wallets.push('veworld'); if (this.options.walletConnectOptions) { wallets.push('wallet-connect'); diff --git a/packages/dapp-kit/test/wallet-tests/sync.test.ts b/packages/dapp-kit/test/wallet-tests/sync.test.ts index 10457d08..5d9709a7 100644 --- a/packages/dapp-kit/test/wallet-tests/sync.test.ts +++ b/packages/dapp-kit/test/wallet-tests/sync.test.ts @@ -82,7 +82,7 @@ describe('sync', () => { ); }); - it('get available sources - should not include veworld', () => { + it('get available sources - should not include sync', () => { const connex = createUnitTestConnex(); const sources = connex.wallet.state.availableSources; diff --git a/packages/dapp-kit/test/wallet-tests/veworld-extension.test.ts b/packages/dapp-kit/test/wallet-tests/veworld-extension.test.ts index f9d0293d..75b68aff 100644 --- a/packages/dapp-kit/test/wallet-tests/veworld-extension.test.ts +++ b/packages/dapp-kit/test/wallet-tests/veworld-extension.test.ts @@ -40,26 +40,4 @@ describe('veworld', () => { expect(sources).toContain('veworld'); }); }); - - describe('is NOT in veworld browser', () => { - beforeEach(() => { - window.vechain = undefined; - }); - - it('not installed - should throw error', () => { - const connex = createUnitTestConnex(); - - expect(() => connex.wallet.setSource('veworld')).toThrowError( - 'VeWorld Extension is not installed', - ); - }); - - it('get available sources - should not include veworld', () => { - const connex = createUnitTestConnex(); - - const sources = connex.wallet.state.availableSources; - - expect(sources).not.toContain('veworld'); - }); - }); });