Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix button configuration in next #182

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions packages/dapp-kit-ui/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CustomWalletConnectModal, ConnectModalManager } from './classes';
import {
type CustomizedStyle,
dispatchCustomEvent,
configureUI,
initModalsAndButtons,
} from './utils';
import type { SourceInfo, I18n, ThemeMode } from './constants';

Expand Down Expand Up @@ -40,14 +40,20 @@ export const DAppKitUI = {
});

// configure bottons and modals options
configureUI(options);
initModalsAndButtons(options);
dispatchCustomEvent('vdk-dapp-kit-configured');

initialized = true;

return dappKit;
},

configureButtonsAndModals(): void {
if (dappKitOptions) {
initModalsAndButtons(dappKitOptions);
}
},

get initialized(): boolean {
return initialized;
},
Expand Down
9 changes: 4 additions & 5 deletions packages/dapp-kit-ui/src/components/buttons/button.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { html, LitElement, type TemplateResult } 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 ThemeMode } from '../../constants';
Expand All @@ -13,6 +12,10 @@ export class Button extends LitElement {
if (DAppKitUI.initialized) {
this.address = DAppKitUI.wallet.state.address ?? '';
this.initAddressListener();
setTimeout(() => {
DAppKitUI.configureButtonsAndModals();
this.requestUpdate();
}, 0);
} else {
subscribeToCustomEvent('vdk-dapp-kit-configured', () => {
this.address = DAppKitUI.wallet.state.address ?? '';
Expand All @@ -28,10 +31,6 @@ export class Button extends LitElement {
});
}

private get wallet(): WalletManager {
return DAppKitUI.wallet;
}

@property()
mode: ThemeMode = 'LIGHT';

Expand Down
15 changes: 5 additions & 10 deletions packages/dapp-kit-ui/src/utils/ui-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ export const initStyles = (customizedStyle: CustomizedStyle): void => {
};

export const initModalsAndButtons = (options: DAppKitUIOptions): void => {
// configure theme variables
if (options.themeVariables) {
initStyles(options.themeVariables);
}

const button = document.querySelector('vdk-button');
const modal = document.querySelector('vdk-modal');

Expand All @@ -86,13 +91,3 @@ export const initModalsAndButtons = (options: DAppKitUIOptions): void => {
modal.onSourceClick = options.onSourceClick;
}
};

export const configureUI = (options: DAppKitUIOptions): void => {
// init buttons and modals
initModalsAndButtons(options);

// configure theme variables
if (options.themeVariables) {
initStyles(options.themeVariables);
}
};
Loading