Skip to content

Commit

Permalink
Handle uninstalled wallets
Browse files Browse the repository at this point in the history
  • Loading branch information
aryzing committed Mar 20, 2024
1 parent 88c6c58 commit 31595ab
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
21 changes: 13 additions & 8 deletions src/lib/WalletOption.tsx → src/lib/ProviderOption.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { createSignal } from "solid-js";

interface Props {
name: string;
icon: string;
onWalletSelected: (wallet: string) => void;
import { ProviderOption } from "./utils";

interface Props extends ProviderOption {
onWalletSelected: (walletId: string) => void;
}

export function WalletOption(props: Props) {
function handleWalletSelected(wallet: string) {
props.onWalletSelected(wallet);
function handleWalletSelected(walletId: string) {
if (props.installPrompt) {
window.open(props.installPrompt.url, "_blank");
return;
}

props.onWalletSelected(walletId);
}

const [isMouseOver, setIsMouseOver] = createSignal(false);
Expand All @@ -21,7 +26,7 @@ export function WalletOption(props: Props) {

return (
<div
role="button"
role={props.installPrompt ? "link" : "button"}
tabIndex={0}
style={{
display: "flex",
Expand All @@ -32,7 +37,7 @@ export function WalletOption(props: Props) {
outline: "none",
"padding-top": "10px",
}}
onClick={[handleWalletSelected, props.name]}
onClick={[handleWalletSelected, props.id]}
onMouseEnter={() => setIsMouseOver(true)}
onMouseLeave={() => setIsMouseOver(false)}
onFocus={() => setIsFocused(true)}
Expand Down
9 changes: 4 additions & 5 deletions src/lib/Selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Dialog } from "@ark-ui/solid";
import { For, Show, batch, createSignal, onCleanup, onMount } from "solid-js";

import { CssReset } from "./CssReset";
import { WalletOption } from "./WalletOption";
import { WalletOption } from "./ProviderOption";
import { XCircle } from "./XCircle";
import { ProviderOption } from "./utils";

Expand All @@ -22,9 +22,9 @@ export function WalletSelector() {
triggerFadeOut();
}

function handleWalletSelected(wallet: string) {
function handleWalletSelected(walletId: string) {
const event = new CustomEvent("sats-connect_wallet-selector_select", {
detail: wallet,
detail: walletId,
bubbles: true,
composed: true,
});
Expand Down Expand Up @@ -208,9 +208,8 @@ export function WalletSelector() {
<For each={providers()}>
{(provider) => (
<WalletOption
{...provider}
onWalletSelected={handleWalletSelected}
name={provider.name}
icon={provider.icon}
/>
)}
</For>
Expand Down
5 changes: 5 additions & 0 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@ export function cleanup() {
}
}

export interface InstallPrompt {
url: string;
}

export interface ProviderOption {
name: string;
id: string;
icon: string;
installPrompt?: InstallPrompt;
}

export function selectProvider(
Expand Down

0 comments on commit 31595ab

Please sign in to comment.