1- import { createContext , useContext , useEffect , useState } from "react" ;
1+ import { createContext , useContext , useState } from "react" ;
22import { WalletModal } from "./modal" ;
33import { WalletState } from "@interchain-kit/core" ;
44import { useChainWallet , useWalletManager } from "../hooks" ;
@@ -23,10 +23,6 @@ export const WalletModalProvider = ({
2323 const open = ( ) => setModalIsOpen ( true ) ;
2424 const close = ( ) => setModalIsOpen ( false ) ;
2525
26- const [ walletNameToConnect , setWalletNameToConnect ] = useState < string | null > (
27- null
28- ) ;
29-
3026 const {
3127 chains,
3228 wallets,
@@ -36,9 +32,11 @@ export const WalletModalProvider = ({
3632 walletConnectQRCodeUri,
3733 getDownloadLink,
3834 getEnv,
35+ connect,
36+ getAccount,
3937 } = useWalletManager ( ) ;
4038
41- const { wallet, status, connect , disconnect, username, address, message } =
39+ const { wallet, status, disconnect, username, address, message } =
4240 useChainWallet ( currentChainName || chains [ 0 ] . chainName , currentWalletName ) ;
4341
4442 const [ shouldShowList , setShouldShowList ] = useState (
@@ -49,27 +47,18 @@ export const WalletModalProvider = ({
4947 transferToWalletUISchema
5048 ) ;
5149
52- useEffect ( ( ) => {
53- const handleConnect = async ( ) => {
54- if ( walletNameToConnect ) {
55- try {
56- await connect ( ) ;
57- setWalletNameToConnect ( null ) ;
58- setShouldShowList ( false ) ;
59- } catch ( error ) {
60- console . error ( "Error connecting to wallet:" , error ) ;
61- throw error ;
62- }
63- }
64- } ;
65- handleConnect ( ) ;
66- } , [ walletNameToConnect ] ) ;
67-
6850 const handleCloseModal = ( ) => {
6951 close ( ) ;
7052 setShouldShowList ( false ) ;
7153 } ;
7254
55+ const handleConnectWallet = async ( walletName : string ) => {
56+ const chainToConnect = currentChainName || chains [ 0 ] . chainName ;
57+ setShouldShowList ( false ) ;
58+ setCurrentWalletName ( walletName ) ;
59+ await connect ( walletName , chainToConnect ) ;
60+ } ;
61+
7362 return (
7463 < WalletModalContext . Provider value = { { modalIsOpen, open, close } } >
7564 { children }
@@ -90,12 +79,9 @@ export const WalletModalProvider = ({
9079 isDisconnected = { status === WalletState . Disconnected }
9180 isNotExist = { status === WalletState . NotExist }
9281 errorMessage = { message }
93- onSelectWallet = { ( w ) => {
94- setWalletNameToConnect ( w . info . name ) ;
95- setCurrentWalletName ( w . info . name ) ;
96- } }
82+ onSelectWallet = { ( w ) => handleConnectWallet ( w . info . name ) }
9783 onBack = { ( ) => setShouldShowList ( true ) } // Add other required props with appropriate default or mock values
98- onReconnect = { connect }
84+ onReconnect = { ( ) => handleConnectWallet ( currentWalletName ) }
9985 getDownloadLink = { ( ) => getDownloadLink ( wallet ?. info . name ) }
10086 getEnv = { getEnv }
10187 />
0 commit comments