Skip to content

Commit

Permalink
Merge pull request #447 from lidofinance/feature/si-1533-add-hover-on…
Browse files Browse the repository at this point in the history
…-ledger-live-if-try-to-click-on-disabled-request

feat: ledger live claim tooltip
  • Loading branch information
Vorobeyko authored Sep 5, 2024
2 parents 6a54a3c + 160c22d commit 65de0c4
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ import {
} from './use-default-values';
import { ClaimFormHelperState, useHelperState } from './use-helper-state';

type ClaimFormDataContextValueType = ClaimFormHelperState;
type ClaimFormDataContextValueType = ClaimFormHelperState & {
maxSelectedCountReason: string | null;
};

const claimFormDataContext =
createContext<ClaimFormDataContextValueType | null>(null);
Expand All @@ -43,8 +45,11 @@ export const ClaimFormProvider: FC<PropsWithChildren> = ({ children }) => {
const { isDappActive } = useDappStatus();
const { data } = useClaimData();

const { maxSelectedRequestCount, defaultSelectedRequestCount } =
useMaxSelectedCount();
const {
maxSelectedRequestCount,
defaultSelectedRequestCount,
maxSelectedCountReason,
} = useMaxSelectedCount();
const { getDefaultValues } = useGetDefaultValues(defaultSelectedRequestCount);

const formObject = useForm<ClaimFormInputType, ClaimFormValidationContext>({
Expand All @@ -55,10 +60,14 @@ export const ClaimFormProvider: FC<PropsWithChildren> = ({ children }) => {
reValidateMode: 'onChange',
});
const { watch, reset, setValue, getValues, formState } = formObject;
const claimFormDataContextValue = useHelperState(
watch,
maxSelectedRequestCount,

const helperState = useHelperState(watch, maxSelectedRequestCount);

const claimFormDataContextValue = useMemo(
() => ({ ...helperState, maxSelectedCountReason }),
[helperState, maxSelectedCountReason],
);

const { retryEvent, retryFire } = useFormControllerRetry();

const claim = useClaim({ onRetry: retryFire });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ export const useMaxSelectedCount = () => {
DEFAULT_CLAIM_REQUEST_SELECTED,
maxSelectedRequestCount,
);

const maxSelectedCountReason = isLedgerLive
? 'Ledger Clear Sign allows to claim up to 2 requests per transaction'
: null;

return {
maxSelectedRequestCount,
defaultSelectedRequestCount,
maxSelectedCountReason,
};
};
27 changes: 24 additions & 3 deletions features/withdrawals/claim/form/requests-list/request-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { forwardRef } from 'react';
import { useFormState, useWatch } from 'react-hook-form';
import { useAccount } from 'wagmi';

import { Checkbox, CheckboxProps, External } from '@lidofinance/lido-ui';
import {
Checkbox,
CheckboxProps,
External,
Tooltip,
} from '@lidofinance/lido-ui';
import { FormatToken } from 'shared/formatters';

import { RequestStatus } from './request-item-status';
Expand All @@ -21,7 +26,7 @@ export const RequestItem = forwardRef<HTMLInputElement, RequestItemProps>(
({ token_id, name, disabled, index, ...props }, ref) => {
const { chainId } = useAccount();
const { isSubmitting } = useFormState();
const { canSelectMore } = useClaimFormData();
const { canSelectMore, maxSelectedCountReason } = useClaimFormData();
const { checked, status } = useWatch<
ClaimFormInputType,
`requests.${number}`
Expand All @@ -42,15 +47,23 @@ export const RequestItem = forwardRef<HTMLInputElement, RequestItemProps>(
: status.amountOfStETH;
const symbol = isClaimable ? 'ETH' : 'stETH';

const showDisabledReasonTooltip =
maxSelectedCountReason &&
!canSelectMore &&
status.isFinalized &&
!checked;

const label = (
<FormatToken
data-testid="requestAmount"
amount={amountValue}
symbol={symbol}
// prevents tip overlap
showAmountTip={!showDisabledReasonTooltip}
/>
);

return (
const requestBody = (
<RequestStyled data-testid={'requestItem'} $disabled={isDisabled}>
<Checkbox
{...props}
Expand All @@ -72,5 +85,13 @@ export const RequestItem = forwardRef<HTMLInputElement, RequestItemProps>(
</LinkStyled>
</RequestStyled>
);

return showDisabledReasonTooltip ? (
<Tooltip title={maxSelectedCountReason} placement="top">
{requestBody}
</Tooltip>
) : (
requestBody
);
},
);
1 change: 1 addition & 0 deletions features/withdrawals/withdrawals-constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// max requests count for one tx
export const MAX_REQUESTS_COUNT = 256;
// Leger Clear Sign only allows 2 requests per claim
export const MAX_REQUESTS_COUNT_LEDGER_LIMIT = 2;

export const DEFAULT_CLAIM_REQUEST_SELECTED = 80;
Expand Down

0 comments on commit 65de0c4

Please sign in to comment.