Skip to content

Commit

Permalink
Merge pull request #1463 from kleros/feat(web)/case-cards-indicators
Browse files Browse the repository at this point in the history
Feat(web)/case cards indicators
  • Loading branch information
alcercu authored Feb 2, 2024
2 parents f7b6240 + 95073a0 commit e2a18cc
Show file tree
Hide file tree
Showing 22 changed files with 381 additions and 10 deletions.
1 change: 1 addition & 0 deletions subgraph/core/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ type ClassicContribution implements Contribution @entity {

localRound: ClassicRound!
amount: BigInt!
rewardAmount: BigInt
choice: BigInt!
rewardWithdrawn: Boolean!
}
1 change: 1 addition & 0 deletions subgraph/core/src/DisputeKitClassic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,6 @@ export function handleWithdrawal(event: Withdrawal): void {
const contribution = ensureClassicContributionFromEvent(event);
if (!contribution) return;
contribution.rewardWithdrawn = true;
contribution.rewardAmount = event.params._amount;
contribution.save();
}
10 changes: 5 additions & 5 deletions subgraph/core/src/entities/ClassicContribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { Contribution as ContributionEvent, Withdrawal } from "../../generated/D
import { DISPUTEKIT_ID } from "../DisputeKitClassic";

export function ensureClassicContributionFromEvent<T>(event: T): ClassicContribution | null {
if (!(event instanceof ContributionEvent) && !(event instanceof Withdrawal)) {
return null;
}
if (!(event instanceof ContributionEvent) && !(event instanceof Withdrawal)) return null;
const coreDisputeID = event.params._coreDisputeID.toString();
const coreRoundIndex = event.params._coreRoundID.toString();
const roundID = `${DISPUTEKIT_ID}-${coreDisputeID}-${coreRoundIndex}`;
Expand All @@ -25,9 +23,11 @@ export function ensureClassicContributionFromEvent<T>(event: T): ClassicContribu
classicContribution.rewardWithdrawn = false;
} else {
const currentAmount = classicContribution.amount;
classicContribution.amount = currentAmount.plus(event.params._amount);
// we dont want to increase amount on withdraw event, the amount in that event is reward/reimburse amount
if (event instanceof ContributionEvent) {
classicContribution.amount = currentAmount.plus(event.params._amount);
}
}

classicContribution.save();
return classicContribution;
}
2 changes: 1 addition & 1 deletion subgraph/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kleros/kleros-v2-subgraph",
"version": "0.4.0",
"version": "0.5.0",
"license": "MIT",
"scripts": {
"update:core:arbitrum-sepolia-devnet": "./scripts/update.sh arbitrumSepoliaDevnet arbitrum-sepolia core/subgraph.yaml",
Expand Down
2 changes: 1 addition & 1 deletion web/src/assets/svgs/icons/eth.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions web/src/assets/svgs/label-icons/appeal.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions web/src/assets/svgs/label-icons/evidence.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions web/src/assets/svgs/label-icons/forgot-vote.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions web/src/assets/svgs/label-icons/funded.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions web/src/assets/svgs/label-icons/minus-circle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions web/src/assets/svgs/label-icons/rewards-lost.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions web/src/assets/svgs/label-icons/rewards-won.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions web/src/assets/svgs/label-icons/vote.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions web/src/assets/svgs/label-icons/voted.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 63 additions & 0 deletions web/src/components/DisputeCard/CardLabels/Label.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React, { useMemo } from "react";
import styled, { Theme, useTheme } from "styled-components";

const COLORS: Record<string, Array<keyof Theme>> = {
red: ["error", "errorLight"],
green: ["success", "successLight"],
blue: ["primaryBlue", "mediumBlue"],
purple: ["secondaryPurple", "mediumPurple"],
lightPurple: ["tint", "mediumPurple"],
grey: ["secondaryText", "lightGrey"],
};

export type IColors = keyof typeof COLORS;

const LabelContainer = styled.div<{ backgroundColor: string }>`
display: inline-flex;
padding: 4px 8px;
align-items: center;
gap: 10px;
border-radius: 300px;
background-color: ${({ backgroundColor }) => backgroundColor};
`;

const IconContainer = styled.div<{ contentColor: string }>`
height: 14px;
width: 14px;
display: flex;
align-items: center;
justify-content: center;
> svg {
fill: ${({ contentColor }) => contentColor};
}
`;

const StyledText = styled.label<{ contentColor: string }>`
font-size: 12px;
font-weight: 400;
color: ${({ contentColor }) => contentColor};
`;

export interface ILabelProps {
text: string;
icon: React.FC<React.SVGAttributes<SVGElement>>;
color: keyof typeof COLORS;
}

const Label: React.FC<ILabelProps> = ({ text, icon: Icon, color }) => {
const theme = useTheme();
const [contentColor, backgroundColor] = useMemo(() => {
return COLORS[color].map((color) => theme[color]);
}, [theme, color]);

return (
<LabelContainer {...{ backgroundColor }}>
<IconContainer {...{ contentColor }}>
<Icon />
</IconContainer>
<StyledText {...{ contentColor }}>{text}</StyledText>
</LabelContainer>
);
};

export default Label;
46 changes: 46 additions & 0 deletions web/src/components/DisputeCard/CardLabels/RewardsAndFundLabel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from "react";
import styled, { useTheme } from "styled-components";
import EthIcon from "assets/svgs/icons/eth.svg";
import PnkIcon from "assets/svgs/icons/kleros.svg";
import NumberDisplay from "components/NumberDisplay";

const Container = styled.div`
display: flex;
gap: 4px;
align-items: center;
flex-wrap: wrap;
`;

const StyledIcon = styled.div<{ color: string }>`
width: 12px;
height: 12px;
path {
fill: ${({ color }) => color};
}
`;

const StyledLabel = styled.label<{ color: string }>`
color: ${({ color }) => color};
`;
interface IRewardsAndFundLabel {
value: string;
unit: "ETH" | "PNK";
isFund?: boolean;
}

const RewardsAndFundLabel: React.FC<IRewardsAndFundLabel> = ({ value, unit = "ETH", isFund = false }) => {
const theme = useTheme();
const isWon = Number(value) > 0;
const color = isWon ? theme.success : theme.error;
return Number(value) !== 0 ? (
<Container>
<StyledLabel color={isFund ? theme.tint : color}>
<NumberDisplay {...{ value, unit }} showUnitInDisplay={false} />
</StyledLabel>
<StyledIcon as={unit === "ETH" ? EthIcon : PnkIcon} color={isFund ? theme.tint : color} />
</Container>
) : null;
};

export default RewardsAndFundLabel;
Loading

0 comments on commit e2a18cc

Please sign in to comment.