packages/react-api/src/Api.tsx
File Api.tsx
has 287 lines of code (exceeds 250 allowed). Consider refactoring. Open
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';
Function loadOnReady
has 54 lines of code (exceeds 25 allowed). Consider refactoring. Open
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();
Function ApiCtxRoot
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
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);
- Read upRead up
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
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;
Function loadOnReady
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
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> {