Skip to content
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

dApp: Action duration estimation & validation #790

Merged
merged 7 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading