diff --git a/apps/browser-extension-wallet/src/utils/format-number.ts b/apps/browser-extension-wallet/src/utils/format-number.ts index 1c23f4d32..7acec2dad 100644 --- a/apps/browser-extension-wallet/src/utils/format-number.ts +++ b/apps/browser-extension-wallet/src/utils/format-number.ts @@ -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, ''); @@ -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); diff --git a/apps/browser-extension-wallet/src/views/browser-view/features/send-transaction/components/Form/CoinInput/useSelectedCoins.tsx b/apps/browser-extension-wallet/src/views/browser-view/features/send-transaction/components/Form/CoinInput/useSelectedCoins.tsx index 501aa3f81..b3dc69286 100644 --- a/apps/browser-extension-wallet/src/views/browser-view/features/send-transaction/components/Form/CoinInput/useSelectedCoins.tsx +++ b/apps/browser-extension-wallet/src/views/browser-view/features/send-transaction/components/Form/CoinInput/useSelectedCoins.tsx @@ -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; } diff --git a/packages/core/src/ui/components/AssetInput/AssetInput.tsx b/packages/core/src/ui/components/AssetInput/AssetInput.tsx index b34e38f21..41863fb51 100644 --- a/packages/core/src/ui/components/AssetInput/AssetInput.tsx +++ b/packages/core/src/ui/components/AssetInput/AssetInput.tsx @@ -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; @@ -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; @@ -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; @@ -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() @@ -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, @@ -167,7 +167,7 @@ export const AssetInput = ({ const handleOnFocus = () => { setFocusInput?.(inputId); onFocus?.({ - value: value ?? placeholderValue, + value, id: coin.id, maxDecimals }); @@ -207,13 +207,7 @@ export const AssetInput = ({ )} - + { setIsFocused(false); onBlur?.({ - value: value ?? '0', + value, id: coin.id, maxDecimals }); diff --git a/packages/core/src/ui/components/Transaction/CopiableHash.tsx b/packages/core/src/ui/components/Transaction/CopiableHash.tsx index eac783d61..b0ea98382 100644 --- a/packages/core/src/ui/components/Transaction/CopiableHash.tsx +++ b/packages/core/src/ui/components/Transaction/CopiableHash.tsx @@ -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 => (
diff --git a/packages/core/src/ui/components/Transaction/TxHash.tsx b/packages/core/src/ui/components/Transaction/TxHash.tsx index 314f062be..373231789 100644 --- a/packages/core/src/ui/components/Transaction/TxHash.tsx +++ b/packages/core/src/ui/components/Transaction/TxHash.tsx @@ -14,8 +14,7 @@ type TxHashProps = { export const TxHash = ({ hash, success, sending, openLink }: TxHashProps): React.ReactElement => { const { t } = useTranslation(); const hashComponent = useMemo( - () => - sending && hash ? : hash, + () => (sending ? : hash), [hash, sending, t] ); @@ -34,7 +33,7 @@ export const TxHash = ({ hash, success, sending, openLink }: TxHashProps): React })} onClick={openLink} > - {hashComponent &&
{hashComponent}
} +
{hashComponent}
); diff --git a/packages/staking/src/features/overview/StakingInfoCard/StakingInfoCard.tsx b/packages/staking/src/features/overview/StakingInfoCard/StakingInfoCard.tsx index d9f308f76..51a5e6f2b 100644 --- a/packages/staking/src/features/overview/StakingInfoCard/StakingInfoCard.tsx +++ b/packages/staking/src/features/overview/StakingInfoCard/StakingInfoCard.tsx @@ -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) : '-'} @@ -77,7 +77,7 @@ export const StakingInfoCard = ({ id, logo, margin, - name = '', + name, totalRewards, lastReward, ros,