From 7a5cef0e6235291a17e8e2611b3f72ee75f02e9f Mon Sep 17 00:00:00 2001 From: devinxl Date: Wed, 11 Oct 2023 15:48:18 +0800 Subject: [PATCH] fix(dcellar-web-ui): connect wallet button function when user was logined --- .../ConnectWallet/WalletConnectModal.tsx | 8 ++++++-- .../src/components/ConnectWallet/index.tsx | 18 ++++++++++++++++++ .../components/layout/Common/SelectNetwork.tsx | 6 +++++- .../layout/LandingHeader/BaseHeader.tsx | 2 +- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/apps/dcellar-web-ui/src/components/ConnectWallet/WalletConnectModal.tsx b/apps/dcellar-web-ui/src/components/ConnectWallet/WalletConnectModal.tsx index 91db6166..60304a1c 100644 --- a/apps/dcellar-web-ui/src/components/ConnectWallet/WalletConnectModal.tsx +++ b/apps/dcellar-web-ui/src/components/ConnectWallet/WalletConnectModal.tsx @@ -43,10 +43,14 @@ export function WalletConnectModal() { if ( hasTrigger && !isAuthPending && - !!address && - ssrLandingRoutes.some((item) => item === router.pathname) + !!address ) { onClose(); + // Only user trigger login at landing page that app needs redirect to the main page. + if (!ssrLandingRoutes.some((item) => item === router.pathname)) { + return; + } + // Redirect to the main page after user login manually. const originPathname = decodeURIComponent(router.query.originAsPath as string); setTimeout( () => diff --git a/apps/dcellar-web-ui/src/components/ConnectWallet/index.tsx b/apps/dcellar-web-ui/src/components/ConnectWallet/index.tsx index 8763a9c4..22ac267e 100644 --- a/apps/dcellar-web-ui/src/components/ConnectWallet/index.tsx +++ b/apps/dcellar-web-ui/src/components/ConnectWallet/index.tsx @@ -4,6 +4,9 @@ import { Text } from '@totejs/uikit'; import { smMedia } from '@/modules/responsive'; import { useDispatch } from 'react-redux'; import { setConnectWallet } from '@/store/slices/global'; +import { useAppSelector } from '@/store'; +import { useRouter } from 'next/router'; +import { InternalRoutePaths } from '@/utils/constant'; interface ConnectWalletProps extends DCButtonProps { icon?: ReactElement; @@ -12,8 +15,23 @@ interface ConnectWalletProps extends DCButtonProps { export const ConnectWallet = memo>(function ConnectButton(props) { const dispatch = useDispatch(); + const router = useRouter(); + const { loginAccount } = useAppSelector((root) => root.persist); 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)); } return ( diff --git a/apps/dcellar-web-ui/src/components/layout/Common/SelectNetwork.tsx b/apps/dcellar-web-ui/src/components/layout/Common/SelectNetwork.tsx index b25208aa..4aa2e47a 100644 --- a/apps/dcellar-web-ui/src/components/layout/Common/SelectNetwork.tsx +++ b/apps/dcellar-web-ui/src/components/layout/Common/SelectNetwork.tsx @@ -6,6 +6,7 @@ import { DCMenu } from '@/components/common/DCMenu'; import { MenuOption } from '@/components/common/DCMenuList'; import { IconFont } from '@/components/IconFont'; import { DCButton } from '@/components/common/DCButton'; +import { InternalRoutePaths } from '@/utils/constant'; interface TNetwork extends MenuOption { label: string; @@ -33,7 +34,10 @@ export const SelectNetwork = () => { if (runtimeEnv === net.value) { return; } - window.location.href = `${net.domain}${router.asPath}`; + const isBucketsPath = router.pathname.includes(InternalRoutePaths.buckets); + window.location.href = isBucketsPath + ? `${net.domain}${InternalRoutePaths.buckets}` + : `${net.domain}${router.asPath}`; }; return ( diff --git a/apps/dcellar-web-ui/src/components/layout/LandingHeader/BaseHeader.tsx b/apps/dcellar-web-ui/src/components/layout/LandingHeader/BaseHeader.tsx index 705ff785..ea179503 100644 --- a/apps/dcellar-web-ui/src/components/layout/LandingHeader/BaseHeader.tsx +++ b/apps/dcellar-web-ui/src/components/layout/LandingHeader/BaseHeader.tsx @@ -75,7 +75,7 @@ export const BaseHeader = () => { fontSize={14} gaClickName={gaClickName} icon={} - text="Connect Wallet" + text="Get Started" variant="ghost" border={'1px solid readable.border'} _hover={{