-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from lidofinance/feature/si-582-stake-widget-w…
…rap-page Wrap/Unwrap forms refactor
- Loading branch information
Showing
95 changed files
with
1,971 additions
and
1,492 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
9 changes: 4 additions & 5 deletions
9
...awals/request/form/inputs/input-group.tsx → ...est/form/controls/input-group-request.tsx
This file contains 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 |
---|---|---|
@@ -1,17 +1,16 @@ | ||
import { useTvlMessage } from 'features/withdrawals/hooks'; | ||
import { useFormState } from 'react-hook-form'; | ||
import { InputGroupHookForm } from 'shared/hook-form/controls/input-group-hook-form'; | ||
import { RequestFormInputType } from '../../request-form-context'; | ||
import { InputGroupStyled } from '../styles'; | ||
|
||
export const ErrorMessageInputGroup: React.FC = ({ children }) => { | ||
export const InputGroupRequest: React.FC = ({ children }) => { | ||
const { | ||
errors: { amount: amountError }, | ||
} = useFormState<RequestFormInputType>({ name: 'amount' }); | ||
const { tvlMessage } = useTvlMessage(amountError); | ||
const errorMessage = amountError?.type === 'validate' && amountError.message; | ||
return ( | ||
<InputGroupStyled error={errorMessage} success={tvlMessage} fullwidth> | ||
<InputGroupHookForm errorField="amount" success={tvlMessage}> | ||
{children} | ||
</InputGroupStyled> | ||
</InputGroupHookForm> | ||
); | ||
}; |
This file contains 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
52 changes: 52 additions & 0 deletions
52
features/withdrawals/request/form/controls/submit-button-request.tsx
This file contains 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,52 @@ | ||
import { useWithdrawals } from 'features/withdrawals/contexts/withdrawals-context'; | ||
import { | ||
RequestFormInputType, | ||
useRequestFormData, | ||
} from '../../request-form-context'; | ||
|
||
import { SubmitButtonHookForm } from 'shared/hook-form/controls/submit-button-hook-form'; | ||
import { useFormState } from 'react-hook-form'; | ||
import { isValidationErrorTypeUnhandled } from 'shared/hook-form/validation/validation-error'; | ||
import { useIsMultisig } from 'shared/hooks/useIsMultisig'; | ||
|
||
// conditional render breaks useFormState, so it can't be inside SubmitButton | ||
export const useRequestSubmitButtonProps = (): SubmitButtonRequestProps => { | ||
const { isPaused } = useWithdrawals(); | ||
const { isValidating, isSubmitting, errors } = | ||
useFormState<RequestFormInputType>({ name: ['requests', 'amount'] }); | ||
|
||
return { | ||
loading: isValidating || isSubmitting, | ||
disabled: | ||
isPaused || | ||
(!!errors.amount && !isValidationErrorTypeUnhandled(errors.amount.type)), | ||
}; | ||
}; | ||
|
||
type SubmitButtonRequestProps = { | ||
loading?: boolean; | ||
disabled?: boolean; | ||
}; | ||
|
||
export const SubmitButtonRequest = ({ | ||
loading, | ||
disabled, | ||
}: SubmitButtonRequestProps) => { | ||
const [isMultisig] = useIsMultisig(); | ||
const { isTokenLocked } = useRequestFormData(); | ||
const buttonTitle = isTokenLocked | ||
? `Unlock tokens ${isMultisig ? 'for' : 'and'} withdrawal` | ||
: 'Request withdrawal'; | ||
|
||
return ( | ||
<SubmitButtonHookForm | ||
errorField="amount" | ||
loading={loading} | ||
isLocked={isTokenLocked} | ||
disabled={disabled} | ||
data-testid="requestButton" | ||
> | ||
{buttonTitle} | ||
</SubmitButtonHookForm> | ||
); | ||
}; |
23 changes: 8 additions & 15 deletions
23
...wals/request/form/inputs/amount-input.tsx → ...m/controls/token-amount-input-request.tsx
This file contains 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 |
---|---|---|
@@ -1,42 +1,35 @@ | ||
import { TOKENS } from '@lido-sdk/constants'; | ||
import { InputDecoratorTvlStake } from 'features/withdrawals/shared/input-decorator-tvl-stake'; | ||
import { useController, useWatch } from 'react-hook-form'; | ||
import { InputAmount } from 'shared/forms/components/input-amount'; | ||
import { getTokenDisplayName } from 'utils/getTokenDisplayName'; | ||
|
||
import { | ||
RequestFormInputType, | ||
useRequestFormData, | ||
} from 'features/withdrawals/request/request-form-context'; | ||
import { useTvlMessage } from 'features/withdrawals/hooks/useTvlMessage'; | ||
import { TokenAmountInputHookForm } from 'shared/hook-form/controls/token-amount-input-hook-form'; | ||
|
||
export const AmountInput = () => { | ||
const { balanceSteth, balanceWSteth, isTokenLocked } = useRequestFormData(); | ||
export const TokenAmountInputRequest = () => { | ||
const token = useWatch<RequestFormInputType, 'token'>({ name: 'token' }); | ||
const { maxAmount, isTokenLocked } = useRequestFormData(); | ||
|
||
const { | ||
field, | ||
fieldState: { error }, | ||
} = useController<RequestFormInputType, 'amount'>({ | ||
name: 'amount', | ||
}); | ||
|
||
const { balanceDiff } = useTvlMessage(error); | ||
|
||
const balance = token === TOKENS.STETH ? balanceSteth : balanceWSteth; | ||
|
||
return ( | ||
<InputAmount | ||
fullwidth | ||
error={error?.type === 'validate'} | ||
placeholder="0" | ||
<TokenAmountInputHookForm | ||
fieldName="amount" | ||
token={token} | ||
isLocked={isTokenLocked} | ||
maxValue={balance} | ||
maxValue={maxAmount} | ||
rightDecorator={ | ||
balanceDiff && <InputDecoratorTvlStake tvlDiff={balanceDiff} /> | ||
} | ||
label={`${getTokenDisplayName(token)} amount`} | ||
{...field} | ||
showErrorMessage={false} | ||
/> | ||
); | ||
}; |
14 changes: 14 additions & 0 deletions
14
features/withdrawals/request/form/controls/token-select-request.tsx
This file contains 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,14 @@ | ||
import { | ||
TOKENS, | ||
TokenOption, | ||
TokenSelectHookForm, | ||
} from 'shared/hook-form/controls/token-select-hook-form'; | ||
|
||
const OPTIONS: TokenOption[] = [ | ||
{ token: TOKENS.STETH }, | ||
{ token: TOKENS.WSTETH }, | ||
]; | ||
|
||
export const TokenSelectRequest = () => { | ||
return <TokenSelectHookForm options={OPTIONS} />; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains 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 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 was deleted.
Oops, something went wrong.
Oops, something went wrong.