Skip to content

Commit

Permalink
fix: [lw-11802]: fix e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
vetalcore committed Nov 29, 2024
1 parent c3e5ddc commit dc46640
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 26 deletions.
4 changes: 2 additions & 2 deletions apps/browser-extension-wallet/src/utils/format-number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const formatLocaleNumber = (value: string, decimalPlaces: number = DEFAUL
* @param maxDecimals The maximum number of decimal places to include. Default is 0.
* @returns The formatted number string.
*/
export const formatNumberForDisplay = (value: string, maxDecimals = 0): string => {
export const formatNumberForDisplay = (value?: string, maxDecimals = 0): string => {
if (!value) return '0';
// Remove any character that is not a dot or a number
const parsedStringValue = value.replace(/[^\d.]/g, '');
Expand Down Expand Up @@ -137,7 +137,7 @@ export const handleFormattedValueChange = (
* @param decimals The desired decimal places (default = 2)
* @returns The formatted value with the desired decimals and the unit as a string
*/
export const compactNumberWithUnit = (value: number | string, decimals = DEFAULT_DECIMALS): string => {
export const compactNumberWithUnit = (value?: number | string, decimals = DEFAULT_DECIMALS): string => {
const bigNumberValue = value ? new BigNumber(value) : new BigNumber(0);

if (bigNumberValue.isNaN()) return formatLocaleNumber('0', decimals);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { MAX_NFT_TICKER_LENGTH, MAX_TOKEN_TICKER_LENGTH } from '../../../constan

interface InputFieldActionParams {
id: string;
value: string;
value?: string;
maxDecimals?: number;
}

Expand Down
24 changes: 9 additions & 15 deletions packages/core/src/ui/components/AssetInput/AssetInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { useTranslation } from 'react-i18next';
import cn from 'classnames';
import { CoreTranslationKey } from '@lace/translation';

const isSameNumberFormat = (num1: string, num2: string) => {
const isSameNumberFormat = (num1?: string, num2?: string) => {
if (!num1 || !num2) return false;
const strippedNum = Number(num2?.replace(/,/g, ''));
return Number(num1) === strippedNum;
Expand All @@ -24,8 +24,8 @@ export interface AssetInputProps {
inputId: string;
coin: { id: string; balance: string; src?: string; ticker?: string; shortTicker?: string };
onChange: (args: { value: string; prevValue?: string; id: string; element?: any; maxDecimals?: number }) => void;
onBlur?: (args: { value: string; id: string; maxDecimals?: number }) => void;
onFocus?: (args: { value: string; id: string; maxDecimals?: number }) => void;
onBlur?: (args: { value?: string; id: string; maxDecimals?: number }) => void;
onFocus?: (args: { value?: string; id: string; maxDecimals?: number }) => void;
fiatValue: string;
formattedFiatValue?: string;
value?: string;
Expand Down Expand Up @@ -81,7 +81,7 @@ export const AssetInput = ({
const [isInvalid, setIsInvalid] = useState(invalid);
const [isTouched, setIsTouched] = useState(false);

const adjustInputWidth = useCallback((text: string) => {
const adjustInputWidth = useCallback((text?: string) => {
if (!inputRef?.current?.input) return;
const textWidth = !text || text === '0' ? defaultInputWidth : getTextWidth(text, inputRef.current.input);
const numberOneQuantity = text?.match(/1/g)?.length ?? 0;
Expand Down Expand Up @@ -115,14 +115,14 @@ export const AssetInput = ({
}, [invalid]);

useLayoutEffect(() => {
adjustInputWidth(focused ? displayValue ?? '' : compactValue ?? '');
adjustInputWidth(focused ? displayValue : compactValue);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [adjustInputWidth]);

// eslint-disable-next-line complexity
const setValue = (newValue: string, element?: any) => {
const sanitizedValue = sanitizeNumber(newValue);
const tokenMaxDecimalsOverflow = maxDecimals ?? 0;
const tokenMaxDecimalsOverflow = maxDecimals;
const isValidNumericValue = validateNumericValue(sanitizedValue, {
isFloat: allowFloat,
maxDecimals: tokenMaxDecimalsOverflow?.toString()
Expand Down Expand Up @@ -154,7 +154,7 @@ export const AssetInput = ({

const handleOnBlur = () => {
setIsTouched(true);
const currentValue = value && !Number.parseFloat(value) ? placeholderValue : value ?? '0';
const currentValue = value && !Number.parseFloat(value) ? placeholderValue : value;
onBlur?.({
value: currentValue,
id: coin.id,
Expand All @@ -167,7 +167,7 @@ export const AssetInput = ({
const handleOnFocus = () => {
setFocusInput?.(inputId);
onFocus?.({
value: value ?? placeholderValue,
value,
id: coin.id,
maxDecimals
});
Expand Down Expand Up @@ -207,13 +207,7 @@ export const AssetInput = ({
</div>
)}

<Tooltip
title={
!isSameNumberFormat(value ?? placeholderValue, compactValue ?? placeholderValue) &&
!focused &&
displayValue
}
>
<Tooltip title={!isSameNumberFormat(value, compactValue) && !focused && displayValue}>
<Input
onMouseDown={onClick}
ref={inputRef}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/ui/components/AssetInput/AssetInputRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const AssetInputRow = ({
if (!isInFocusableArea)
// do not apply compact notation in case we are still in the focusable area
onBlur?.({
value: value ?? '0',
value,
id: coin.id,
maxDecimals
});
Expand All @@ -54,7 +54,7 @@ export const AssetInputRow = ({
() => {
setIsFocused(false);
onBlur?.({
value: value ?? '0',
value,
id: coin.id,
maxDecimals
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import CopyToClipboard from 'react-copy-to-clipboard';

const TOAST_DEFAULT_DURATION = 3;

export const CopiableHash = ({ hash, copiedText }: { hash: string; copiedText: string }): React.ReactElement => (
export const CopiableHash = ({ hash = '', copiedText }: { hash?: string; copiedText: string }): React.ReactElement => (
<CopyToClipboard text={hash}>
<div
onClick={() =>
Expand Down
5 changes: 2 additions & 3 deletions packages/core/src/ui/components/Transaction/TxHash.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ type TxHashProps = {
export const TxHash = ({ hash, success, sending, openLink }: TxHashProps): React.ReactElement => {
const { t } = useTranslation();
const hashComponent = useMemo(
() =>
sending && hash ? <CopiableHash hash={hash} copiedText={t('core.activityDetails.copiedToClipboard')} /> : hash,
() => (sending ? <CopiableHash hash={hash} copiedText={t('core.activityDetails.copiedToClipboard')} /> : hash),
[hash, sending, t]
);

Expand All @@ -34,7 +33,7 @@ export const TxHash = ({ hash, success, sending, openLink }: TxHashProps): React
})}
onClick={openLink}
>
{hashComponent && <div>{hashComponent}</div>}
<div>{hashComponent}</div>
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const formatLocaleNumber = (value: string | number, decimalPlaces: number
const formatNumericValue = (
val: number | string,
suffix: number | string,
decimalPlaces: number = DEFAULT_DECIMALS
decimalPlaces: number = DEFAULT_DECIMALS,
): React.ReactElement => (
<>
{val ? formatLocaleNumber(String(val), decimalPlaces) : '-'}
Expand Down Expand Up @@ -77,7 +77,7 @@ export const StakingInfoCard = ({
id,
logo,
margin,
name = '',
name,
totalRewards,
lastReward,
ros,
Expand Down

0 comments on commit dc46640

Please sign in to comment.