-
Notifications
You must be signed in to change notification settings - Fork 49
Maintenance buttons at arbitrator-level #1668
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
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
58cc149
feat(web): arbitrator-lvl-dev-buttons
tractorss 46b7260
refactor(web): remove-log
tractorss 0b4f7da
chore: version bump
jaybuidl 9fa4148
Merge branch 'dev' into feat/arbitrator-dev-buttons
jaybuidl 1e8cd15
refactor(web): move-maintenance-button-to-top
tractorss ec0e43f
refactor(web): abstract-phase-component
tractorss 5d9bf8e
refactor(web): better-type-handling-for-is-drawn-variable
tractorss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import React from "react"; | ||
import styled, { css, keyframes } from "styled-components"; | ||
|
||
import DottedMenu from "svgs/icons/dotted-menu.svg"; | ||
|
||
const ripple = keyframes` | ||
0% { | ||
opacity: 0; | ||
transform: scale3d(0.5, 0.5, 1); | ||
} | ||
10% { | ||
opacity: 0.5; | ||
transform: scale3d(0.75, 0.75, 1); | ||
} | ||
|
||
100% { | ||
opacity: 0; | ||
transform: scale3d(1.75, 1.75, 1); | ||
} | ||
`; | ||
|
||
const ring = (duration: string, delay: string) => css` | ||
opacity: 0; | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
transform: translate(50%); | ||
content: ""; | ||
height: 100%; | ||
width: 100%; | ||
border: 3px solid ${({ theme }) => theme.primaryBlue}; | ||
border-radius: 100%; | ||
animation-name: ${ripple}; | ||
animation-duration: ${duration}; | ||
animation-delay: ${delay}; | ||
animation-iteration-count: infinite; | ||
animation-timing-function: cubic-bezier(0.65, 0, 0.34, 1); | ||
z-index: 0; | ||
`; | ||
|
||
const Container = styled.div<{ displayRipple: boolean }>` | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
width: 36px; | ||
height: 36px; | ||
${({ displayRipple }) => | ||
displayRipple && | ||
css` | ||
&::after { | ||
${ring("3s", "0s")} | ||
} | ||
&::before { | ||
${ring("3s", "0.5s")} | ||
} | ||
`} | ||
`; | ||
|
||
const ButtonContainer = styled.div` | ||
border-radius: 50%; | ||
z-index: 1; | ||
background-color: ${({ theme }) => theme.lightBackground}; | ||
`; | ||
|
||
const StyledDottedMenu = styled(DottedMenu)` | ||
cursor: pointer; | ||
width: 100%; | ||
height: 100%; | ||
fill: ${({ theme }) => theme.primaryBlue}; | ||
`; | ||
|
||
interface IMenuButton { | ||
toggle: () => void; | ||
displayRipple: boolean; | ||
className?: string; | ||
} | ||
|
||
const DottedMenuButton: React.FC<IMenuButton> = ({ toggle, displayRipple, className }) => { | ||
return ( | ||
<Container {...{ displayRipple, className }}> | ||
<ButtonContainer className="button-container"> | ||
<StyledDottedMenu onClick={toggle} className="menu-icon" /> | ||
</ButtonContainer> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default DottedMenuButton; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
web/src/pages/Courts/CourtDetails/StakeMaintenanceButton/ExecuteDelayedStakeButton.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import React, { useMemo, useState } from "react"; | ||
import styled from "styled-components"; | ||
|
||
import { usePublicClient } from "wagmi"; | ||
|
||
import { Button } from "@kleros/ui-components-library"; | ||
|
||
import { | ||
useReadSortitionModuleDelayedStakeReadIndex, | ||
useReadSortitionModuleDelayedStakeWriteIndex, | ||
useSimulateSortitionModuleExecuteDelayedStakes, | ||
useWriteSortitionModuleExecuteDelayedStakes, | ||
} from "hooks/contracts/generated"; | ||
import { useSortitionModulePhase } from "hooks/useSortitionModulePhase"; | ||
import { wrapWithToast } from "utils/wrapWithToast"; | ||
|
||
import { isUndefined } from "src/utils"; | ||
|
||
import { IBaseStakeMaintenanceButton, Phases } from "."; | ||
|
||
const StyledButton = styled(Button)` | ||
width: 100%; | ||
`; | ||
|
||
type IExecuteStakeDelayedButton = IBaseStakeMaintenanceButton; | ||
|
||
const ExecuteDelayedStakeButton: React.FC<IExecuteStakeDelayedButton> = ({ setIsOpen }) => { | ||
const [isSending, setIsSending] = useState(false); | ||
const publicClient = usePublicClient(); | ||
const { data: phase } = useSortitionModulePhase(); | ||
const { data: delayedStakeWriteIndex } = useReadSortitionModuleDelayedStakeWriteIndex(); | ||
const { data: delayedStakeReadIndex } = useReadSortitionModuleDelayedStakeReadIndex(); | ||
|
||
const canExecute = useMemo(() => { | ||
if (isUndefined(phase) || isUndefined(delayedStakeReadIndex) || isUndefined(delayedStakeWriteIndex)) return false; | ||
return phase === Phases.staking && delayedStakeWriteIndex >= delayedStakeReadIndex; | ||
}, [phase, delayedStakeReadIndex, delayedStakeWriteIndex]); | ||
|
||
const { | ||
data: executeDelayedStakeConfig, | ||
isLoading: isLoadingConfig, | ||
isError, | ||
} = useSimulateSortitionModuleExecuteDelayedStakes({ | ||
query: { | ||
enabled: canExecute, | ||
}, | ||
args: [1n + (delayedStakeWriteIndex ?? 0n) - (delayedStakeReadIndex ?? 0n)], | ||
}); | ||
|
||
const { writeContractAsync: executeDelayedStake } = useWriteSortitionModuleExecuteDelayedStakes(); | ||
|
||
const isLoading = useMemo(() => isLoadingConfig || isSending, [isLoadingConfig, isSending]); | ||
const isDisabled = useMemo(() => isError || isLoading || !canExecute, [isError, isLoading, canExecute]); | ||
const handleClick = () => { | ||
if (!executeDelayedStakeConfig || !publicClient || !executeDelayedStake) return; | ||
|
||
setIsSending(true); | ||
|
||
wrapWithToast(async () => await executeDelayedStake(executeDelayedStakeConfig.request), publicClient).finally( | ||
() => { | ||
setIsSending(false); | ||
setIsOpen(false); | ||
} | ||
); | ||
}; | ||
return ( | ||
<StyledButton | ||
text="Execute Delayed Stakes" | ||
small | ||
isLoading={isLoading} | ||
disabled={isDisabled} | ||
onClick={handleClick} | ||
/> | ||
); | ||
}; | ||
|
||
export default ExecuteDelayedStakeButton; |
86 changes: 86 additions & 0 deletions
86
web/src/pages/Courts/CourtDetails/StakeMaintenanceButton/PassPhaseButton.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import React, { useMemo, useState } from "react"; | ||
import styled from "styled-components"; | ||
|
||
import { usePublicClient } from "wagmi"; | ||
|
||
import { Button } from "@kleros/ui-components-library"; | ||
|
||
import { | ||
useReadSortitionModuleDisputesWithoutJurors, | ||
useReadSortitionModuleLastPhaseChange, | ||
useReadSortitionModuleMaxDrawingTime, | ||
useReadSortitionModuleMinStakingTime, | ||
useSimulateSortitionModulePassPhase, | ||
useWriteSortitionModulePassPhase, | ||
} from "hooks/contracts/generated"; | ||
import { useSortitionModulePhase } from "hooks/useSortitionModulePhase"; | ||
import { wrapWithToast } from "utils/wrapWithToast"; | ||
|
||
import { isUndefined } from "src/utils"; | ||
|
||
import { IBaseStakeMaintenanceButton, Phases } from "."; | ||
|
||
const StyledButton = styled(Button)` | ||
width: 100%; | ||
`; | ||
|
||
type IPassPhaseButton = IBaseStakeMaintenanceButton; | ||
|
||
const PassPhaseButton: React.FC<IPassPhaseButton> = ({ setIsOpen }) => { | ||
const [isSending, setIsSending] = useState(false); | ||
const publicClient = usePublicClient(); | ||
const { data: phase } = useSortitionModulePhase(); | ||
const { data: lastPhaseChange } = useReadSortitionModuleLastPhaseChange(); | ||
const { data: minStakingTime } = useReadSortitionModuleMinStakingTime(); | ||
const { data: maxDrawingTime } = useReadSortitionModuleMaxDrawingTime(); | ||
const { data: disputeWithoutJurors } = useReadSortitionModuleDisputesWithoutJurors(); | ||
|
||
const canChangePhase = useMemo(() => { | ||
if ( | ||
isUndefined(phase) || | ||
isUndefined(lastPhaseChange) || | ||
isUndefined(minStakingTime) || | ||
isUndefined(maxDrawingTime) || | ||
isUndefined(disputeWithoutJurors) | ||
) | ||
return false; | ||
|
||
const now = Math.floor(Date.now() / 1000); | ||
switch (phase) { | ||
case Phases.staking: | ||
return BigInt(now) - lastPhaseChange >= minStakingTime; | ||
case Phases.drawing: | ||
return disputeWithoutJurors === 0n || BigInt(now) - lastPhaseChange >= maxDrawingTime; | ||
default: | ||
return true; | ||
} | ||
}, [phase, lastPhaseChange, minStakingTime, maxDrawingTime, disputeWithoutJurors]); | ||
|
||
const { | ||
data: passPhaseConfig, | ||
isLoading: isLoadingConfig, | ||
isError, | ||
} = useSimulateSortitionModulePassPhase({ | ||
query: { | ||
enabled: canChangePhase, | ||
}, | ||
}); | ||
|
||
const { writeContractAsync: passPhase } = useWriteSortitionModulePassPhase(); | ||
|
||
const isLoading = useMemo(() => isLoadingConfig || isSending, [isLoadingConfig, isSending]); | ||
const isDisabled = useMemo(() => isError || isLoading || !canChangePhase, [isError, isLoading, canChangePhase]); | ||
const handleClick = () => { | ||
if (!passPhaseConfig || !publicClient || !passPhase) return; | ||
|
||
setIsSending(true); | ||
|
||
wrapWithToast(async () => await passPhase(passPhaseConfig.request), publicClient).finally(() => { | ||
setIsSending(false); | ||
setIsOpen(false); | ||
}); | ||
}; | ||
return <StyledButton text="Pass Phase" small isLoading={isLoading} disabled={isDisabled} onClick={handleClick} />; | ||
}; | ||
|
||
export default PassPhaseButton; |
84 changes: 84 additions & 0 deletions
84
web/src/pages/Courts/CourtDetails/StakeMaintenanceButton/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import React, { useState } from "react"; | ||
import styled from "styled-components"; | ||
|
||
import DottedMenuButton from "components/DottedMenuButton"; | ||
import { EnsureChain } from "components/EnsureChain"; | ||
import { Overlay } from "components/Overlay"; | ||
import { Phase } from "layout/Header/navbar/Debug"; | ||
|
||
import ExecuteDelayedStakeButton from "./ExecuteDelayedStakeButton"; | ||
import PassPhaseButton from "./PassPhaseButton"; | ||
|
||
const Container = styled.div` | ||
width: 36px; | ||
height: 36px; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
position: relative; | ||
`; | ||
|
||
const PopupContainer = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
position: absolute; | ||
height: fit-content; | ||
overflow-y: auto; | ||
z-index: 31; | ||
padding: 27px; | ||
gap: 16px; | ||
border: 1px solid ${({ theme }) => theme.stroke}; | ||
background-color: ${({ theme }) => theme.whiteBackground}; | ||
border-radius: 3px; | ||
box-shadow: 0px 2px 3px rgba(0, 0, 0, 0.06); | ||
|
||
bottom: 0; | ||
left: 0; | ||
transform: translate(-100%, 100%); | ||
`; | ||
|
||
const StyledDottedMenu = styled(DottedMenuButton)` | ||
.button-container { | ||
background-color: ${({ theme }) => theme.whiteBackground}; | ||
} | ||
`; | ||
|
||
export enum Phases { | ||
staking, | ||
generating, | ||
drawing, | ||
} | ||
|
||
export interface IBaseStakeMaintenanceButton { | ||
setIsOpen: (open: boolean) => void; | ||
} | ||
|
||
interface IStakeMaintenanceButtons { | ||
className?: string; | ||
} | ||
const StakeMaintenanceButtons: React.FC<IStakeMaintenanceButtons> = ({ className }) => { | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
const toggle = () => setIsOpen((prevValue) => !prevValue); | ||
return ( | ||
<Container {...{ className }}> | ||
{isOpen ? ( | ||
<> | ||
<Overlay onClick={() => setIsOpen(false)} /> | ||
<PopupContainer> | ||
<EnsureChain> | ||
<> | ||
<Phase /> | ||
<PassPhaseButton {...{ setIsOpen }} /> | ||
<ExecuteDelayedStakeButton {...{ setIsOpen }} /> | ||
</> | ||
</EnsureChain> | ||
</PopupContainer> | ||
</> | ||
) : null} | ||
<StyledDottedMenu {...{ toggle }} displayRipple={false} /> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default StakeMaintenanceButtons; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.