polkadot-js/apps

View on GitHub

Showing 600 of 2,052 total issues

File Forks.tsx has 344 lines of code (exceeds 250 allowed). Consider refactoring.
Open

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

import type { Header } from '@polkadot/types/interfaces';

Severity: Minor
Found in packages/page-explorer/src/Forks.tsx - About 4 hrs to fix

    Function render has 104 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      render (accounts: [string, AccountOverrides][]): void {
        mockAccountHooks.setAccounts(accounts);
    
        accounts.forEach(([address, { meta }]) => {
          keyring.addExternal(address, meta);
    Severity: Major
    Found in packages/test-support/src/pages/Page.tsx - About 4 hrs to fix

      File CrustFiles.tsx has 334 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      // Copyright 2017-2024 @polkadot/app-files authors & contributors
      // SPDX-License-Identifier: Apache-2.0
      
      import type { ActionStatusBase } from '@polkadot/react-components/Status/types';
      import type { DirFile, FileInfo, SaveFile } from './types.js';
      Severity: Minor
      Found in packages/page-files/src/CrustFiles.tsx - About 4 hrs to fix

        Consider simplifying this complex logical expression.
        Open

            if (value) {
              try {
                const accountOrAddress = keyring.getAccount(value) || keyring.getAddress(value);
                const isOwned = isAccount(value);
                const isInContacts = isAddress(value);
        Severity: Critical
        Found in packages/react-hooks/src/useAccountInfo.ts - About 4 hrs to fix

          Function BountyCreate has 100 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function BountyCreate () {
            const { t } = useTranslation();
            const { bountyDepositBase, bountyValueMinimum, dataDepositPerByte, maximumReasonLength, proposeBounty } = useBounties();
            const [accountId, setAccountId] = useState<string | null>(null);
            const balance = useBalance(accountId);
          Severity: Major
          Found in packages/page-bounties/src/BountyCreate.tsx - About 4 hrs to fix

            Function useWeightImpl has 99 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function useWeightImpl (): UseWeight {
              const { api } = useApi();
              const blockTime = useBlockInterval();
              const isWeightV2 = !!api.registry.createType<WeightV2>('Weight').proofSize;
              const [megaGas, _setMegaGas] = useState<BN>(
            Severity: Major
            Found in packages/page-contracts/src/useWeight.ts - About 3 hrs to fix

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

              // Copyright 2017-2024 @polkadot/apps authors & contributors
              // SPDX-License-Identifier: Apache-2.0
              
              import type { LinkOption } from '@polkadot/apps-config/endpoints/types';
              import type { Group } from './types.js';
              Severity: Minor
              Found in packages/apps/src/Endpoints/index.tsx - About 3 hrs to fix

                Function VanityApp has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
                Open

                function VanityApp ({ className = '', onStatusChange }: Props): React.ReactElement<Props> {
                  const { t } = useTranslation();
                  const { api, isEthereum } = useApi();
                  const results = useRef<GeneratorResult[]>([]);
                  const runningRef = useRef(false);
                Severity: Minor
                Found in packages/page-accounts/src/Vanity/index.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 getInitValue has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
                Open

                export default function getInitValue (registry: Registry, def: TypeDef): unknown {
                  if (def.info === TypeDefInfo.Vec) {
                    return [getInitValue(registry, def.sub as TypeDef)];
                  } else if (def.info === TypeDefInfo.Tuple) {
                    return Array.isArray(def.sub)
                Severity: Minor
                Found in packages/react-params/src/initValue.ts - 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 groupLocks has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
                Open

                function groupLocks (t: (key: string, options?: { replace: Record<string, unknown> }) => string, bestNumber: BN, locks: Partial<DeriveDemocracyLock>[] = []): State {
                  return {
                    maxBalance: bnMax(...locks.map(({ balance }) => balance).filter((b): b is Balance => !!b)),
                    sorted: locks
                      .map((info): [Partial<DeriveDemocracyLock>, BN] => [info, info.unlockAt && info.unlockAt.gt(bestNumber) ? info.unlockAt.sub(bestNumber) : BN_ZERO])
                Severity: Minor
                Found in packages/react-components/src/DemocracyLocks.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 Transfer has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
                Open

                function Transfer ({ className = '', onClose, recipientId: propRecipientId, senderId: propSenderId }: Props): React.ReactElement<Props> {
                  const { t } = useTranslation();
                  const { api } = useApi();
                  const [amount, setAmount] = useState<BN | undefined>(BN_ZERO);
                  const [hasAvailable] = useState(true);
                Severity: Minor
                Found in packages/react-components/src/modals/Transfer.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 Forks has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
                Open

                function Forks ({ className }: Props): React.ReactElement<Props> | null {
                  const { t } = useTranslation();
                  const { api } = useApi();
                  const [tree, setTree] = useState<Link | null>(null);
                  const childrenRef = useRef<Map<string, string[]>>(new Map([['root', []]]));
                Severity: Minor
                Found in packages/page-explorer/src/Forks.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 Account has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
                Open

                function Account ({ account: { address, meta }, className = '', delegation, filter, isFavorite, proxy, setBalance, toggleFavorite }: Props): React.ReactElement<Props> | null {
                  const { t } = useTranslation();
                  const [isExpanded, toggleIsExpanded] = useToggle(false);
                  const { queueExtrinsic } = useQueue();
                  const { api, apiIdentity, enableIdentity, isDevelopment: isDevelopmentApiProps, isEthereum: isEthereumApiProps } = useApi();
                Severity: Minor
                Found in packages/page-accounts/src/Accounts/Account.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 group has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
                Open

                function group (tracks: TrackDescription[], totalIssuance?: BN, referenda?: Referendum[]): ReferendaGroup[] {
                  if (!referenda || !totalIssuance) {
                    // return an empty group when we have no referenda
                    return [{ key: 'empty' }];
                  } else if (!tracks) {
                Severity: Minor
                Found in packages/page-referenda/src/useReferenda.ts - 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 Fund has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
                Open

                function Fund ({ bestHash, bestNumber, className = '', isOngoing, leasePeriod, value: { info: { cap, depositor, end, firstPeriod, lastPeriod, raised, verifier }, isCapped, isEnded, isWinner, paraId } }: Props): React.ReactElement<Props> {
                  const { t } = useTranslation();
                  const { api } = useApi();
                  const { isAccount } = useAccounts();
                  const endpoints = useParaEndpoints(paraId);
                Severity: Minor
                Found in packages/page-parachains/src/Crowdloan/Fund.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 QueueCtxRoot has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
                Open

                export function QueueCtxRoot ({ children }: Props): React.ReactElement<Props> {
                  const [stqueue, _setStQueue] = useState<QueueStatus[]>(EMPTY_QUEUE_ST);
                  const [txqueue, _setTxQueue] = useState<QueueTx[]>(EMPTY_QUEUE_TX);
                  const stRef = useRef(stqueue);
                  const txRef = useRef(txqueue);
                Severity: Minor
                Found in packages/react-hooks/src/ctx/Queue.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 Create has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
                Open

                function Create ({ onClose, onStatusChange }: Props): React.ReactElement<Props> {
                  const { t } = useTranslation();
                  const { api, isEthereum } = useApi();
                  const [{ isNameValid, name }, setName] = useState<NameState>({ isNameValid: false, name: '' });
                  const [{ address, addressInput, isAddressExisting, isAddressValid }, setAddress] = useState<AddrState>({ address: '', addressInput: '', isAddressExisting: false, isAddressValid: false, isPublicKey: false });
                Severity: Minor
                Found in packages/page-addresses/src/modals/Create.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 getCachedComponent has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
                Open

                function getCachedComponent (registry: Registry, query: QueryTypes): CacheInstance {
                  const { blockHash, id, isConst, key, params = [] } = query as StorageModuleQuery;
                
                  if (!cache[id]) {
                    let renderHelper;
                Severity: Minor
                Found in packages/page-storage/src/Query.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 checkVisibility has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
                Open

                export function checkVisibility (api: ApiPromise, address: string, accountInfo: DeriveAccountInfo, filterName = '', onlyNamed = false): boolean {
                  let isVisible = false;
                  const filterLower = filterName.toLowerCase();
                
                  if (filterLower || onlyNamed) {
                Severity: Minor
                Found in packages/react-components/src/util/checkVisibility.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 _onClickUp has 84 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  const _onClickUp = useCallback(async () => {
                    setError('');
                
                    if (!isUsable || !currentPair) {
                      return;
                Severity: Major
                Found in packages/page-files/src/UploadModal.tsx - About 3 hrs to fix
                  Severity
                  Category
                  Status
                  Source
                  Language