Skip to content

Commit

Permalink
feat: display the number of connected accounts for each wallet (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
tien authored Aug 8, 2024
1 parent c58758d commit 966b35b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/cuddly-bananas-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"dot-connect": minor
---

Display the number of connected accounts for each wallet.
36 changes: 31 additions & 5 deletions packages/dot-connect/src/elements/dc-connection-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ import {
disconnected as disconnectedIcon,
download as downloadIcon,
qrCode as qrCodeIcon,
users as usersIcon,
wallet as walletIcon,
} from "../icons/index.js";
import { observableSignal } from "../observable-signal.js";
import { connectedWallets$, walletConfigs, wallets$ } from "../stores.js";
import {
accounts$,
connectedWallets$,
walletConfigs,
wallets$,
} from "../stores.js";
import type { SupportedWallet } from "../types.js";
import { getDownloadUrl } from "../utils.js";
import type { InjectedWalletInfo, WalletConfig } from "../wallets/types.js";
Expand Down Expand Up @@ -35,6 +41,13 @@ export class InjectedWalletConnection extends DotConnectElement {
color: var(--error-color);
}
}
.icon {
display: contents;
> * {
vertical-align: -0.125em;
}
}
`,
];

Expand All @@ -47,6 +60,14 @@ export class InjectedWalletConnection extends DotConnectElement {

readonly #connectedWallets = observableSignal(this, connectedWallets$, []);

readonly #connectedAccounts = observableSignal(this, accounts$, []);

readonly #accounts = computed(() =>
this.#connectedAccounts.value.filter(
(account) => account.wallet === this.wallet,
),
);

readonly #connected = computed(() =>
this.#connectedWallets.value.includes(this.wallet),
);
Expand All @@ -64,9 +85,11 @@ export class InjectedWalletConnection extends DotConnectElement {
try {
this.#pending.value = true;
this.#connected.value
? await disconnectWallet(this.wallet)
: await connectWallet(this.wallet);
if (this.#connected.value) {
await disconnectWallet(this.wallet);
} else {
await connectWallet(this.wallet);
}
} finally {
this.#pending.value = false;
}
Expand All @@ -81,7 +104,10 @@ export class InjectedWalletConnection extends DotConnectElement {
id="connection-status"
slot="supporting"
class=${classMap({ connected: this.#connected.value })}
>${this.#connected.value ? "Connected" : "Not connected"}</span
>${this.#connected.value
? html`Connected | ${this.#accounts.value.length}
<span class="icon">${usersIcon({ size: "1em" })}</span>`
: "Not connected"}</span
>
<div
id="hover-icon"
Expand Down

0 comments on commit 966b35b

Please sign in to comment.