@@ -7,13 +7,14 @@ import { SearchIcon, WalletMinimalIcon } from "lucide-react";
77import { useCallback , useMemo , useState } from "react" ;
88import { toast } from "sonner" ;
99import { match , P } from "ts-pattern" ;
10- import { useModal } from "../../hooks/use-modal" ;
10+ import { showModal , useModal } from "../../hooks/use-modal" ;
1111import { useSwapKit } from "../../swapkit-context" ;
1212import { Button } from "../ui/button" ;
1313import { Dialog , DialogContent , DialogFooter , DialogHeader , DialogTitle } from "../ui/dialog" ;
1414import { Input } from "../ui/input" ;
1515import { SWAPKIT_WIDGET_TOASTER_ID } from "../ui/sonner" ;
1616import { WalletIcon } from "../wallet-icon" ;
17+ import { WalletKeystoreConnectDialog } from "./wallet-keystore-connect-dialog" ;
1718
1819const 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 = [
200201export 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 >
0 commit comments