Skip to content

Commit

Permalink
Merge branch 'master' into release/v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
aziolek committed Mar 21, 2024
2 parents 7479bfa + 92e7a14 commit 3c5187b
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 25 deletions.
39 changes: 32 additions & 7 deletions client/cypress/e2e/earn.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,43 @@ Object.values(viewports).forEach(({ device, viewportWidth, viewportHeight, isDes
cy.get('[data-test=ModalGlmLock__overflow]').should('exist');
});

it('Wallet connected: Lock 1 GLM', () => {
it('Wallet connected: inputs allow to type multiple characters without focus problems', () => {
/**
* In EarnGlmLock there are multiple autofocus rules set.
* This test checks if user is still able to type without any autofocus disruption.
*/
connectWallet();
cy.get('[data-test=BoxGlmLock__Button]').click();
cy.get('[data-test=ModalGlmLock]').should('be.visible');
cy.get('[data-test=InputsCryptoFiat__InputText--crypto]').should('have.focus');
cy.get('[data-test=InputsCryptoFiat__InputText--crypto]').clear().type('100');
cy.get('[data-test=InputsCryptoFiat__InputText--crypto]').should('have.value', '100');
cy.get('[data-test=EarnGlmLockTabs__tab--1]').click();
cy.get('[data-test=InputsCryptoFiat__InputText--crypto]').clear().type('100');
cy.get('[data-test=InputsCryptoFiat__InputText--crypto]').should('have.value', '100');
});

it('Wallet connected: "ModalGlmLock" - changing tabs keep focus on first input', () => {
connectWallet();
cy.get('[data-test=BoxGlmLock__Button]').click();
cy.get('[data-test=InputsCryptoFiat__InputText--crypto]').blur();
cy.get('[data-test=BudgetBox__currentlyLocked__value]')
cy.get('[data-test=ModalGlmLock]').should('be.visible');
cy.get('[data-test=InputsCryptoFiat__InputText--crypto]').should('have.focus');
cy.get('[data-test=EarnGlmLockTabs__tab--1]').click();
cy.get('[data-test=InputsCryptoFiat__InputText--crypto]').should('have.focus');
cy.get('[data-test=EarnGlmLockTabs__tab--0]').click();
cy.get('[data-test=InputsCryptoFiat__InputText--crypto]').should('have.focus');
});

it('Wallet connected: Lock 1 GLM', () => {
connectWallet();

cy.get('[data-test=BoxGlmLock__Section--current__DoubleValue__primary]')
.invoke('text')
.then(text => {
const amountToLock = 1;
const lockedGlms = parseInt(text, 10);

cy.get('[data-test=BoxGlmLock__Button]').click();
cy.get('[data-test=InputsCryptoFiat__InputText--crypto]').clear().type(`${amountToLock}`);
cy.get('[data-test=GlmLockTabs__Button]').should('have.text', 'Lock');
cy.get('[data-test=GlmLockTabs__Button]').click();
Expand Down Expand Up @@ -142,15 +168,14 @@ Object.values(viewports).forEach(({ device, viewportWidth, viewportHeight, isDes
it('Wallet connected: Unlock 1 GLM', () => {
connectWallet();

cy.get('[data-test=BoxGlmLock__Button]').click();
cy.get('[data-test=InputsCryptoFiat__InputText--crypto]').blur();
cy.get('[data-test=BudgetBox__currentlyLocked__value]')
cy.get('[data-test=BoxGlmLock__Section--current__DoubleValue__primary]')
.invoke('text')
.then(text => {
const amountToUnlock = 1;
const lockedGlms = parseInt(text, 10);

cy.get('[data-test=BoxRounded__tab--1]').click();
cy.get('[data-test=BoxGlmLock__Button]').click();
cy.get('[data-test=EarnGlmLockTabs__tab--1]').click();
cy.get('[data-test=InputsCryptoFiat__InputText--crypto]')
.clear()
.type(`${amountToUnlock}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ const EarnGlmLockTabs: FC<EarnGlmLockTabsProps> = ({
return (
<BoxRounded
className={cx(styles.box, className)}
dataTest="EarnGlmLockTabs"
isGrey
tabs={[
{
Expand Down Expand Up @@ -119,7 +120,6 @@ const EarnGlmLockTabs: FC<EarnGlmLockTabsProps> = ({
error={formik.values.valueToDeposeOrWithdraw && formik.errors.valueToDeposeOrWithdraw}
inputCryptoProps={{
name: 'valueToDeposeOrWithdraw',
onChange: onSetValue,
onClear: formik.resetForm,
suffix: 'GLM',
value: formik.values.valueToDeposeOrWithdraw,
Expand Down Expand Up @@ -155,6 +155,8 @@ const EarnGlmLockTabs: FC<EarnGlmLockTabsProps> = ({
)}
</div>
}
mode={currentMode}
onChange={onSetValue}
onInputsFocusChange={onInputsFocusChange}
/>
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ import EarnGlmLockTabsInputsProps from './types';
const EarnGlmLockTabsInputs = forwardRef<HTMLInputElement, EarnGlmLockTabsInputsProps>(
(
{
error,
label,
inputCryptoProps,
cryptoCurrency,
areInputsDisabled,
cryptoCurrency,
dataTest = 'InputsCryptoFiat',
error,
inputCryptoProps,
label,
mode,
onChange,
onInputsFocusChange = () => {},
},
ref,
Expand All @@ -41,9 +43,9 @@ const EarnGlmLockTabsInputs = forwardRef<HTMLInputElement, EarnGlmLockTabsInputs
const isAnyInputFocused = useDeferredValue(isCryptoInputFocused || isFiatInputFocused);

const inputCryptoPropsLabel = isCryptoMainValueDisplay
? { ...inputCryptoProps, error, label }
? { ...inputCryptoProps, error, label, mode }
: { ...inputCryptoProps, error };
const inputFiatPropsLabel = isCryptoMainValueDisplay ? { error } : { error, label };
const inputFiatPropsLabel = isCryptoMainValueDisplay ? { error } : { error, label, mode };

const cryptoFiatRatio = cryptoValues?.[cryptoCurrency][displayCurrency || 'usd'] || 1;

Expand All @@ -57,7 +59,7 @@ const EarnGlmLockTabsInputs = forwardRef<HTMLInputElement, EarnGlmLockTabsInputs
const cryptoToFiat = valueComma ? (parseFloat(valueComma) * cryptoFiatRatio).toFixed(2) : '';

setFiat(cryptoToFiat);
inputCryptoProps.onChange(valueComma);
onChange(valueComma);
};

const onFiatValueChange = (value: string) => {
Expand All @@ -69,7 +71,7 @@ const EarnGlmLockTabsInputs = forwardRef<HTMLInputElement, EarnGlmLockTabsInputs

const fiatToCrypto = valueComma ? (parseFloat(valueComma) / cryptoFiatRatio).toFixed(18) : '';
setFiat(valueComma);
inputCryptoProps.onChange(fiatToCrypto);
onChange(fiatToCrypto);
};

const handleClear = () => {
Expand Down Expand Up @@ -109,20 +111,23 @@ const EarnGlmLockTabsInputs = forwardRef<HTMLInputElement, EarnGlmLockTabsInputs
<div className={cx(styles.root, isCryptoMainValueDisplay && styles.isCryptoMainValueDisplay)}>
<InputText
ref={isCryptoMainValueDisplay ? ref : undefined}
autocomplete="off"
className={cx(styles.input, isCryptoMainValueDisplay && styles.isCryptoMainValueDisplay)}
dataTest={`${dataTest}__InputText--crypto`}
inputMode="decimal"
placeholder="0.00"
variant="simple"
{...inputCryptoPropsLabel}
autocomplete="off"
isDisabled={areInputsDisabled}
isErrorInlineVisible={false}
onBlur={() => setIsCryptoInputFocused(false)}
onChange={e => onCryptoValueChange(e.target.value)}
onChange={e => {
onCryptoValueChange(e.target.value);
}}
onClear={handleClear}
onFocus={() => setIsCryptoInputFocused(true)}
placeholder="0.00"
shouldAutoFocusAndSelect={isCryptoMainValueDisplay}
shouldAutoFocusAndSelectOnModeChange
variant="simple"
{...inputCryptoPropsLabel}
/>
<InputText
ref={isCryptoMainValueDisplay ? undefined : ref}
Expand All @@ -137,10 +142,11 @@ const EarnGlmLockTabsInputs = forwardRef<HTMLInputElement, EarnGlmLockTabsInputs
onClear={handleClear}
onFocus={() => setIsFiatInputFocused(true)}
placeholder="0.00"
shouldAutoFocusAndSelect={!isCryptoMainValueDisplay}
shouldAutoFocusAndSelectOnModeChange
suffix={displayCurrency.toUpperCase()}
value={fiat}
{...inputFiatPropsLabel}
shouldAutoFocusAndSelect={!isCryptoMainValueDisplay}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CurrentMode } from 'components/Earn/EarnGlmLock/types';
import InputTextProps from 'components/ui/InputText/types';
import { CryptoCurrency } from 'types/cryptoCurrency';

Expand All @@ -8,11 +9,12 @@ export default interface EarnGlmLockTabsInputsProps {
error: string | undefined;
inputCryptoProps: {
name: InputTextProps['name'];
onChange: (value: string) => void;
onClear?: InputTextProps['onClear'];
suffix: InputTextProps['suffix'];
value: InputTextProps['value'];
};
label: InputTextProps['label'];
mode: CurrentMode;
onChange: (value: string) => void;
onInputsFocusChange?: (isAnyInputFocused: boolean) => void;
}
9 changes: 8 additions & 1 deletion client/src/components/ui/InputText/InputText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const InputText = forwardRef<HTMLInputElement, InputTextProps>(
isDisabled,
isErrorInlineVisible = true,
label,
mode,
onChange,
onClear,
suffix,
Expand All @@ -29,6 +30,7 @@ const InputText = forwardRef<HTMLInputElement, InputTextProps>(
showLoader = false,
dataTest = 'InputText',
shouldAutoFocusAndSelect = true,
shouldAutoFocusAndSelectOnModeChange,
...rest
},
ref,
Expand Down Expand Up @@ -63,7 +65,12 @@ const InputText = forwardRef<HTMLInputElement, InputTextProps>(
}
inputRef.current.focus();
inputRef.current.select();
}, [inputProps.ref, shouldAutoFocusAndSelect]);
}, [
inputProps.ref,
shouldAutoFocusAndSelect,
// eslint-disable-next-line react-hooks/exhaustive-deps
...(shouldAutoFocusAndSelectOnModeChange ? [shouldAutoFocusAndSelectOnModeChange, mode] : []),
]);

return (
<div className={cx(styles.root, styles[`variant--${variant}`], className)}>
Expand Down
2 changes: 2 additions & 0 deletions client/src/components/ui/InputText/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ export default interface InputTextProps {
isDisabled?: boolean;
isErrorInlineVisible?: boolean;
label?: string | ReactNode;
mode?: string;
name?: string;
onBlur?: FocusEventHandler<HTMLInputElement>;
onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
onClear?: () => void;
onFocus?: FocusEventHandler<HTMLInputElement>;
placeholder?: string;
shouldAutoFocusAndSelect?: boolean;
shouldAutoFocusAndSelectOnModeChange?: boolean;
showLoader?: boolean;
suffix?: string;
suffixClassName?: string;
Expand Down
13 changes: 12 additions & 1 deletion client/src/components/ui/Slider/Slider.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import cx from 'classnames';
import React, { FC, useState, useEffect } from 'react';
import React, { FC, useState, useEffect, useRef } from 'react';
import ReactSlider from 'react-slider';

import styles from './Slider.module.scss';
Expand All @@ -15,6 +15,7 @@ const Slider: FC<SliderProps> = ({
hideThumb,
...rest
}) => {
const reactSliderRef = useRef(null);
const [localValue, setLocalValue] = useState(value);

useEffect(() => {
Expand All @@ -40,9 +41,19 @@ const Slider: FC<SliderProps> = ({
}
};

useEffect(() => {
if (isDisabled || hideThumb || !reactSliderRef?.current) {
return;
}
// Calling handleResize() method solves the problem with rendering thumb outside the box.
// @ts-expect-error method isn't typed
reactSliderRef.current.handleResize();
}, [isDisabled, hideThumb]);

return (
<div className={cx(styles.root, className)}>
<ReactSlider
ref={reactSliderRef}
className={styles.slider}
disabled={isDisabled || hideThumb}
onChange={localOnChange}
Expand Down

0 comments on commit 3c5187b

Please sign in to comment.