Skip to content

Commit f9e0fc1

Browse files
committed
feat: show new keystore connect dialog on keystore click
1 parent 249335f commit f9e0fc1

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

packages/ui/src/react/components/dialogs/wallet-connect-dialog.tsx

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import { SearchIcon, WalletMinimalIcon } from "lucide-react";
77
import { useCallback, useMemo, useState } from "react";
88
import { toast } from "sonner";
99
import { match, P } from "ts-pattern";
10-
import { useModal } from "../../hooks/use-modal";
10+
import { showModal, useModal } from "../../hooks/use-modal";
1111
import { useSwapKit } from "../../swapkit-context";
1212
import { Button } from "../ui/button";
1313
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "../ui/dialog";
1414
import { Input } from "../ui/input";
1515
import { SWAPKIT_WIDGET_TOASTER_ID } from "../ui/sonner";
1616
import { WalletIcon } from "../wallet-icon";
17+
import { WalletKeystoreConnectDialog } from "./wallet-keystore-connect-dialog";
1718

1819
const WALLET_GROUPS = {
1920
"Browser Extensions": [
@@ -190,7 +191,7 @@ const FEATURED_WALLETS = [
190191
WalletOption.METAMASK,
191192
WalletOption.CTRL,
192193
WalletOption.COINBASE_WEB,
193-
WalletOption.PHANTOM,
194+
WalletOption.KEYSTORE,
194195
WalletOption.LEDGER,
195196
WalletOption.TREZOR,
196197
WalletOption.BRAVE,
@@ -200,7 +201,6 @@ const FEATURED_WALLETS = [
200201
export function WalletConnectDialog() {
201202
const modal = useModal();
202203
const [isShowingAllWallets, setIsShowingAllWallets] = useState(false);
203-
204204
const [searchQuery, setSearchQuery] = useState("");
205205

206206
const filteredWalletGroups = useMemo(() => {
@@ -292,11 +292,31 @@ function WalletConnectButton({ wallet }: { wallet: WalletOption }) {
292292
const { connectWallet, isConnectingWallet, walletType } = useSwapKit();
293293
const modal = useModal();
294294

295-
const handleButtonClick = useCallback(async () => {
295+
const handleWalletClick = useCallback(async () => {
296296
try {
297-
await connectWallet(wallet, [Chain.Cosmos, Chain.Maya, Chain.THORChain, Chain.Kujira] as Chain[]);
297+
const chainsForWallet = availableChainsByWallet?.[wallet] as Chain[];
298+
299+
if (!chainsForWallet || chainsForWallet?.length === 0) {
300+
toast.error("This wallet does not support any chains", {
301+
description: "Please try a different wallet.",
302+
toasterId: SWAPKIT_WIDGET_TOASTER_ID,
303+
});
304+
return;
305+
}
306+
307+
await match(wallet)
308+
.with(WalletOption.KEYSTORE, async () => {
309+
const { confirmed } = await showModal(<WalletKeystoreConnectDialog />);
310+
311+
if (!confirmed) return;
312+
313+
modal.resolve({ confirmed: true, data: wallet });
314+
})
315+
.otherwise(async () => {
316+
await connectWallet(wallet, chainsForWallet);
298317

299-
modal.resolve({ confirmed: true, data: wallet });
318+
modal.resolve({ confirmed: true, data: wallet });
319+
});
300320
} catch {
301321
toast.error("Failed to connect your wallet", {
302322
description: "Make sure your wallet is connected and accessible by the browser.",
@@ -315,7 +335,7 @@ function WalletConnectButton({ wallet }: { wallet: WalletOption }) {
315335
className="flex aspect-[1.525/1] h-full w-full flex-col items-center justify-center gap-1"
316336
isLoading={isConnectingWallet && walletType === wallet}
317337
key={`wallet-connect-button-${wallet}`}
318-
onClick={handleButtonClick}>
338+
onClick={handleWalletClick}>
319339
<WalletIcon className="size-5" wallet={wallet} />
320340

321341
<span className="text-foreground text-sm">{walletName}</span>

playgrounds/nextjs/src/app/globals.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
--muted: var(--secondary);
2929
--muted-foreground: var(--white) / 0.64;
3030

31-
--accent: 12 6.5% 15.1%;
31+
--accent: 140 87% 79%;
3232
--accent-foreground: 60 9.1% 97.8%;
3333

3434
--destructive: 0 62.8% 30.6%;

0 commit comments

Comments
 (0)