@@ -130,21 +130,24 @@ export const IbcWithdraw = (): JSX.Element => {
130130 }
131131 } ;
132132
133- const updateDestinationChainAndAddress = ( chain : Chain | undefined ) : void => {
133+ const updateDestinationChainAndAddress = async (
134+ chain : Chain | undefined
135+ ) : Promise < void > => {
134136 setDestinationChain ( chain ) ;
135137 if ( customAddress ) {
136138 setCustomAddress ( "" ) ;
137139 }
138140 if ( chain ) {
139- loadWalletAddress ( chain ?. chain_id ) ;
141+ await connectToChainId ( chain . chain_id ) ;
142+ await loadWalletAddress ( chain . chain_id ) ;
140143 }
141144 } ;
142145
143146 const {
144147 data : ibcChannels ,
145148 isError : unknownIbcChannels ,
146149 isLoading : isLoadingIbcChannels ,
147- } = useAtomValue ( ibcChannelsFamily ( registry ?. chain . chain_name ) ) ;
150+ } = useAtomValue ( ibcChannelsFamily ( destinationChain ? .chain_name ) ) ;
148151
149152 useEffect ( ( ) => {
150153 setSourceChannel ( ibcChannels ?. namadaChannel || "" ) ;
@@ -154,23 +157,25 @@ export const IbcWithdraw = (): JSX.Element => {
154157 // to other chains different than the original one. Ex: OSMO should only be withdrew to Osmosis,
155158 // ATOM to Cosmoshub, etc.
156159 useEffect ( ( ) => {
157- if ( ! selectedAsset || ! chainTokens . data ) {
158- updateDestinationChainAndAddress ( undefined ) ;
159- return ;
160- }
160+ ( async ( ) => {
161+ if ( ! selectedAsset || ! chainTokens . data ) {
162+ await updateDestinationChainAndAddress ( undefined ) ;
163+ return ;
164+ }
161165
162- const token = chainTokens . data . find (
163- ( token ) => token . address === selectedAsset . originalAddress
164- ) ;
166+ const token = chainTokens . data . find (
167+ ( token ) => token . address === selectedAsset . originalAddress
168+ ) ;
165169
166- if ( token && "trace" in token ) {
167- const denom = getDenomFromIbcTrace ( token . trace ) ;
168- const chain = searchChainByDenom ( denom ) ;
169- updateDestinationChainAndAddress ( chain ) ;
170- return ;
171- }
170+ if ( token && "trace" in token ) {
171+ const denom = getDenomFromIbcTrace ( token . trace ) ;
172+ const chain = searchChainByDenom ( denom ) ;
173+ await updateDestinationChainAndAddress ( chain ) ;
174+ return ;
175+ }
172176
173- updateDestinationChainAndAddress ( undefined ) ;
177+ await updateDestinationChainAndAddress ( undefined ) ;
178+ } ) ( ) ;
174179 } , [ selectedAsset , chainTokens . data ] ) ;
175180
176181 const {
0 commit comments