|
1 |
| -import React from "react"; |
| 1 | +import React, { useMemo } from "react"; |
2 | 2 | import styled from "styled-components";
|
3 | 3 |
|
4 | 4 | import { responsiveSize } from "styles/responsiveSize";
|
5 | 5 |
|
6 | 6 | import { useToggle } from "react-use";
|
| 7 | +import { useSearchParams } from "react-router-dom"; |
| 8 | +import { Copiable } from "@kleros/ui-components-library"; |
7 | 9 |
|
8 | 10 | import XIcon from "svgs/socialmedia/x.svg";
|
9 | 11 |
|
| 12 | +import { DEFAULT_CHAIN, getChain } from "consts/chains"; |
| 13 | +import { shortenAddress } from "utils/shortenAddress"; |
| 14 | + |
10 | 15 | import HowItWorks from "components/HowItWorks";
|
11 | 16 | import JurorLevels from "components/Popup/MiniGuides/JurorLevels";
|
12 | 17 | import { ExternalLink } from "components/ExternalLink";
|
@@ -45,31 +50,57 @@ const StyledLink = styled(ExternalLink)`
|
45 | 50 | gap: 8px;
|
46 | 51 | `;
|
47 | 52 |
|
| 53 | +const StyledExternalLink = styled(ExternalLink)` |
| 54 | + font-size: ${responsiveSize(18, 22)}; |
| 55 | + margin-left: ${responsiveSize(4, 8)}; |
| 56 | + font-weight: 600; |
| 57 | +`; |
| 58 | + |
48 | 59 | interface IHeader {
|
49 | 60 | levelTitle: string;
|
50 | 61 | levelNumber: number;
|
51 | 62 | totalCoherentVotes: number;
|
52 | 63 | totalResolvedVotes: number;
|
| 64 | + addressToQuery: `0x${string}`; |
53 | 65 | }
|
54 | 66 |
|
55 |
| -const Header: React.FC<IHeader> = ({ levelTitle, levelNumber, totalCoherentVotes, totalResolvedVotes }) => { |
| 67 | +const Header: React.FC<IHeader> = ({ |
| 68 | + levelTitle, |
| 69 | + levelNumber, |
| 70 | + totalCoherentVotes, |
| 71 | + totalResolvedVotes, |
| 72 | + addressToQuery, |
| 73 | +}) => { |
56 | 74 | const [isJurorLevelsMiniGuideOpen, toggleJurorLevelsMiniGuide] = useToggle(false);
|
| 75 | + const [searchParams] = useSearchParams(); |
57 | 76 |
|
58 | 77 | const coherencePercentage = parseFloat(((totalCoherentVotes / Math.max(totalResolvedVotes, 1)) * 100).toFixed(2));
|
59 | 78 | const courtUrl = window.location.origin;
|
60 | 79 | const xPostText = `Hey I've been busy as a Juror on the Kleros court, check out my score: \n\nLevel: ${levelNumber} (${levelTitle})\nCoherence Percentage: ${coherencePercentage}%\nCoherent Votes: ${totalCoherentVotes}/${totalResolvedVotes}\n\nBe a juror with me! ➡️ ${courtUrl}`;
|
61 | 80 | const xShareUrl = `https://twitter.com/intent/tweet?text=${encodeURIComponent(xPostText)}`;
|
| 81 | + const searchParamAddress = searchParams.get("address")?.toLowerCase(); |
| 82 | + |
| 83 | + const addressExplorerLink = useMemo(() => { |
| 84 | + return `${getChain(DEFAULT_CHAIN)?.blockExplorers?.default.url}/address/${addressToQuery}`; |
| 85 | + }, [addressToQuery]); |
62 | 86 |
|
63 | 87 | return (
|
64 | 88 | <Container>
|
65 |
| - <StyledTitle>Juror Dashboard</StyledTitle> |
| 89 | + <StyledTitle> |
| 90 | + Juror Dashboard - |
| 91 | + <Copiable copiableContent={addressToQuery} info="Copy Address"> |
| 92 | + <StyledExternalLink to={addressExplorerLink} target="_blank" rel="noopener noreferrer"> |
| 93 | + {shortenAddress(addressToQuery)} |
| 94 | + </StyledExternalLink> |
| 95 | + </Copiable> |
| 96 | + </StyledTitle> |
66 | 97 | <LinksContainer>
|
67 | 98 | <HowItWorks
|
68 | 99 | isMiniGuideOpen={isJurorLevelsMiniGuideOpen}
|
69 | 100 | toggleMiniGuide={toggleJurorLevelsMiniGuide}
|
70 | 101 | MiniGuideComponent={JurorLevels}
|
71 | 102 | />
|
72 |
| - {totalResolvedVotes > 0 ? ( |
| 103 | + {totalResolvedVotes > 0 && !searchParamAddress ? ( |
73 | 104 | <StyledLink to={xShareUrl} target="_blank" rel="noreferrer">
|
74 | 105 | <StyledXIcon /> <span>Share your juror score</span>
|
75 | 106 | </StyledLink>
|
|
0 commit comments