From 2c7372a1d0198a0b1503ef477f9a58c87c54c38a Mon Sep 17 00:00:00 2001 From: Darren Kelly Date: Tue, 23 Jan 2024 15:33:43 +0000 Subject: [PATCH 1/3] fix: modal not updating --- .../src/components/modals/modal.ts | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/dapp-kit-ui/src/components/modals/modal.ts b/packages/dapp-kit-ui/src/components/modals/modal.ts index 6f1dd0f5..b56fe73c 100644 --- a/packages/dapp-kit-ui/src/components/modals/modal.ts +++ b/packages/dapp-kit-ui/src/components/modals/modal.ts @@ -1,7 +1,6 @@ import { html, LitElement, type TemplateResult, nothing } from 'lit'; import { customElement, property } from 'lit/decorators.js'; import { type WalletManager } from '@vechain/dapp-kit'; -import { subscribeKey } from 'valtio/vanilla/utils'; import { DAppKitUI } from '../../client'; import { defaultI18n, @@ -9,13 +8,25 @@ import { type SourceInfo, type ThemeMode, } from '../../constants'; +import { subscribeToCustomEvent } from '../../utils'; @customElement('vdk-modal') export class Modal extends LitElement { constructor() { super(); - subscribeKey(DAppKitUI.wallet.state, 'address', (v) => { - this.address = v ?? ''; + if (DAppKitUI.initialized) { + this.init(); + } else { + subscribeToCustomEvent('vdk-dapp-kit-configured', () => { + this.init(); + }); + } + } + + private init(): void { + this.address = DAppKitUI.wallet.state.address ?? ''; + this.wallet.subscribeToKey('address', (addr) => { + this.address = addr ?? ''; this.requestUpdate(); }); } @@ -45,6 +56,10 @@ export class Modal extends LitElement { }; override render(): TemplateResult { + if (!DAppKitUI.initialized) { + return html``; + } + return html`
${this.address From b49736773c4430418627340294d0cff5fb7e3bb8 Mon Sep 17 00:00:00 2001 From: Darren Kelly Date: Tue, 23 Jan 2024 15:53:41 +0000 Subject: [PATCH 2/3] chore: add code coverage --- .../src/app/pages/homepage.tsx | 12 +++++++++++ packages/dapp-kit-ui/src/client.ts | 15 ++++++++++--- .../src/components/buttons/button.ts | 14 ++++++++----- .../classes/connect-modal-manager.test.ts | 21 +++++++++++++++++++ 4 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 packages/dapp-kit-ui/test/classes/connect-modal-manager.test.ts diff --git a/examples/sample-next-app/src/app/pages/homepage.tsx b/examples/sample-next-app/src/app/pages/homepage.tsx index 894c7776..634786b9 100644 --- a/examples/sample-next-app/src/app/pages/homepage.tsx +++ b/examples/sample-next-app/src/app/pages/homepage.tsx @@ -60,13 +60,25 @@ const walletConnectOptions: WalletConnectOptions = { }; const HomePage = (): ReactElement => { + const [theme, setTheme] = useState<'DARK' | 'LIGHT'>('DARK'); + + const toggleTheme = () => { + if (theme === 'DARK') { + setTheme('LIGHT'); + } else { + setTheme('DARK'); + } + }; + return ( +