polkadot-js/apps

View on GitHub
packages/react-api/src/Api.tsx

Summary

Maintainability
C
1 day
Test Coverage

File Api.tsx has 287 lines of code (exceeds 250 allowed). Consider refactoring.
Open

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

import type { Blockchain } from '@acala-network/chopsticks-core';
import type { LinkOption } from '@polkadot/apps-config/endpoints/types';
Severity: Minor
Found in packages/react-api/src/Api.tsx - About 2 hrs to fix

    Function loadOnReady has 54 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    async function loadOnReady (api: ApiPromise, endpoint: LinkOption | null, fork: Blockchain | null, injectedPromise: Promise<InjectedExtension[]>, store: KeyringStore | undefined, types: Record<string, Record<string, string>>, urlIsEthereum = false): Promise<ApiState> {
      statics.registry.register(types);
    
      const { injectedAccounts, properties, systemChain, systemChainType, systemName, systemVersion } = await retrieve(api, injectedPromise);
      const chainSS58 = properties.ss58Format.unwrapOr(DEFAULT_SS58).toNumber();
    Severity: Major
    Found in packages/react-api/src/Api.tsx - About 2 hrs to fix

      Function ApiCtxRoot has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

      export function ApiCtxRoot ({ apiUrl, children, isElectron, store: keyringStore }: Props): React.ReactElement<Props> | null {
        const { queuePayload, queueSetTxStatus } = useQueue();
        const [state, setState] = useState<ApiState>(EMPTY_STATE);
        const [isApiConnected, setIsApiConnected] = useState(false);
        const [isApiInitialized, setIsApiInitialized] = useState(false);
      Severity: Minor
      Found in packages/react-api/src/Api.tsx - About 1 hr 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 createApi has 34 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      async function createApi (apiUrl: string, signer: ApiSigner, isLocalFork: boolean, onError: (error: unknown) => void): Promise<CreateApiReturn> {
        const types = getDevTypes();
        const isLight = apiUrl.startsWith('light://');
        let provider;
        let chopsticksFork: Blockchain | null = null;
      Severity: Minor
      Found in packages/react-api/src/Api.tsx - About 1 hr to fix

        Function loadOnReady has 7 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        async function loadOnReady (api: ApiPromise, endpoint: LinkOption | null, fork: Blockchain | null, injectedPromise: Promise<InjectedExtension[]>, store: KeyringStore | undefined, types: Record<string, Record<string, string>>, urlIsEthereum = false): Promise<ApiState> {
        Severity: Major
        Found in packages/react-api/src/Api.tsx - About 50 mins to fix

          There are no issues that match your filters.

          Category
          Status