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

Feature/staking form ux improvements fixes #666

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
4 changes: 1 addition & 3 deletions src/components/Forms/TokenAmountForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export type TokenAmountFormBaseProps = {
isDisabled?: boolean
shouldValidateForm?: boolean
shouldDisplayMaxAmountInLabel?: boolean
shouldDisableButton?: boolean
token?: { decimals: number; symbol: string }
placeholder?: string
minTokenAmount?: string | number
Expand All @@ -44,7 +43,6 @@ export const TokenAmountFormBase: FC<
isDisabled = false,
shouldValidateForm = true,
shouldDisplayMaxAmountInLabel = false,
shouldDisableButton = true,
placeholder,
submitButtonVariant = "solid",
...formikProps
Expand Down Expand Up @@ -81,7 +79,7 @@ export const TokenAmountFormBase: FC<
mt="6"
submitText={submitButtonText}
variant={submitButtonVariant}
isDisabled={shouldDisableButton && isDisabled}
isDisabled={isDisabled}
/>
</Form>
)
Expand Down
4 changes: 2 additions & 2 deletions src/components/StakingApplicationForms/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FormikErrors, FormikProps, withFormik } from "formik"
import { FC, Ref, useEffect, useState } from "react"
import { formatTokenAmount } from "../../utils/formatAmount"
import {
defaultStakingLessThanMessage,
defaultLessThanMessage,
defaultAmountValidationOptions,
DEFAULT_MIN_VALUE,
getErrorsObj,
Expand Down Expand Up @@ -150,7 +150,7 @@ const deauthorizationValidation = (
{
...defaultAmountValidationOptions,
lessThanValidationMessage(amount) {
return `${defaultStakingLessThanMessage(
return `${defaultLessThanMessage(
amount
)} or equal to ${formatTokenAmount(authorizedAmount.toString())} T`
},
Expand Down
1 change: 1 addition & 0 deletions src/components/SubmitTxButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const SubmitTxButton: FC<Props> = ({
onClick={() => openModal(ModalType.SelectWallet)}
{...buttonProps}
type="button"
isDisabled={false}
>
Connect Wallet
</Button>
Expand Down
5 changes: 2 additions & 3 deletions src/pages/Staking/NewStakeCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const NewStakeCard: FC<ComponentProps<typeof Card>> = () => {
const { openModal } = useModal()
const tBalance = useTokenBalance(Token.T)
const { minStakeAmount, isLoading, hasError } = useMinStakeAmount()
const { active: isWalletConnected } = useWeb3React()
const { active } = useWeb3React()

const openStakingModal = async (stakeAmount: string) => {
openModal(ModalType.StakingChecklist, { stakeAmount })
Expand Down Expand Up @@ -41,8 +41,7 @@ const NewStakeCard: FC<ComponentProps<typeof Card>> = () => {
maxTokenAmount={tBalance}
placeholder={placeholder}
minTokenAmount={minStakeAmount}
shouldDisableButton={false}
isDisabled={!isWalletConnected}
isDisabled={!active}
/>
<StakingContractLearnMore mt="3" />
</Card>
Expand Down
18 changes: 11 additions & 7 deletions src/utils/forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,25 @@ type AmountValidationOptions = {
}
export const DEFAULT_MIN_VALUE = WeiPerEther.toString()

export const defaultStakingLessThanMessage: (maxAmount: string) => string = (
export const defaultLessThanMessage: (maxAmount: string) => string = (
maxAmount
) => {
return `The maximum stake amount is ${formatTokenAmount(maxAmount)}.`
return `The value should be less than or equal ${formatTokenAmount(
maxAmount
)}`
}

export const defaultStakingGreaterThanMessage: (minAmount: string) => string = (
export const defaultGreaterThanMessage: (minAmount: string) => string = (
minAmount
) => {
return `The minimum stake amount is ${formatTokenAmount(minAmount)}.`
return `The value should be greater than or equal ${formatTokenAmount(
minAmount
)}`
}
export const defaultAmountValidationOptions: AmountValidationOptions = {
greaterThanValidationMessage: defaultStakingGreaterThanMessage,
lessThanValidationMessage: defaultStakingLessThanMessage,
requiredMessage: "The stake amount is required.",
greaterThanValidationMessage: defaultGreaterThanMessage,
lessThanValidationMessage: defaultLessThanMessage,
requiredMessage: "Required.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this line. Full sentence will be more informative and simply elegant.
Something like "The value is required.". What do you think?

Copy link
Contributor Author

@michalsmiarowski michalsmiarowski Nov 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but from what I see we use such message in other places too. I think it would be best to change it across the whole app.

@SorinQ What do you think? Maybe you could look into the dApp and let me know fi some validation messages could be improved?

insufficientBalanceMessage: "Your wallet balance is insufficient.",
}

Expand Down
Loading