Skip to content

Commit

Permalink
refactor: fix sonarcloud issues
Browse files Browse the repository at this point in the history
  • Loading branch information
vetalcore committed Nov 25, 2024
1 parent 14263c6 commit 6687d69
Show file tree
Hide file tree
Showing 16 changed files with 38 additions and 51 deletions.
2 changes: 1 addition & 1 deletion apps/browser-extension-wallet/src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"references": [
{ "path": "../../../packages/core/src" },
{ "path": "../../../packages/cardano/src" },
{ "path": "../../../packages/translation/" }
{ "path": "../../../packages/translation/src" }
],
"include": ["**/*", "../test/types/*.d.ts", "**/*.json"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export const StakePoolInfo = ({
onClick?: () => void;
popupView: boolean;
}): React.ReactElement => {
const title = name || ticker || '-';
const subTitle: string | React.ReactElement = ticker || (
const title = name ?? ticker ?? '-';
const subTitle: string | React.ReactElement = ticker ?? (
<Ellipsis className={styles.id} text={id} beforeEllipsis={6} afterEllipsis={8} />
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ export const StakePoolNameBrowser = ({
isOversaturated,
translations
}: StakePoolNameBrowserProps): React.ReactElement => {
const title = name || ticker || '-';
const subTitle: string | React.ReactElement = ticker || (
<Ellipsis className={styles.id} text={id || ''} beforeEllipsis={6} afterEllipsis={8} />
const title = name ?? ticker ?? '-';
const subTitle: string | React.ReactElement = ticker ?? (
<Ellipsis className={styles.id} text={id ?? ''} beforeEllipsis={6} afterEllipsis={8} />
);

return (
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/ui/components/Ellipsis/Ellipsis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const Ellipsis = ({
<div
style={{ ...(ellipsisInTheMiddle && { width: '100%' }) }}
ref={ref}
data-testid={dataTestId || 'ellipsis-container'}
data-testid={dataTestId ?? 'ellipsis-container'}
className={className}
>
{withTooltip && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const TextArea = ({
data-testid={dataTestId}
value={localVal}
autoSize
rows={props.rows || 1}
rows={props.rows ?? 1}
className={cn(styles.textArea, {
...(className && { [className]: className }),
[styles.isResizable]: isResizable,
Expand Down
9 changes: 4 additions & 5 deletions packages/common/src/ui/hooks/useSearchParams.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { useLocation } from 'react-router-dom';

export const useSearchParams = <T extends string>(keys: T[]): Record<T, string> => {
export const useSearchParams = <T extends string>(keys: T[]): Record<T, string | null> => {
const { search } = useLocation();
const urlSearchParams = new URLSearchParams(search);
const searchParams = {} as Record<T, string>;
keys.forEach((key) => {
const paramFound = urlSearchParams.get(key);
if (paramFound) searchParams[key];
const searchParams = {} as Record<T, string | null>;
keys.forEach((key: T) => {
searchParams[key] = urlSearchParams.get(key);
});
return searchParams;
};
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const makeButtons = ({ props, defaultLabel }: MakeButtonsParams) => {
if (!leftButton && 'onBack' in props) {
leftButton = (
<Button.Secondary
label={props.customBackLabel || defaultLabel.back}
label={props.customBackLabel ?? defaultLabel.back}
onClick={props.onBack}
data-testid="shared-wallet-step-btn-back"
/>
Expand All @@ -45,9 +45,9 @@ const makeButtons = ({ props, defaultLabel }: MakeButtonsParams) => {
rightButton = (
<Button.CallToAction
icon={props.isLoading ? <LoadingComponent className={styles.loadingIcon} /> : undefined}
label={props.customNextLabel || defaultLabel.next}
label={props.customNextLabel ?? defaultLabel.next}
onClick={props.onNext}
disabled={!props.isNextEnabled || props.isLoading}
disabled={!props.isNextEnabled ?? props.isLoading}
data-testid="shared-wallet-step-btn-next"
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,14 @@ type ErrorDialogProps = {

export const ErrorDialog: VFC<ErrorDialogProps> = ({ errorKind, onCancel, onConfirm }) => {
const { t } = useTranslation();
const secondaryButton = errorsTranslationKeysMap[errorKind].secondaryButton;

return (
<Dialog.Root open zIndex={1000} setOpen={() => void 0}>
<Dialog.Title>{t(errorsTranslationKeysMap[errorKind].title)}</Dialog.Title>
<Dialog.Description>{t(errorsTranslationKeysMap[errorKind].message)}</Dialog.Description>
<Dialog.Actions>
{errorsTranslationKeysMap[errorKind].secondaryButton && (
<Dialog.Action
cancel
autoFocus
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
label={t(errorsTranslationKeysMap[errorKind].secondaryButton!)}
onClick={onCancel}
/>
)}
{secondaryButton && <Dialog.Action cancel autoFocus label={t(secondaryButton)} onClick={onCancel} />}
<Dialog.Action autoFocus label={t(errorsTranslationKeysMap[errorKind].primaryButton)} onClick={onConfirm} />
</Dialog.Actions>
</Dialog.Root>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export const AssetActivityItem = ({

const assetsIdsText = assets
?.slice(0, items)
.map(({ val, info }) => `${val} ${info?.ticker || '"?"'}`)
.map(({ val, info }) => `${val} ${info?.ticker ?? '"?"'}`)
.join(', ');
const suffix = assets && assets?.length - items > 0 ? `, +${assets.length - items}` : '';
const appendedAssetId = assetsIdsText ? `, ${assetsIdsText}` : '';
Expand Down Expand Up @@ -209,7 +209,7 @@ export const AssetActivityItem = ({
{customIcon ? (
<Image src={customIcon} className={styles.icon} preview={false} alt="asset image" />
) : (
<ActivityStatusIcon status={status ?? ActivityStatus.ERROR} type={type!} />
type && <ActivityStatusIcon status={status ?? ActivityStatus.ERROR} type={type} />
)}
</div>
<div data-testid="asset-info" className={styles.info}>
Expand Down Expand Up @@ -255,7 +255,7 @@ export const AssetActivityItem = ({
{assets
?.slice(assetsToShow, assets.length)
.map(({ id, val, info }) => (
<div key={id} className={styles.tooltipItem}>{`${val} ${info?.ticker || '?'}`}</div>
<div key={id} className={styles.tooltipItem}>{`${val} ${info?.ticker ?? '?'}`}</div>
))}
</>
}
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/ui/components/AssetInput/AssetInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const AssetInput = ({
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;
const numberOneQuantity = text?.match(/1/g)?.length ?? 0;
// cursorBufferWidth - represents a space buffer (in px) between the cursor and particular number char
// for "1" it's approximately 2.4px from each side, for every other - about 0.5px (it might be diff per font type/weight/letter spacing)
// eslint-disable-next-line no-magic-numbers
Expand Down Expand Up @@ -122,7 +122,7 @@ export const AssetInput = ({
// eslint-disable-next-line complexity
const setValue = (newValue: string, element?: any) => {
const sanitizedValue = sanitizeNumber(newValue);
const tokenMaxDecimalsOverflow = maxDecimals || 0;
const tokenMaxDecimalsOverflow = maxDecimals ?? 0;
const isValidNumericValue = validateNumericValue(sanitizedValue, {
isFloat: allowFloat,
maxDecimals: tokenMaxDecimalsOverflow?.toString()
Expand Down Expand Up @@ -185,7 +185,7 @@ export const AssetInput = ({
<div data-testid="coin-configure-info" className={styles.assetConfigRow}>
<div data-testid="coin-configure-text" onClick={onNameClick} className={styles.tickerContainer}>
<Tooltip title={coin?.shortTicker && coin.ticker}>
<span className={styles.ticker}>{coin?.shortTicker || coin?.ticker}</span>
<span className={styles.ticker}>{coin?.shortTicker ?? coin?.ticker}</span>
</Tooltip>
<Chevron className={styles.icon} />
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/ui/components/Nft/NftFolderItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const initialContextMenu = {
const contextMenuWidth = 200;

export const NftFolderItem = ({ name, onClick, nfts, contextMenuItems }: NftFolderItemProps): React.ReactElement => {
const restOfNfts = (nfts?.length || 0) - numberOfNftsToShow + 1;
const restOfNfts = (nfts?.length ?? 0) - numberOfNftsToShow + 1;
const [contextMenu, setContextMenu] = React.useState(initialContextMenu);

const shouldShowCompactNumber = restOfNfts > maxRestOfNftsNumber;
Expand Down
10 changes: 2 additions & 8 deletions packages/core/src/ui/components/Transaction/TxHash.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,8 @@ export const TxHash = ({ hash, success, sending, openLink }: TxHashProps): React
const { t } = useTranslation();
const hashComponent = useMemo(
() =>
hash ? (
sending ? (
<CopiableHash hash={hash} copiedText={t('core.activityDetails.copiedToClipboard')} />
) : (
hash
)
) : undefined,
[hash, sending]
sending && hash ? <CopiableHash hash={hash} copiedText={t('core.activityDetails.copiedToClipboard')} /> : hash,
[hash, sending, t]
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const WalletSetupStepLayout = ({
isHardwareWallet = false
}: WalletSetupStepLayoutProps): React.ReactElement => {
const { t } = useTranslation();
const nextButtonContainerRef = useRef(null);
const nextButtonContainerRef = useRef<HTMLDivElement | null>(null);
const flow = useWalletSetupFlow();

const defaultLabel = {
Expand Down Expand Up @@ -143,23 +143,23 @@ export const WalletSetupStepLayout = ({
<div className={styles.footer} data-testid="wallet-setup-step-footer">
{onBack ? (
<Button color="secondary" onClick={onBack} data-testid="wallet-setup-step-btn-back">
{backLabel || defaultLabel.back}
{backLabel ?? defaultLabel.back}
</Button>
) : (
<div />
)}
{stepInfoText && <p data-testid="step-info-text">{stepInfoText}</p>}
{onSkip && (
<Button variant="text" onClick={onSkip} data-testid="wallet-setup-step-btn-skip">
{skipLabel || defaultLabel.skip}
{skipLabel ?? defaultLabel.skip}
</Button>
)}
{onNext && (
<div ref={nextButtonContainerRef}>
<Tooltip
visible={!isNextEnabled && !!toolTipText}
title={!isNextEnabled && toolTipText}
getPopupContainer={() => nextButtonContainerRef.current!}
getPopupContainer={() => nextButtonContainerRef.current as HTMLElement}
autoAdjustOverflow={false}
>
<Button
Expand All @@ -168,7 +168,7 @@ export const WalletSetupStepLayout = ({
loading={isNextLoading}
data-testid="wallet-setup-step-btn-next"
>
{nextLabel || defaultLabel.next}
{nextLabel ?? defaultLabel.next}
</Button>
</Tooltip>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export const WalletSetupStepLayoutRevamp = ({
<div className={styles.footer} data-testid="wallet-setup-step-footer">
{onBack && (
<Button color="secondary" onClick={onBack} data-testid="wallet-setup-step-btn-back">
{backLabel || defaultLabel.back}
{backLabel ?? defaultLabel.back}
</Button>
)}
{customAction}
Expand All @@ -125,7 +125,7 @@ export const WalletSetupStepLayoutRevamp = ({
<Tooltip
open={!isNextEnabled && !!toolTipText}
title={!isNextEnabled && toolTipText}
getPopupContainer={() => nextButtonContainerRef.current!}
getPopupContainer={() => nextButtonContainerRef.current as HTMLElement}
autoAdjustOverflow={false}
>
<Button
Expand All @@ -134,7 +134,7 @@ export const WalletSetupStepLayoutRevamp = ({
loading={isNextLoading}
data-testid="wallet-setup-step-btn-next"
>
{nextLabel || defaultLabel.next}
{nextLabel ?? defaultLabel.next}
</Button>
</Tooltip>
</span>
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/ui/utils/password-complexity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const passwordComplexity = (password?: string): { feedbackKeys: string[];

const { feedback, score } = zxcvbn(password);
const translationFeedbackKeyList = feedback.suggestions
.map((text) => translationKeysMap.get(text) || translationKeysMap.get(defaultKey))
.map((text) => translationKeysMap.get(text) ?? translationKeysMap.get(defaultKey))
// eslint-disable-next-line unicorn/no-array-callback-reference
.filter(isNotNil);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export const StakePoolInfo = ({
id: string;
onClick?: () => void;
}): React.ReactElement => {
const title = name || ticker || '-';
const subTitle: string | React.ReactElement = ticker || (
const title = name ?? ticker ?? '-';
const subTitle: string | React.ReactElement = ticker ?? (
<Ellipsis className={styles.id} text={id} beforeEllipsis={6} afterEllipsis={8} />
);

Expand Down

0 comments on commit 6687d69

Please sign in to comment.