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

Input warning highlight for wrapEth #247

Merged
merged 8 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
22 changes: 22 additions & 0 deletions features/wsteth/wrap/wrap-form-controls/input-group-wrap.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useWatch } from 'react-hook-form';
import { InputGroupHookForm } from 'shared/hook-form/controls/input-group-hook-form';
import { useStakingLimitWarning } from 'shared/hooks/use-staking-limit-warning';
import { WrapFormInputType, useWrapFormData } from '../wrap-form-context';
import { TokenAmountInputWrap } from './token-amount-input-wrap';
import { TokenSelectWrap } from './token-select-wrap';

export const InputGroupWrap: React.FC = () => {
const token = useWatch<WrapFormInputType, 'token'>({ name: 'token' });
const { stakeLimitInfo } = useWrapFormData();
const { limitWarning } = useStakingLimitWarning(
stakeLimitInfo?.stakeLimitLevel,
);
const hasWarning = !!(token === 'ETH' && limitWarning);
const warningText = hasWarning ? limitWarning : null;
return (
<InputGroupHookForm warning={warningText} errorField="amount">
<TokenSelectWrap warning={hasWarning} />
<TokenAmountInputWrap warning={hasWarning} />
</InputGroupHookForm>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ import { useWatch } from 'react-hook-form';
import { useWrapFormData, WrapFormInputType } from '../wrap-form-context';

import { TokenAmountInputHookForm } from 'shared/hook-form/controls/token-amount-input-hook-form';
import { useStakingLimitWarning } from 'shared/hooks/use-staking-limit-warning';

export const TokenAmountInputWrap = () => {
const token = useWatch<WrapFormInputType, 'token'>({ name: 'token' });
type TokenAmountInputWrapProps = Pick<
React.ComponentProps<typeof TokenAmountInputHookForm>,
'warning'
>;

const { maxAmount, isApprovalNeededBeforeWrap, stakeLimitInfo } =
useWrapFormData();
const { limitWarning } = useStakingLimitWarning(
stakeLimitInfo?.stakeLimitLevel,
);
export const TokenAmountInputWrap = (props: TokenAmountInputWrapProps) => {
const token = useWatch<WrapFormInputType, 'token'>({ name: 'token' });
const { maxAmount, isApprovalNeededBeforeWrap } = useWrapFormData();

return (
<TokenAmountInputHookForm
Expand All @@ -20,8 +19,8 @@ export const TokenAmountInputWrap = () => {
data-testid="wrapInput"
isLocked={isApprovalNeededBeforeWrap}
maxValue={maxAmount}
warning={token === 'ETH' ? limitWarning : null}
showErrorMessage={false}
{...props}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ const OPTIONS = [
},
];

export const TokenSelectWrap = () => {
type TokenSelectWrapProps = Pick<
React.ComponentProps<typeof TokenSelectHookForm>,
'warning'
>;

export const TokenSelectWrap = (props: TokenSelectWrapProps) => {
return (
<TokenSelectHookForm
options={OPTIONS}
Expand All @@ -25,6 +30,7 @@ export const TokenSelectWrap = () => {
: MATOMO_CLICK_EVENTS.wrapTokenSelectSteth),
);
}}
{...props}
/>
);
};
11 changes: 3 additions & 8 deletions features/wsteth/wrap/wrap-form/wrap-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,20 @@ import { WrapBlock } from '../../shared/styles';
import { WrapFormTxModal } from './wrap-form-tx-modal';
import { WrapFormProvider } from '../wrap-form-context/wrap-form-context';
import { FormControllerWrap } from '../wrap-form-controls/form-controller-wrap';
import { TokenSelectWrap } from '../wrap-form-controls/token-select-wrap';
import { TokenAmountInputWrap } from '../wrap-form-controls/token-amount-input-wrap';
import { InputGroupWrap } from '../wrap-form-controls/input-group-wrap';
import { SubmitButtonWrap } from '../wrap-form-controls/submit-button-wrap';

import { TransactionModalProvider } from 'shared/transaction-modal/transaction-modal-context';
import { InputGroupHookForm } from 'shared/hook-form/controls/input-group-hook-form';

import { L2Wsteth } from 'shared/banners/l2-wsteth';
import { MATOMO_CLICK_EVENTS } from 'config';

export const WrapForm: React.FC = memo(() => {
return (
<TransactionModalProvider>
<WrapFormProvider>
<WrapBlock data-testid="wrapForm">
<FormControllerWrap>
<InputGroupHookForm errorField="amount">
<TokenSelectWrap />
<TokenAmountInputWrap />
</InputGroupHookForm>
<InputGroupWrap />
<SubmitButtonWrap />
</FormControllerWrap>
<L2Wsteth matomoEventLink={MATOMO_CLICK_EVENTS.l2BannerWrap} />
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@lidofinance/api-rpc": "^0.39.1",
"@lidofinance/eth-api-providers": "^0.39.1",
"@lidofinance/eth-providers": "^0.39.1",
"@lidofinance/lido-ui": "^3.20.1",
"@lidofinance/lido-ui": "^3.23.0",
"@lidofinance/next-api-wrapper": "^0.39.1",
"@lidofinance/next-ip-rate-limit": "^0.39.1",
"@lidofinance/next-pages": "^0.39.1",
Expand Down
3 changes: 3 additions & 0 deletions shared/hook-form/controls/token-select-hook-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type TokenSelectHookFormProps = {
resetField?: string;
errorField?: string;
onChange?: (value: TOKENS) => void;
warning?: boolean;
};

export const TokenSelectHookForm = ({
Expand All @@ -45,6 +46,7 @@ export const TokenSelectHookForm = ({
resetField = 'amount',
errorField = 'amount',
onChange,
warning,
}: TokenSelectHookFormProps) => {
const { field } = useController<Record<string, TOKENS>>({ name: fieldName });
const { setValue, clearErrors } = useFormContext();
Expand All @@ -56,6 +58,7 @@ export const TokenSelectHookForm = ({
return (
<SelectIcon
{...field}
warning={warning}
icon={iconsMap[field.value]}
data-testid="drop-down"
error={isValidationErrorTypeValidate(errors[errorField]?.type)}
Expand Down
16 changes: 15 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2224,7 +2224,7 @@
resolved "https://registry.yarnpkg.com/@lidofinance/eth-providers/-/eth-providers-0.39.1.tgz#46f4c264da61b2a8c3704ea07fd9088b4de93279"
integrity sha512-XT8Fu3CQbqVayoE01ZFGYwQJte8G4NHg2FD+xxK++Q7C7umfAsU00H68YwnWoQOpOj/DHtnsqItvU0uj0jQ1Zg==

"@lidofinance/lido-ui@^3.18.0", "@lidofinance/lido-ui@^3.20.1":
"@lidofinance/lido-ui@^3.18.0":
version "3.21.0"
resolved "https://registry.yarnpkg.com/@lidofinance/lido-ui/-/lido-ui-3.21.0.tgz#da772e44ca7e96a062187858fe896ebc7e3d5cd1"
integrity sha512-bnyjUs09yVAz1Irw/z3LGIcGudJ4whIJrIJqWWqKpcZB62zQacgueTIEd2ZRgZYDrv2EuVyTsbnnNdw0ly+8ng==
Expand All @@ -2238,6 +2238,20 @@
ua-parser-js "^1.0.35"
use-callback-ref "1.2.5"

"@lidofinance/lido-ui@^3.23.1":
version "3.23.0"
resolved "https://registry.yarnpkg.com/@lidofinance/lido-ui/-/lido-ui-3.23.0.tgz#b62ea16dda33da86279e0d2285e1f5283b215997"
integrity sha512-qSTMtJhlH0/JTqZfDBMRk95fTbU0AGSLPFMCvURD41yF9YboDfTQZcJjbqZHavWvwE55fiJ+BCarH6UaGhPBuA==
dependencies:
"@styled-system/should-forward-prop" "5.1.5"
react-collapsed "3.0.2"
react-jazzicon "^1.0.4"
react-toastify "7.0.4"
react-transition-group "4"
styled-system "5.1.5"
ua-parser-js "^1.0.35"
use-callback-ref "1.2.5"

"@lidofinance/next-api-wrapper@^0.39.1", "@lidofinance/next-api-wrapper@~0.39.1":
version "0.39.1"
resolved "https://registry.yarnpkg.com/@lidofinance/next-api-wrapper/-/next-api-wrapper-0.39.1.tgz#604472a842fa4571c9691fb909685f4d2aaeb65a"
Expand Down
Loading