@@ -11,7 +11,7 @@ import {
1111 Button ,
1212} from "@chakra-ui/react" ;
1313import { ArrowDown , Fuel , TriangleAlert } from "lucide-react" ;
14- import { Address , isAddress } from "viem" ;
14+ import { type Address , isAddress } from "viem" ;
1515import { mainnet } from "viem/chains" ;
1616import { Toaster } from "@/components/ui/toaster" ;
1717import {
@@ -45,7 +45,7 @@ import { ClipboardLink, ClipboardRoot } from "@/components/ui/clipboard";
4545import RouteIndication from "@/components/RouteIndication" ;
4646import { Tooltip } from "@/components/ui/tooltip" ;
4747import Slippage from "@/components/Slippage" ;
48- import { NotifyType , ObligatedToken , WidgetComponentProps } from "@/types" ;
48+ import { NotifyType , ObligatedToken , type WidgetComponentProps } from "@/types" ;
4949
5050const BridgingFee = ( {
5151 gasValue,
@@ -109,7 +109,7 @@ const SwapWidget = ({
109109 ) ;
110110
111111 const chainId = usePriorityChainId ( ) ;
112- const { chainId : wagmiChainId } = useAccount ( ) ;
112+ const { chainId : wagmiChainId , address } = useAccount ( ) ;
113113 const setOutChainId = useStore ( ( state ) => state . setTokenOutChainId ) ;
114114 const outChainId = useStore ( ( state ) => state . tokenOutChainId ?? chainId ) ;
115115 const obligatedChainId = useStore ( ( state ) => state . obligatedChainId ) ;
@@ -143,8 +143,11 @@ const SwapWidget = ({
143143 if ( chainId === wagmiChainId ) {
144144 switchChain ( { chainId : newChainId } ) ;
145145 }
146+ if ( ! tokenOut ) {
147+ setOutChainId ( newChainId ) ;
148+ }
146149 } ,
147- [ wagmiChainId , chainId , setObligatedChainId , switchChain ]
150+ [ wagmiChainId , chainId , switchChain , tokenOut ]
148151 ) ;
149152
150153 // Notify parent of state changes when any relevant state changes
@@ -447,49 +450,53 @@ const SwapWidget = ({
447450 </ Flex >
448451 </ Box >
449452
450- < Flex w = { "full" } gap = { 4 } >
451- { wrongChain ? (
452- < Button
453- size = "lg"
454- borderRadius = { "lg" }
455- colorPalette = { "blue" }
456- onClick = { ( ) => switchChain ( { chainId } ) }
457- >
458- Switch to { getChainName ( chainId ) }
459- </ Button >
460- ) : (
461- approveNeeded && (
453+ { address ? (
454+ < Flex w = { "full" } gap = { 4 } >
455+ { wrongChain ? (
462456 < Button
463457 size = "lg"
464458 borderRadius = { "lg" }
465459 colorPalette = { "blue" }
466- flex = { 1 }
467- loading = { approve . isLoading }
468- onClick = { approve . write }
460+ onClick = { ( ) => switchChain ( { chainId } ) }
469461 >
470- Approve
462+ Switch to { getChainName ( chainId ) }
471463 </ Button >
472- )
473- ) }
464+ ) : (
465+ approveNeeded && (
466+ < Button
467+ size = "lg"
468+ borderRadius = { "lg" }
469+ colorPalette = { "blue" }
470+ flex = { 1 }
471+ loading = { approve . isLoading }
472+ onClick = { approve . write }
473+ >
474+ Approve
475+ </ Button >
476+ )
477+ ) }
474478
475- < Tooltip content = { swapWarning } disabled = { ! swapWarning } >
476- < Button
477- size = "lg"
478- borderRadius = { "lg" }
479- colorPalette = { "blue" }
480- flex = { 1 }
481- disabled = { swapDisabled }
482- loading = { sendTransaction . isLoading || routerLoading }
483- onClick = {
484- needToAcceptWarning
485- ? showPriceImpactWarning
486- : sendTransaction . send
487- }
488- >
489- { chainId === outChainId ? "Swap" : "Bridge" }
490- </ Button >
491- </ Tooltip >
492- </ Flex >
479+ < Tooltip content = { swapWarning } disabled = { ! swapWarning } >
480+ < Button
481+ size = "lg"
482+ borderRadius = { "lg" }
483+ colorPalette = { "blue" }
484+ flex = { 1 }
485+ disabled = { swapDisabled }
486+ loading = { sendTransaction . isLoading || routerLoading }
487+ onClick = {
488+ needToAcceptWarning
489+ ? showPriceImpactWarning
490+ : sendTransaction . send
491+ }
492+ >
493+ { chainId === outChainId ? "Swap" : "Bridge" }
494+ </ Button >
495+ </ Tooltip >
496+ </ Flex >
497+ ) : (
498+ < Text > Please connect your wallet</ Text >
499+ ) }
493500
494501 { error && (
495502 < Text color = "red.500" fontSize = "xs" mt = { 1 } >
0 commit comments