-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathindex.tsx
65 lines (53 loc) · 1.83 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import React from "react";
import styled, { css } from "styled-components";
import Skeleton from "react-loading-skeleton";
import { useAccount } from "wagmi";
import { useReadSortitionModuleGetJurorBalance } from "hooks/contracts/generated";
import { useJurorStakeDetailsQuery } from "queries/useJurorStakeDetailsQuery";
import { landscapeStyle } from "styles/landscapeStyle";
import CourtCard from "./CourtCard";
import Header from "./Header";
const Container = styled.div`
margin-top: 64px;
`;
const CourtCardsContainer = styled.div`
display: flex;
flex-direction: column;
gap: 12px;
z-index: 0;
${landscapeStyle(
() => css`
gap: 16px;
`
)}
`;
const StyledLabel = styled.label`
font-size: 16px;
`;
const Courts: React.FC = () => {
const { address } = useAccount();
const { data: stakeData, isLoading } = useJurorStakeDetailsQuery(address?.toLowerCase() as `0x${string}`);
const { data: jurorBalance } = useReadSortitionModuleGetJurorBalance({
args: [address as `0x${string}`, BigInt(1)],
});
const stakedCourts = stakeData?.jurorTokensPerCourts?.filter(({ staked }) => staked > 0);
const isStaked = stakedCourts && stakedCourts.length > 0;
const lockedStake = jurorBalance?.[1];
return (
<Container>
<Header lockedStake={lockedStake ?? BigInt(0)} />
{isLoading ? <Skeleton /> : null}
{!isStaked && !isLoading ? <StyledLabel>You are not staked in any court</StyledLabel> : null}
{isStaked && !isLoading ? (
<CourtCardsContainer>
{stakeData?.jurorTokensPerCourts
?.filter(({ staked }) => staked > 0)
.map(({ court: { id, name }, staked }) => (
<CourtCard key={id} name={name ?? ""} stake={staked} {...{ id }} />
))}
</CourtCardsContainer>
) : null}
</Container>
);
};
export default Courts;