Skip to content

Commit

Permalink
Carpini fix connect button bugs (#201)
Browse files Browse the repository at this point in the history
* fix: link icon

* fix: connection button
  • Loading branch information
davidecarpini authored Feb 24, 2024
1 parent 9d7729f commit 4d85d2b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
23 changes: 17 additions & 6 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 { subscribeKey } from 'valtio/vanilla/utils';
import { DAppKitUI } from '../../client';
import { defaultI18n, type I18n, type ThemeMode } from '../../constants';
import { subscribeToCustomEvent } from '../../utils';
Expand All @@ -9,10 +8,17 @@ import { subscribeToCustomEvent } from '../../utils';
export class Button extends LitElement {
constructor() {
super();

if (DAppKitUI.initialized) {
this.initAddressListener();
this.setAddressFromState();
this.configureButtonUI();
this.initAddressListener();

// this subscribeToCustomEvent need to be done if the DappKitUI button is reconfigured and so recreated after the initial configuration
subscribeToCustomEvent('vdk-dapp-kit-configured', () => {
this.setAddressFromState();
this.initAddressListener();
});
} else {
subscribeToCustomEvent('vdk-dapp-kit-configured', () => {
this.setAddressFromState();
Expand All @@ -23,19 +29,24 @@ export class Button extends LitElement {

private setAddressFromState(): void {
this.address = DAppKitUI.wallet.state.address ?? '';
this.requestUpdate();
}

private configureButtonUI(): void {
this.mode = DAppKitUI.configuration?.themeMode ?? 'LIGHT';
this.i18n = DAppKitUI.configuration?.i18n ?? defaultI18n;
this.language = DAppKitUI.configuration?.language ?? 'en';
this.requestUpdate();
}

private initAddressListener(): void {
subscribeKey(DAppKitUI.wallet.state, 'address', (v) => {
this.address = v ?? '';
this.requestUpdate();
});
DAppKitUI.wallet.subscribeToKey(
'address',
(_address: string | null) => {
this.address = _address ?? '';
this.requestUpdate();
},
);
}

@property()
Expand Down
11 changes: 10 additions & 1 deletion packages/dapp-kit-ui/src/components/buttons/connect-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ export class ConnectButton extends LitElement {
button.mobile {
height: 41px;
width: 41px;
padding: 0;
display: flex;
align-items: center;
justify-content: center;
}
.icon {
padding-top: 4px;
width: 18px;
height: 18px;
}
`,
];
Expand Down Expand Up @@ -55,7 +64,7 @@ export class ConnectButton extends LitElement {
@click=${this.handleOpen}
?disabled=${this.disabled}
>
${connectIcon}
<div class="icon">${connectIcon}</div>
</button>`;
}

Expand Down

0 comments on commit 4d85d2b

Please sign in to comment.