polkadot-js/apps

View on GitHub

Showing 600 of 2,052 total issues

Function QrModal has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

function QrModal ({ className = '', onClose, onStatusChange }: Props): React.ReactElement<Props> {
  const { t } = useTranslation();
  const { api, isEthereum } = useApi();
  const { isIpfs } = useIpfs();
  const [{ isNameValid, name }, setName] = useState({ isNameValid: false, name: '' });
Severity: Minor
Found in packages/page-accounts/src/modals/Qr.tsx - About 2 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 Delegate has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

function Delegate ({ className, palletReferenda, palletVote, tracks }: Props): React.ReactElement<Props> {
  const { t } = useTranslation();
  const { api } = useApi();
  const { hasAccounts } = useAccounts();
  const [isOpen, toggleOpen] = useToggle();
Severity: Minor
Found in packages/page-referenda/src/Referenda/Delegate/index.tsx - About 2 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 Expander has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

function Expander ({ children, className = '', isHeader, isLeft, isOpen, isPadded, onClick, renderChildren, summary, summaryHead, summaryMeta, summarySub, withBreaks, withHidden }: Props): React.ReactElement<Props> {
  const [isExpanded, toggleExpanded] = useToggle(isOpen, onClick);

  const demandChildren = useMemo(
    () => isExpanded && renderChildren && renderChildren(),
Severity: Minor
Found in packages/react-components/src/Expander.tsx - About 2 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 curveDelay has 64 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function curveDelay (curve: PalletReferendaCurve, input: BN, div: BN): BN {
  try {
    // if divisor is zero, we return the max
    if (div.isZero()) {
      return BN_BILLION;
Severity: Major
Found in packages/page-referenda/src/util.ts - About 2 hrs to fix

    File index.tsx has 273 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    // Copyright 2017-2024 @polkadot/app-claims authors & contributors
    // SPDX-License-Identifier: Apache-2.0
    
    import type { AppProps as Props } from '@polkadot/react-components/types';
    import type { Option } from '@polkadot/types';
    Severity: Minor
    Found in packages/page-claims/src/index.tsx - About 2 hrs to fix

      Function EnumParam has 63 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function EnumParam (props: Props): React.ReactElement<Props> {
        const { className = '', defaultValue, isDisabled, isError, label, onChange, overrides, registry, type, withLabel } = props;
        const [{ options, subTypes }] = useState<Options>(() => getOptions(registry, type));
        const [current, setCurrent] = useState<ParamDef[] | null>(() => getCurrent(registry, type, defaultValue, subTypes));
        const [{ initialEnum, initialParams }, setInitial] = useState<Initial>(() => getInitial(defaultValue, options));
      Severity: Major
      Found in packages/react-params/src/Param/Enum.tsx - About 2 hrs to fix

        Function BannerExtension has 62 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function BannerExtension (): React.ReactElement | null {
          const { t } = useTranslation();
          const { hasInjectedAccounts } = useApi();
          const upgradableCount = useExtensionCounter();
          const phishing = useRef<string>(t('Since some extensions, such as the polkadot-js extension, protects you against all community reported phishing sites, there are valid reasons to use them for additional protection, even if you are not storing accounts in it.'));
        Severity: Major
        Found in packages/page-accounts/src/Accounts/BannerExtension.tsx - About 2 hrs to fix

          Function manageEvents has 62 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          async function manageEvents (api: ApiPromise, prev: PrevHashes, records: Vec<EventRecord>, setState: React.Dispatch<React.SetStateAction<BlockEvents>>): Promise<void> {
            const newEvents: IndexedEvent[] = records
              .map((record, index) => ({ indexes: [index], record }))
              .filter(({ record: { event: { method, section } } }) =>
                section !== 'system' &&
          Severity: Major
          Found in packages/react-hooks/src/ctx/BlockEvents.tsx - About 2 hrs to fix

            File Call.tsx has 269 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            // Copyright 2017-2024 @polkadot/app-contracts authors & contributors
            // SPDX-License-Identifier: Apache-2.0
            
            import type { SubmittableExtrinsic } from '@polkadot/api/types';
            import type { ContractPromise } from '@polkadot/api-contract';
            Severity: Minor
            Found in packages/page-contracts/src/Contracts/Call.tsx - About 2 hrs to fix

              Function Call has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
              Open

              function Call ({ className = '', contract, messageIndex, onCallResult, onChangeMessage, onClose }: Props): React.ReactElement<Props> | null {
                const { t } = useTranslation();
                const { api } = useApi();
                const message = contract.abi.messages[messageIndex];
                const [accountId, setAccountId] = useAccountId();
              Severity: Minor
              Found in packages/page-contracts/src/Contracts/Call.tsx - About 2 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 Validator has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
              Open

              function Validator ({ allSlashes, canSelect, filterName, info: { accountId, bondOther, bondOwn, bondTotal, commissionPer, isBlocking, isElected, isFavorite, key, lastPayout, numNominators, rankOverall, stakedReturnCmp }, isNominated, isSelected, nominatedBy = [], toggleFavorite, toggleSelected }: Props): React.ReactElement<Props> | null {
                const { t } = useTranslation();
                const { api, apiIdentity } = useApi();
                const accountInfo = useDeriveAccountInfo(accountId);
                const [,, time] = useBlockTime(lastPayout);
              Severity: Minor
              Found in packages/page-staking-legacy/src/Targets/Validator.tsx - About 2 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 createErasString has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
              Open

              export function createErasString (eras: BN[]): React.ReactNode {
                if (!eras.length) {
                  return '';
                }
              
              
              Severity: Minor
              Found in packages/page-staking-legacy/src/Payouts/util.tsx - About 2 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 Validator has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
              Open

              function Validator ({ allSlashes, canSelect, filterName, info: { accountId, bondOther, bondOwn, bondTotal, commissionPer, isBlocking, isElected, isFavorite, key, lastPayout, numNominators, rankOverall, stakedReturnCmp }, isNominated, isSelected, nominatedBy = [], toggleFavorite, toggleSelected }: Props): React.ReactElement<Props> | null {
                const { t } = useTranslation();
                const { api, apiIdentity } = useApi();
                const accountInfo = useDeriveAccountInfo(accountId);
                const [,, time] = useBlockTime(lastPayout);
              Severity: Minor
              Found in packages/page-staking/src/Targets/Validator.tsx - About 2 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 createErasString has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
              Open

              export function createErasString (eras: BN[]): React.ReactNode {
                if (!eras.length) {
                  return '';
                }
              
              
              Severity: Minor
              Found in packages/page-staking/src/Payouts/util.tsx - About 2 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 wrapTx has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
              Open

              async function wrapTx (api: ApiPromise, currentItem: QueueTx, { isMultiCall, multiRoot, proxyRoot, signAddress }: AddressProxy): Promise<SubmittableExtrinsic<'promise'>> {
                let tx = currentItem.extrinsic as SubmittableExtrinsic<'promise'>;
              
                if (proxyRoot) {
                  tx = api.tx.proxy.proxy(proxyRoot, null, tx);
              Severity: Minor
              Found in packages/react-signer/src/TxSigned.tsx - About 2 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 ClaimsApp has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
              Open

              function ClaimsApp ({ basePath }: Props): React.ReactElement<Props> {
                const [didCopy, setDidCopy] = useState(false);
                const [ethereumAddress, setEthereumAddress] = useState<string | undefined | null>(null);
                const [signature, setSignature] = useState<EcdsaSignature | null>(null);
                const [step, setStep] = useState<Step>(Step.Account);
              Severity: Minor
              Found in packages/page-claims/src/index.tsx - About 2 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 getValues has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
              Open

              function getValues (selectedId: string | null | undefined, noDefault: boolean | undefined, allBalances: DeriveBalancesAll, existential: BN): ValueState {
                const sortedLocks = allBalances.lockedBreakdown
                  // first sort by amount, so greatest value first
                  .sort((a, b) =>
                    b.amount.cmp(a.amount)
              Severity: Minor
              Found in packages/react-components/src/VoteValue.tsx - About 2 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 ButtonBase has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
              Open

              function ButtonBase ({ activeOnEnter, children, className = '', dataTestId = '', icon, isBasic, isBusy, isCircular, isDisabled, isFull, isIcon, isSelected, isToplevel, label, onClick, isReadOnly = !onClick, onMouseEnter, onMouseLeave, tabIndex, withoutLink }: Props): React.ReactElement<Props> {
                const _onClick = useCallback(
                  (): void => {
                    !(isBusy || isDisabled) && onClick && Promise
                      .resolve(onClick())
              Severity: Minor
              Found in packages/react-components/src/Button/index.tsx - About 2 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 filterProxies has 60 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function filterProxies (allAccounts: string[], tx: Call | SubmittableExtrinsic<'promise'>, proxies: [string, BN, KitchensinkRuntimeProxyType][]): string[] {
                // get the call info
                const { method, section } = findCall(tx);
              
                // check an array of calls to all have proxies as the address
              Severity: Major
              Found in packages/react-signer/src/Address.tsx - About 2 hrs to fix

                File index.tsx has 266 lines of code (exceeds 250 allowed). Consider refactoring.
                Open

                // Copyright 2017-2024 @polkadot/app-referenda authors & contributors
                // SPDX-License-Identifier: Apache-2.0
                
                import type { BatchOptions } from '@polkadot/react-hooks/types';
                import type { BN } from '@polkadot/util';
                Severity: Minor
                Found in packages/page-referenda/src/Referenda/Delegate/index.tsx - About 2 hrs to fix
                  Severity
                  Category
                  Status
                  Source
                  Language