Skip to content

fix(web): improve onClick functionality #1657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 22, 2024
Merged

Conversation

ShubhamParkhi
Copy link
Contributor

@ShubhamParkhi ShubhamParkhi commented Jul 20, 2024

PR-Codex overview

The focus of this PR is to optimize the settings menu in the header by passing additional props and conditionally rendering based on the default chain.

Detailed summary

  • Added isDefaultChain prop to ConnectWalletContainer styled component
  • Added DEFAULT_CHAIN import
  • Extracted chainId from useAccount hook in DesktopHeader
  • Updated ConnectWalletContainer onClick logic to consider both isConnected and isDefaultChain

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • New Features

    • Enhanced wallet connection logic, ensuring user actions depend on being connected to the correct blockchain.
    • Introduced new styling conditions in the wallet connection component to improve user experience.
  • Bug Fixes

    • Improved functionality of the settings toggle to prevent unintended behavior when not connected to the correct chain.
  • Documentation

    • Updated prop passing syntax for improved readability in the settings component.

Copy link

netlify bot commented Jul 20, 2024

Deploy Preview for kleros-v2 ready!

Name Link
🔨 Latest commit d4f28a5
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2/deploys/669e2c53e1f8060009c9e561
😎 Deploy Preview https://deploy-preview-1657--kleros-v2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Jul 20, 2024

‼️ Deploy request for kleros-v2-neo rejected.

Name Link
🔨 Latest commit 1fd68f0

Copy link

netlify bot commented Jul 20, 2024

👷 Deploy request for kleros-v2-university pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit d4f28a5

Copy link
Contributor

coderabbitai bot commented Jul 20, 2024

Walkthrough

The recent updates enhance the DesktopHeader component's wallet connection functionality by incorporating blockchain chain validation. The ConnectWalletContainer now conditionally styles based on whether the user is connected to the default chain. Additionally, the prop syntax in the Settings component is refined for improved readability. Together, these changes streamline user interactions and ensure a better experience when managing wallet connectivity.

Changes

Files Change Summary
web/src/layout/Header/DesktopHeader.tsx Enhanced wallet connection logic by adding isDefaultChain prop to ConnectWalletContainer. Updated click handler to check both connection status and chain validity.
web/src/layout/Header/navbar/Menu/Settings/index.tsx Modified prop passing to NotificationSettings using the spread operator for improved readability.

Poem

🐇 In the header where wallets gleam,
A rabbit hops, chasing a dream.
Clicks now check both right and bright,
Settings open with pure delight!
Each change a hop, each line a cheer,
A better way for us all to steer! ✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7165c90 and 1fd68f0.

Files selected for processing (2)
  • web/src/layout/Header/DesktopHeader.tsx (5 hunks)
  • web/src/layout/Header/navbar/Menu/Settings/index.tsx (1 hunks)
Files skipped from review due to trivial changes (1)
  • web/src/layout/Header/navbar/Menu/Settings/index.tsx
Additional comments not posted (5)
web/src/layout/Header/DesktopHeader.tsx (5)

6-6: LGTM! Imports are correct.

The useAccount and useChainId hooks are correctly imported from wagmi.


12-12: LGTM! Constant import is correct.

The DEFAULT_CHAIN constant is correctly imported for chain validation.


78-88: LGTM! Styled component prop addition is correct.

The ConnectWalletContainer styled component now correctly accepts the isCorrectChain prop for conditional styling.


111-113: LGTM! State and hooks changes are correct.

The chainId and isCorrectChain variables are correctly introduced and implemented for chain validation.


149-152: LGTM! Rendering logic changes are correct.

The ConnectWalletContainer now correctly passes the isCorrectChain prop and conditionally sets the onClick handler based on connection and chain validation.

coderabbitai[bot]
coderabbitai bot previously approved these changes Jul 20, 2024
@kemuru kemuru self-requested a review July 22, 2024 09:47
Copy link
Contributor

@kemuru kemuru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesnt work. correct code below, this is different from escrow-v2 and curate-v2 since the useAccount hook has the chainId in the new wagmi versions. The problem with useChainId is that it fetches the chainId used by the web application and not from the wallet:

import React, { useCallback, useEffect, useState } from "react";
import styled, { css } from "styled-components";

import { useLocation } from "react-router-dom";
import { useToggle } from "react-use";
import { useAccount } from "wagmi";

import KlerosSolutionsIcon from "svgs/menu-icons/kleros-solutions.svg";

import { useLockOverlayScroll } from "hooks/useLockOverlayScroll";

import { DEFAULT_CHAIN } from "consts/chains";

import { landscapeStyle } from "styles/landscapeStyle";
import { responsiveSize } from "styles/responsiveSize";

import ConnectWallet from "components/ConnectWallet";
import LightButton from "components/LightButton";
import Onboarding from "components/Popup/MiniGuides/Onboarding";

