@@ -2,7 +2,7 @@ import { IbcTransferProps } from "@namada/sdk-multicore";
22import { AccountType } from "@namada/types" ;
33import { mapUndefined } from "@namada/utils" ;
44import { routes } from "App/routes" ;
5- import { isShieldedAddress } from "App/Transfer/common" ;
5+ import { isIbcAddress , isShieldedAddress } from "App/Transfer/common" ;
66import { TransferModule } from "App/Transfer/TransferModule" ;
77import { OnSubmitTransferParams } from "App/Transfer/types" ;
88import {
@@ -28,6 +28,7 @@ import { useTransaction } from "hooks/useTransaction";
2828import { useTransactionActions } from "hooks/useTransactionActions" ;
2929import { useWalletManager } from "hooks/useWalletManager" ;
3030import { KeplrWalletManager } from "integrations/Keplr" ;
31+ import { getChainFromAddress } from "integrations/utils" ;
3132import invariant from "invariant" ;
3233import { useAtom , useAtomValue } from "jotai" ;
3334import { TransactionPair } from "lib/query" ;
@@ -84,6 +85,7 @@ export const IbcWithdraw = ({
8485 walletAddress : keplrAddress ,
8586 chainId,
8687 registry,
88+ connectToChainId,
8789 } = useWalletManager ( keplrWalletManager ) ;
8890 const transparentAccount = useAtomValue ( defaultAccountAtom ) ;
8991 const namadaChain = useAtomValue ( chainAtom ) ;
@@ -142,6 +144,22 @@ export const IbcWithdraw = ({
142144 }
143145 } ;
144146
147+ // Connect to IBC chain if destination address is an IBC address
148+ useEffect ( ( ) => {
149+ const connectIfIbc = async ( address : string ) : Promise < void > => {
150+ const chain = getChainFromAddress ( address ) ;
151+ if ( chain ?. chain_id ) {
152+ try {
153+ await connectToChainId ( chain . chain_id ) ;
154+ } catch ( error ) {
155+ console . error ( "Failed to connect to IBC chain:" , error ) ;
156+ }
157+ }
158+ } ;
159+
160+ if ( isIbcAddress ( destinationAddress ) ) connectIfIbc ( destinationAddress ) ;
161+ } , [ destinationAddress ] ) ;
162+
145163 const {
146164 data : ibcChannels ,
147165 isError : unknownIbcChannels ,
0 commit comments