diff --git a/apps/dcellar-web-ui/src/components/ConnectWallet/index.tsx b/apps/dcellar-web-ui/src/components/ConnectWallet/index.tsx index 22ac267e..4c092170 100644 --- a/apps/dcellar-web-ui/src/components/ConnectWallet/index.tsx +++ b/apps/dcellar-web-ui/src/components/ConnectWallet/index.tsx @@ -7,6 +7,7 @@ import { setConnectWallet } from '@/store/slices/global'; import { useAppSelector } from '@/store'; import { useRouter } from 'next/router'; import { InternalRoutePaths } from '@/utils/constant'; +import { useAccount } from 'wagmi'; interface ConnectWalletProps extends DCButtonProps { icon?: ReactElement; @@ -17,23 +18,23 @@ export const ConnectWallet = memo>(function ConnectB const dispatch = useDispatch(); const router = useRouter(); const { loginAccount } = useAppSelector((root) => root.persist); + const { isConnected } = useAccount(); const { icon, text, ...restProps } = props; const onOpen = () => { - if (loginAccount) { - const originPathname = decodeURIComponent(router.query.originAsPath as string); - setTimeout( - () => - router.push( - !!originPathname && originPathname !== 'undefined' - ? originPathname - : InternalRoutePaths.buckets, - ), - 100, - ); - return; - }; - dispatch(setConnectWallet(true)); + // The window.trustwallet.request method is undefined when the app is loaded. So add a delay to avoid. + setTimeout(() => { + if (loginAccount && isConnected) { + const originPathname = decodeURIComponent(router.query.originAsPath as string); + return router.push( + !!originPathname && originPathname !== 'undefined' + ? originPathname + : InternalRoutePaths.buckets, + ); + }; + dispatch(setConnectWallet(true)); + }, 200) } + return ( <>