Skip to content

Commit

Permalink
fix(dcellar-web-ui): connect wallet button function when user was log…
Browse files Browse the repository at this point in the history
…ined
  • Loading branch information
devinxl committed Oct 11, 2023
1 parent 1842e58 commit 7a5cef0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
() =>
Expand Down
18 changes: 18 additions & 0 deletions apps/dcellar-web-ui/src/components/ConnectWallet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -12,8 +15,23 @@ interface ConnectWalletProps extends DCButtonProps {

export const ConnectWallet = memo<Partial<ConnectWalletProps>>(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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const BaseHeader = () => {
fontSize={14}
gaClickName={gaClickName}
icon={<IconFont type={'wallet-filled'} w={24} />}
text="Connect Wallet"
text="Get Started"
variant="ghost"
border={'1px solid readable.border'}
_hover={{
Expand Down

0 comments on commit 7a5cef0

Please sign in to comment.