import Logo from "./Logo";
import DappList from "./navbar/DappList";
import Explore from "./navbar/Explore";
import Menu from "./navbar/Menu";
import Help from "./navbar/Menu/Help";
import Settings from "./navbar/Menu/Settings";

const Container = styled.div`
  display: none;
  position: absolute;

  ${landscapeStyle(
    () => css`
      display: flex;
      align-items: center;
      justify-content: space-between;
      width: 100%;
      position: relative;
    `
  )};
`;

const LeftSide = styled.div`
  display: flex;
`;

const MiddleSide = styled.div`
  display: flex;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  color: ${({ theme }) => theme.white} !important;
`;

const RightSide = styled.div`
  display: flex;
  gap: ${responsiveSize(8, 16, 300, 1024)};

  margin-left: 8px;
  canvas {
    width: 20px;
  }
`;

const LightButtonContainer = styled.div`
  display: flex;
  align-items: center;
  width: 16px;
  margin-left: ${responsiveSize(4, 8)};
  margin-right: ${responsiveSize(12, 16)};
`;

const StyledKlerosSolutionsIcon = styled(KlerosSolutionsIcon)`
  fill: ${({ theme }) => theme.white} !important;
`;

const ConnectWalletContainer = styled.div<{ isConnected: boolean; isDefaultChain: boolean }>`
  label {
    color: ${({ theme }) => theme.white};
  }

  ${({ isConnected, isDefaultChain }) =>
    isConnected &&
    isDefaultChain &&
    css`
      cursor: pointer;
      & > * {
        pointer-events: none;
      }
    `}
`;

const PopupContainer = styled.div`
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  background-color: ${({ theme }) => theme.blackLowOpacity};
`;

const DesktopHeader: React.FC = () => {
  const [isDappListOpen, toggleIsDappListOpen] = useToggle(false);
  const [isHelpOpen, toggleIsHelpOpen] = useToggle(false);
  const [isSettingsOpen, toggleIsSettingsOpen] = useToggle(false);
  const [isOnboardingMiniGuidesOpen, toggleIsOnboardingMiniGuidesOpen] = useToggle(false);
  const [initialTab, setInitialTab] = useState<number>(0);
  const location = useLocation();
  const { isConnected, chainId } = useAccount();
  const isDefaultChain = chainId === DEFAULT_CHAIN;

  const initializeFragmentURL = useCallback(() => {
    const hash = location.hash;
    const hasOnboardingPath = hash.includes("#onboarding");
    const hasNotificationsPath = hash.includes("#notifications");
    toggleIsOnboardingMiniGuidesOpen(hasOnboardingPath);
    toggleIsSettingsOpen(hasNotificationsPath);
    setInitialTab(hasNotificationsPath ? 1 : 0);
  }, [location.hash, toggleIsSettingsOpen, toggleIsOnboardingMiniGuidesOpen]);

  useEffect(initializeFragmentURL, [initializeFragmentURL]);

  useLockOverlayScroll(isDappListOpen || isHelpOpen || isSettingsOpen);

  return (
    <>
      <Container>
        <LeftSide>
          <LightButtonContainer>
            <LightButton
              text=""
              onClick={() => {
                toggleIsDappListOpen();
              }}
              Icon={StyledKlerosSolutionsIcon}
            />
          </LightButtonContainer>
          <Logo />
        </LeftSide>

        <MiddleSide>
          <Explore />
        </MiddleSide>

        <RightSide>
          <ConnectWalletContainer
            {...{ isConnected, isDefaultChain }}
            onClick={isConnected && isDefaultChain ? toggleIsSettingsOpen : undefined}
          >
            <ConnectWallet />
          </ConnectWalletContainer>
          <Menu {...{ toggleIsHelpOpen, toggleIsSettingsOpen }} />
        </RightSide>
      </Container>
      {(isDappListOpen || isHelpOpen || isSettingsOpen) && (
        <PopupContainer>
          {isDappListOpen && <DappList {...{ toggleIsDappListOpen, isDappListOpen }} />}
          {isHelpOpen && <Help {...{ toggleIsHelpOpen, isHelpOpen }} />}
          {isSettingsOpen && <Settings {...{ toggleIsSettingsOpen, isSettingsOpen, initialTab }} />}
        </PopupContainer>
      )}
      {isOnboardingMiniGuidesOpen && <Onboarding toggleMiniGuide={toggleIsOnboardingMiniGuidesOpen} />}
    </>
  );
};
export default DesktopHeader;

Copy link

codeclimate bot commented Jul 22, 2024

Code Climate has analyzed commit d4f28a5 and detected 0 issues on this pull request.

View more on Code Climate.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1fd68f0 and d4f28a5.

Files selected for processing (1)
  • web/src/layout/Header/DesktopHeader.tsx (5 hunks)
Files skipped from review as they are similar to previous changes (1)
  • web/src/layout/Header/DesktopHeader.tsx

@jaybuidl jaybuidl merged commit 5f3d237 into kleros:dev Jul 22, 2024
12 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants