Skip to content

Commit

Permalink
Show alert when trying to Deauth during Taco commitment period
Browse files Browse the repository at this point in the history
  • Loading branch information
theref committed Jan 23, 2024
1 parent 0551ab5 commit a0ed037
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { formatDate } from "../../../../utils/date"
import { calculatePercenteage } from "../../../../utils/percentage"
import { StakingAppForm } from "../../../../components/StakingApplicationForms"
import { AuthorizationStatus } from "../../../../types"
import { StakingProviderInfo } from "../../../../threshold-ts/applications"

interface CommonProps {
stakingAppId: StakingAppName
Expand All @@ -58,6 +59,7 @@ type StakingAppAuthDataBaseProps = {
remainingAuthorizationDecreaseDelay: string
isOperatorInPool: boolean | undefined
operator: string
stakingProviderInfo?: StakingProviderInfo | undefined
}

type AppAuthDataConditionalProps =
Expand Down Expand Up @@ -255,8 +257,26 @@ export const AuthorizeApplicationsCardCheckboxBase: FC<
}

const onSubmitForm = (tokenAmount: string) => {
if (isIncreaseAction) onAuthorizeApp(tokenAmount)
else onInitiateDeauthorization(tokenAmount)
if (isIncreaseAction) {
onAuthorizeApp(tokenAmount)
} else {
if (appAuthData.stakingAppId === "taco") {
// const endCommitment = appAuthData.stakingProviderInfo?.endCommitment
const endCommitment = appAuthData.stakingProviderInfo?.endCommitment
const currentTime = Math.floor(Date.now() / 1000)
const isCommited = (Number(endCommitment) ?? 0) > currentTime
const endCommitmentDate = new Date(
(Number(endCommitment) ?? 0) * 1000
).toLocaleDateString()
if (isCommited) {
alert(`You are still committed until ${endCommitmentDate}.`)
} else {
onInitiateDeauthorization(tokenAmount)
}
} else {
onInitiateDeauthorization(tokenAmount)
}
}
}

const onConfirmDeauthorization = () => {
Expand Down

0 comments on commit a0ed037

Please sign in to comment.