Skip to content

Commit

Permalink
dApp: Action duration estimation & validation (#790)
Browse files Browse the repository at this point in the history
Closes: #789 

### Changes:
- Implemented action duration estimation based on given amount
- Updated form validation strategy to update the state dynamically based
on given value


https://github.com/user-attachments/assets/1893466c-910a-4933-8293-163da9c45f60
  • Loading branch information
kkosiorowska authored Oct 29, 2024
2 parents 2fad5b4 + b7f6dd2 commit e27b651
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
25 changes: 25 additions & 0 deletions dapp/src/components/TransactionModal/ActionDurationEstimation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from "react"
import { ActivityType } from "#/types"
import { getEstimatedDuration } from "#/utils"
import { useFormField } from "#/hooks"
import { TextMd } from "../shared/Typography"
import { TOKEN_AMOUNT_FIELD_NAME } from "../shared/TokenAmountForm/TokenAmountFormBase"

export default function ActionDurationEstimation({
type,
}: {
type: ActivityType
}) {
const { value: amount = 0n } = useFormField<bigint | undefined>(
TOKEN_AMOUNT_FIELD_NAME,
)

return (
<TextMd mt={4} color="grey.400">
Estimated duration&nbsp;
<TextMd as="span" color="grey.500">
~ {getEstimatedDuration(amount, type)}
</TextMd>
</TextMd>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { fixedPointNumberToString, getCurrencyByType } from "#/utils"
import { featureFlags } from "#/constants"
import StakeDetails from "./StakeDetails"
import AcrePointsRewardEstimation from "./AcrePointsRewardEstimation"
import ActionDurationEstimation from "../../ActionDurationEstimation"

function StakeFormModal({
onSubmitForm,
Expand Down Expand Up @@ -35,6 +36,7 @@ function StakeFormModal({
)}
<StakeDetails currency="bitcoin" />
<FormSubmitButton mt={10}>Deposit</FormSubmitButton>
<ActionDurationEstimation type="deposit" />
</TokenAmountForm>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from "#/hooks"
import { fixedPointNumberToString, getCurrencyByType } from "#/utils"
import UnstakeDetails from "./UnstakeDetails"
import ActionDurationEstimation from "../../ActionDurationEstimation"

function UnstakeFormModal({
onSubmitForm,
Expand Down Expand Up @@ -39,6 +40,7 @@ function UnstakeFormModal({
>
<UnstakeDetails balance={balance} currency="bitcoin" />
<FormSubmitButton mt={10}>Withdraw</FormSubmitButton>
<ActionDurationEstimation type="withdraw" />
</TokenAmountForm>
)
}
Expand Down
2 changes: 1 addition & 1 deletion dapp/src/components/shared/TokenAmountForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const TokenAmountForm = withFormik<TokenAmountFormProps, TokenAmountFormValues>(
handleSubmit: (values, { props }) => {
props.onSubmitForm(values)
},
validateOnBlur: false,
validateOnBlur: true,
validateOnChange: false,
},
)(TokenAmountFormBase)
Expand Down

0 comments on commit e27b651

Please sign in to comment.