|
1 | 1 | import React, { useMemo } from "react"; |
2 | 2 | import styled, { css } from "styled-components"; |
3 | 3 |
|
4 | | -import { landscapeStyle } from "styles/landscapeStyle"; |
5 | | -import { responsiveSize } from "styles/responsiveSize"; |
6 | | - |
7 | 4 | import { Box, Steps } from "@kleros/ui-components-library"; |
8 | 5 |
|
| 6 | +import HourglassIcon from "svgs/icons/hourglass.svg"; |
| 7 | + |
9 | 8 | import { Periods } from "consts/periods"; |
| 9 | +import { useCountdownContext, useFundingContext } from "hooks/useClassicAppealContext"; |
10 | 10 | import { useCountdown } from "hooks/useCountdown"; |
11 | 11 | import useIsDesktop from "hooks/useIsDesktop"; |
12 | 12 | import { secondsToDayHourMinute } from "utils/date"; |
13 | 13 |
|
14 | 14 | import { DisputeDetailsQuery } from "queries/useDisputeDetailsQuery"; |
15 | 15 |
|
| 16 | +import { isUndefined } from "src/utils"; |
| 17 | + |
| 18 | +import { landscapeStyle } from "styles/landscapeStyle"; |
| 19 | +import { responsiveSize } from "styles/responsiveSize"; |
| 20 | + |
16 | 21 | import { StyledSkeleton } from "components/StyledSkeleton"; |
17 | 22 |
|
18 | 23 | const TimeLineContainer = styled(Box)` |
@@ -43,19 +48,56 @@ const StyledSteps = styled(Steps)` |
43 | 48 | )} |
44 | 49 | `; |
45 | 50 |
|
| 51 | +const AppealBannerContainer = styled.div` |
| 52 | + background-color: ${({ theme }) => theme.whiteBackground}; |
| 53 | + border-radius: 3px; |
| 54 | + margin-top: 16px; |
| 55 | + padding: 12px; |
| 56 | + display: flex; |
| 57 | + gap: 8px; |
| 58 | + align-items: center; |
| 59 | + justify-content: center; |
| 60 | + & > svg { |
| 61 | + width: 14px; |
| 62 | + fill: ${({ theme }) => theme.secondaryPurple}; |
| 63 | + } |
| 64 | +`; |
| 65 | + |
46 | 66 | const Timeline: React.FC<{ |
47 | 67 | dispute: DisputeDetailsQuery["dispute"]; |
48 | 68 | currentPeriodIndex: number; |
49 | 69 | }> = ({ currentPeriodIndex, dispute }) => { |
50 | 70 | const currentItemIndex = currentPeriodToCurrentItem(currentPeriodIndex, dispute?.court.hiddenVotes); |
51 | 71 | const items = useTimeline(dispute, currentItemIndex, currentItemIndex); |
| 72 | + |
52 | 73 | return ( |
53 | 74 | <TimeLineContainer> |
54 | 75 | <StyledSteps horizontal {...{ items, currentItemIndex, currentPeriodIndex }} /> |
| 76 | + {currentPeriodIndex === Periods.appeal ? <AppealBanner /> : null} |
55 | 77 | </TimeLineContainer> |
56 | 78 | ); |
57 | 79 | }; |
58 | 80 |
|
| 81 | +const AppealBanner: React.FC = () => { |
| 82 | + const { loserSideCountdown, winnerSideCountdown } = useCountdownContext(); |
| 83 | + const { fundedChoices } = useFundingContext(); |
| 84 | + |
| 85 | + const text = useMemo(() => { |
| 86 | + if (loserSideCountdown) |
| 87 | + return `${secondsToDayHourMinute(loserSideCountdown)} left until losing options can be funded`; |
| 88 | + // only show if loosing option was funded and winner needs funding, else no action is needed from user |
| 89 | + if (winnerSideCountdown && !isUndefined(fundedChoices) && fundedChoices.length > 0) |
| 90 | + return `${secondsToDayHourMinute(winnerSideCountdown)} left until winning option can be funded`; |
| 91 | + return; |
| 92 | + }, [loserSideCountdown, winnerSideCountdown, fundedChoices]); |
| 93 | + |
| 94 | + return text ? ( |
| 95 | + <AppealBannerContainer> |
| 96 | + <HourglassIcon /> <small>{text}</small> |
| 97 | + </AppealBannerContainer> |
| 98 | + ) : null; |
| 99 | +}; |
| 100 | + |
59 | 101 | const currentPeriodToCurrentItem = (currentPeriodIndex: number, hiddenVotes?: boolean): number => { |
60 | 102 | if (hiddenVotes) return currentPeriodIndex; |
61 | 103 | if (currentPeriodIndex <= Periods.commit) return currentPeriodIndex; |
|
0 commit comments