Skip to content

Commit

Permalink
fix: modal not updating (#181)
Browse files Browse the repository at this point in the history
* fix: modal not updating

* chore: add code coverage
  • Loading branch information
darrenvechain authored Jan 23, 2024
1 parent d3f4208 commit 251e8d5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
21 changes: 18 additions & 3 deletions packages/dapp-kit-ui/src/components/modals/modal.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
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,
type I18n,
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();
});
}
Expand Down Expand Up @@ -45,6 +56,10 @@ export class Modal extends LitElement {
};

override render(): TemplateResult {
if (!DAppKitUI.initialized) {
return html``;
}

return html`
<div>
${this.address
Expand Down
21 changes: 21 additions & 0 deletions packages/dapp-kit-ui/test/classes/connect-modal-manager.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ConnectModalManager, DAppKitUI } from '../../src';

DAppKitUI.configure({
nodeUrl: 'https://mainnet.vechain.org/',
});

describe('ConnectModalManager', () => {
it('should be a singleton', () => {
const instance1 = ConnectModalManager.getInstance(DAppKitUI.wallet);
const instance2 = ConnectModalManager.getInstance(DAppKitUI.wallet);
expect(instance1).toBe(instance2);
});

it('should not throw', () => {
const instance = ConnectModalManager.getInstance(DAppKitUI.wallet);
instance.open();
instance.close();
instance.closeWalletConnect();
instance.closeConnectionCertificateRequest();
});
});

0 comments on commit 251e8d5

Please sign in to comment.