polkadot-js/apps

View on GitHub
packages/react-components/src/AddressInfo.tsx

Summary

Maintainability
D
2 days
Test Coverage

File AddressInfo.tsx has 639 lines of code (exceeds 250 allowed). Consider refactoring.
Open

// Copyright 2017-2024 @polkadot/react-components authors & contributors
// SPDX-License-Identifier: Apache-2.0

import type { DeriveBalancesAccountData, DeriveBalancesAll, DeriveDemocracyLock, DeriveStakingAccount } from '@polkadot/api-derive/types';
import type { Raw } from '@polkadot/types';
Severity: Major
Found in packages/react-components/src/AddressInfo.tsx - About 1 day to fix

    Function createBalanceItems has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

    function createBalanceItems (formatIndex: number, lookup: Record<string, string>, t: TFunction, { address, balanceDisplay, balancesAll, bestNumber, convictionLocks, democracyLocks, isAllLocked, otherBonded, ownBonded, stakingInfo, votingOf, withBalanceToggle, withLabel }: { address: string; balanceDisplay: BalanceActiveType; balancesAll?: DeriveBalancesAll | DeriveBalancesAccountData; bestNumber?: BlockNumber; convictionLocks?: RefLock[]; democracyLocks?: DeriveDemocracyLock[]; isAllLocked: boolean; otherBonded: BN[]; ownBonded: BN; stakingInfo?: DeriveStakingAccount; votingOf?: Voting; withBalanceToggle: boolean, withLabel: boolean }): React.ReactNode {
      const allItems: React.ReactNode[] = [];
      const deriveBalances = balancesAll as DeriveBalancesAll;
    
      !withBalanceToggle && balanceDisplay.total && allItems.push(
    Severity: Minor
    Found in packages/react-components/src/AddressInfo.tsx - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function AddressInfo has 49 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function AddressInfo (props: Props): React.ReactElement<Props> {
      const { t } = useTranslation();
      const bestNumber = useBestNumber();
      const { children, className = '', extraInfo, withBalanceToggle, withHexSessionId } = props;
    
    
    Severity: Minor
    Found in packages/react-components/src/AddressInfo.tsx - About 1 hr to fix

      Function skipBalancesIf has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      function skipBalancesIf ({ withBalance = true, withExtended = false }: Props): boolean {
        // NOTE Unsure why we don't have a check for balancesAll in here (check skipStakingIf). adding
        // it doesn't break on Accounts/Addresses, but this gets used a lot, so there _may_ be an actual
        // reason behind the madness. However, derives are memoized, so no issue overall.
        if (withBalance === true || withExtended === true) {
      Severity: Minor
      Found in packages/react-components/src/AddressInfo.tsx - About 45 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function renderValidatorPrefs has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      function renderValidatorPrefs ({ stakingInfo, withValidatorPrefs = false }: Props, t: TFunction): React.ReactNode {
        const validatorPrefsDisplay = withValidatorPrefs === true
          ? DEFAULT_PREFS
          : withValidatorPrefs;
      
      
      Severity: Minor
      Found in packages/react-components/src/AddressInfo.tsx - About 35 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Avoid too many return statements within this function.
      Open

        return true;
      Severity: Major
      Found in packages/react-components/src/AddressInfo.tsx - About 30 mins to fix

        Function skipStakingIf has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

        function skipStakingIf ({ stakingInfo, withBalance = true, withValidatorPrefs = false }: Props): boolean {
          if (stakingInfo) {
            return true;
          } else if (withBalance === true || withValidatorPrefs) {
            return false;
        Severity: Minor
        Found in packages/react-components/src/AddressInfo.tsx - About 25 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                {withHexSessionId?.[0] && (
                  <>
                    <Label label={t('session keys')} />
                    <div className='result'>{withHexSessionId[0]}</div>
                  </>
        Severity: Minor
        Found in packages/react-components/src/AddressInfo.tsx and 1 other location - About 50 mins to fix
        packages/react-components/src/AddressInfo.tsx on lines 575..580

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 51.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                {withHexSessionId && withHexSessionId[0] !== withHexSessionId[1] && (
                  <>
                    <Label label={t('session next')} />
                    <div className='result'>{withHexSessionId[1]}</div>
                  </>
        Severity: Minor
        Found in packages/react-components/src/AddressInfo.tsx and 1 other location - About 50 mins to fix
        packages/react-components/src/AddressInfo.tsx on lines 569..574

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 51.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        There are no issues that match your filters.

        Category
        Status