From 1e203e46a8418834beafe16cf75294a73b20ce4d Mon Sep 17 00:00:00 2001 From: vetalcore Date: Mon, 25 Nov 2024 16:09:44 +0200 Subject: [PATCH] refactor: fix sonarcloud issues --- apps/browser-extension-wallet/src/tsconfig.json | 2 +- .../staking/components/StakingInfo/StakePoolInfo.tsx | 4 ++-- .../StakePoolNameBrowser/StakePoolNameBrowser.tsx | 6 +++--- .../common/src/ui/components/Ellipsis/Ellipsis.tsx | 2 +- .../src/ui/components/Form/TextArea/TextArea.tsx | 2 +- packages/common/src/ui/hooks/useSearchParams.ts | 9 ++++----- .../SharedWalletLayout/SharedWalletLayout.tsx | 4 ++-- .../transaction/CoSignEntry/ErrorDialog.tsx | 12 +++--------- .../src/ui/components/Activity/AssetActivityItem.tsx | 6 +++--- .../core/src/ui/components/AssetInput/AssetInput.tsx | 6 +++--- .../core/src/ui/components/Nft/NftFolderItem.tsx | 2 +- .../core/src/ui/components/Transaction/TxHash.tsx | 10 ++-------- .../components/WalletSetup/WalletSetupStepLayout.tsx | 10 +++++----- .../WalletSetupStepLayoutRevamp.tsx | 6 +++--- packages/core/src/ui/utils/password-complexity.ts | 2 +- .../overview/StakingInfoCard/StakePoolInfo.tsx | 4 ++-- 16 files changed, 37 insertions(+), 50 deletions(-) diff --git a/apps/browser-extension-wallet/src/tsconfig.json b/apps/browser-extension-wallet/src/tsconfig.json index 12a785f08..96a49f509 100644 --- a/apps/browser-extension-wallet/src/tsconfig.json +++ b/apps/browser-extension-wallet/src/tsconfig.json @@ -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"] } diff --git a/apps/browser-extension-wallet/src/views/browser-view/features/staking/components/StakingInfo/StakePoolInfo.tsx b/apps/browser-extension-wallet/src/views/browser-view/features/staking/components/StakingInfo/StakePoolInfo.tsx index 6945dfc44..6ae34dc1c 100644 --- a/apps/browser-extension-wallet/src/views/browser-view/features/staking/components/StakingInfo/StakePoolInfo.tsx +++ b/apps/browser-extension-wallet/src/views/browser-view/features/staking/components/StakingInfo/StakePoolInfo.tsx @@ -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 ?? ( ); diff --git a/packages/cardano/src/ui/components/StakePoolNameBrowser/StakePoolNameBrowser.tsx b/packages/cardano/src/ui/components/StakePoolNameBrowser/StakePoolNameBrowser.tsx index 6681f82b2..b079be83d 100644 --- a/packages/cardano/src/ui/components/StakePoolNameBrowser/StakePoolNameBrowser.tsx +++ b/packages/cardano/src/ui/components/StakePoolNameBrowser/StakePoolNameBrowser.tsx @@ -32,9 +32,9 @@ export const StakePoolNameBrowser = ({ isOversaturated, translations }: StakePoolNameBrowserProps): React.ReactElement => { - const title = name || ticker || '-'; - const subTitle: string | React.ReactElement = ticker || ( - + const title = name ?? ticker ?? '-'; + const subTitle: string | React.ReactElement = ticker ?? ( + ); return ( diff --git a/packages/common/src/ui/components/Ellipsis/Ellipsis.tsx b/packages/common/src/ui/components/Ellipsis/Ellipsis.tsx index 5cead070a..f00eef5cc 100644 --- a/packages/common/src/ui/components/Ellipsis/Ellipsis.tsx +++ b/packages/common/src/ui/components/Ellipsis/Ellipsis.tsx @@ -103,7 +103,7 @@ export const Ellipsis = ({
{withTooltip && ( diff --git a/packages/common/src/ui/components/Form/TextArea/TextArea.tsx b/packages/common/src/ui/components/Form/TextArea/TextArea.tsx index 77c1c3d19..82a15b464 100644 --- a/packages/common/src/ui/components/Form/TextArea/TextArea.tsx +++ b/packages/common/src/ui/components/Form/TextArea/TextArea.tsx @@ -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, diff --git a/packages/common/src/ui/hooks/useSearchParams.ts b/packages/common/src/ui/hooks/useSearchParams.ts index 1fa88cb95..ceda00ae1 100644 --- a/packages/common/src/ui/hooks/useSearchParams.ts +++ b/packages/common/src/ui/hooks/useSearchParams.ts @@ -1,12 +1,11 @@ import { useLocation } from 'react-router-dom'; -export const useSearchParams = (keys: T[]): Record => { +export const useSearchParams = (keys: T[]): Record => { const { search } = useLocation(); const urlSearchParams = new URLSearchParams(search); - const searchParams = {} as Record; - keys.forEach((key) => { - const paramFound = urlSearchParams.get(key); - if (paramFound) searchParams[key]; + const searchParams = {} as Record; + keys.forEach((key: T) => { + searchParams[key] = urlSearchParams.get(key); }); return searchParams; }; diff --git a/packages/core/src/shared-wallets/add-shared-wallet/SharedWalletLayout/SharedWalletLayout.tsx b/packages/core/src/shared-wallets/add-shared-wallet/SharedWalletLayout/SharedWalletLayout.tsx index 1a4d0c949..537171504 100644 --- a/packages/core/src/shared-wallets/add-shared-wallet/SharedWalletLayout/SharedWalletLayout.tsx +++ b/packages/core/src/shared-wallets/add-shared-wallet/SharedWalletLayout/SharedWalletLayout.tsx @@ -33,7 +33,7 @@ const makeButtons = ({ props, defaultLabel }: MakeButtonsParams) => { if (!leftButton && 'onBack' in props) { leftButton = ( @@ -45,7 +45,7 @@ const makeButtons = ({ props, defaultLabel }: MakeButtonsParams) => { rightButton = ( : undefined} - label={props.customNextLabel || defaultLabel.next} + label={props.customNextLabel ?? defaultLabel.next} onClick={props.onNext} disabled={!props.isNextEnabled || props.isLoading} data-testid="shared-wallet-step-btn-next" diff --git a/packages/core/src/shared-wallets/transaction/CoSignEntry/ErrorDialog.tsx b/packages/core/src/shared-wallets/transaction/CoSignEntry/ErrorDialog.tsx index 99f02461c..396ff781b 100644 --- a/packages/core/src/shared-wallets/transaction/CoSignEntry/ErrorDialog.tsx +++ b/packages/core/src/shared-wallets/transaction/CoSignEntry/ErrorDialog.tsx @@ -57,20 +57,14 @@ type ErrorDialogProps = { export const ErrorDialog: VFC = ({ errorKind, onCancel, onConfirm }) => { const { t } = useTranslation(); + const secondaryButton = errorsTranslationKeysMap[errorKind].secondaryButton; + return ( void 0}> {t(errorsTranslationKeysMap[errorKind].title)} {t(errorsTranslationKeysMap[errorKind].message)} - {errorsTranslationKeysMap[errorKind].secondaryButton && ( - - )} + {secondaryButton && } diff --git a/packages/core/src/ui/components/Activity/AssetActivityItem.tsx b/packages/core/src/ui/components/Activity/AssetActivityItem.tsx index 266f54877..d06252990 100644 --- a/packages/core/src/ui/components/Activity/AssetActivityItem.tsx +++ b/packages/core/src/ui/components/Activity/AssetActivityItem.tsx @@ -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}` : ''; @@ -209,7 +209,7 @@ export const AssetActivityItem = ({ {customIcon ? ( asset image ) : ( - + type && )}
@@ -255,7 +255,7 @@ export const AssetActivityItem = ({ {assets ?.slice(assetsToShow, assets.length) .map(({ id, val, info }) => ( -
{`${val} ${info?.ticker || '?'}`}
+
{`${val} ${info?.ticker ?? '?'}`}
))} } diff --git a/packages/core/src/ui/components/AssetInput/AssetInput.tsx b/packages/core/src/ui/components/AssetInput/AssetInput.tsx index ed7d5d7ca..b34e38f21 100644 --- a/packages/core/src/ui/components/AssetInput/AssetInput.tsx +++ b/packages/core/src/ui/components/AssetInput/AssetInput.tsx @@ -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 @@ -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() @@ -185,7 +185,7 @@ export const AssetInput = ({
- {coin?.shortTicker || coin?.ticker} + {coin?.shortTicker ?? coin?.ticker}
diff --git a/packages/core/src/ui/components/Nft/NftFolderItem.tsx b/packages/core/src/ui/components/Nft/NftFolderItem.tsx index 9f4612e25..0cba29a24 100644 --- a/packages/core/src/ui/components/Nft/NftFolderItem.tsx +++ b/packages/core/src/ui/components/Nft/NftFolderItem.tsx @@ -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; diff --git a/packages/core/src/ui/components/Transaction/TxHash.tsx b/packages/core/src/ui/components/Transaction/TxHash.tsx index f56778ed9..314f062be 100644 --- a/packages/core/src/ui/components/Transaction/TxHash.tsx +++ b/packages/core/src/ui/components/Transaction/TxHash.tsx @@ -15,14 +15,8 @@ export const TxHash = ({ hash, success, sending, openLink }: TxHashProps): React const { t } = useTranslation(); const hashComponent = useMemo( () => - hash ? ( - sending ? ( - - ) : ( - hash - ) - ) : undefined, - [hash, sending] + sending && hash ? : hash, + [hash, sending, t] ); return ( diff --git a/packages/core/src/ui/components/WalletSetup/WalletSetupStepLayout.tsx b/packages/core/src/ui/components/WalletSetup/WalletSetupStepLayout.tsx index a94bcc8d4..3e8c724e3 100644 --- a/packages/core/src/ui/components/WalletSetup/WalletSetupStepLayout.tsx +++ b/packages/core/src/ui/components/WalletSetup/WalletSetupStepLayout.tsx @@ -102,7 +102,7 @@ export const WalletSetupStepLayout = ({ isHardwareWallet = false }: WalletSetupStepLayoutProps): React.ReactElement => { const { t } = useTranslation(); - const nextButtonContainerRef = useRef(null); + const nextButtonContainerRef = useRef(null); const flow = useWalletSetupFlow(); const defaultLabel = { @@ -143,7 +143,7 @@ export const WalletSetupStepLayout = ({
{onBack ? ( ) : (
@@ -151,7 +151,7 @@ export const WalletSetupStepLayout = ({ {stepInfoText &&

{stepInfoText}

} {onSkip && ( )} {onNext && ( @@ -159,7 +159,7 @@ export const WalletSetupStepLayout = ({ nextButtonContainerRef.current!} + getPopupContainer={() => nextButtonContainerRef.current as HTMLElement} autoAdjustOverflow={false} >
diff --git a/packages/core/src/ui/components/WalletSetupRevamp/WalletSetupStepLayoutRevamp.tsx b/packages/core/src/ui/components/WalletSetupRevamp/WalletSetupStepLayoutRevamp.tsx index e4a3dbee7..47671a200 100644 --- a/packages/core/src/ui/components/WalletSetupRevamp/WalletSetupStepLayoutRevamp.tsx +++ b/packages/core/src/ui/components/WalletSetupRevamp/WalletSetupStepLayoutRevamp.tsx @@ -116,7 +116,7 @@ export const WalletSetupStepLayoutRevamp = ({
{onBack && ( )} {customAction} @@ -125,7 +125,7 @@ export const WalletSetupStepLayoutRevamp = ({ nextButtonContainerRef.current!} + getPopupContainer={() => nextButtonContainerRef.current as HTMLElement} autoAdjustOverflow={false} > diff --git a/packages/core/src/ui/utils/password-complexity.ts b/packages/core/src/ui/utils/password-complexity.ts index b73425471..37de495e4 100644 --- a/packages/core/src/ui/utils/password-complexity.ts +++ b/packages/core/src/ui/utils/password-complexity.ts @@ -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); diff --git a/packages/staking/src/features/overview/StakingInfoCard/StakePoolInfo.tsx b/packages/staking/src/features/overview/StakingInfoCard/StakePoolInfo.tsx index c8cf492dc..c9983b44c 100644 --- a/packages/staking/src/features/overview/StakingInfoCard/StakePoolInfo.tsx +++ b/packages/staking/src/features/overview/StakingInfoCard/StakePoolInfo.tsx @@ -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 ?? ( );