polkadot-js/apps

View on GitHub

Showing 600 of 2,050 total issues

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 _setExtrinsicHex has 43 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    (hex: string): void => {
      try {
        assert(isHex(hex), 'Expected a hex-encoded call');

        let extrinsicCall: Call;
Severity: Minor
Found in packages/page-extrinsics/src/Decoder.tsx - About 1 hr to fix

    Function useSortedTargetsImpl has 42 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function useSortedTargetsImpl (favorites: string[], withLedger: boolean): SortedTargets {
      const { api } = useApi();
      const { allAccounts } = useAccounts();
      const { counterForNominators, counterForValidators, historyDepth, maxNominatorsCount, maxValidatorsCount, minNominatorBond, minValidatorBond, totalIssuance } = useCallMulti<MultiResult>([
        api.query.staking.historyDepth,
    Severity: Minor
    Found in packages/page-staking-legacy/src/useSortedTargets.ts - About 1 hr to fix

      Function useAbiImpl has 42 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function useAbiImpl (initialValue: [string | null | undefined, Abi | null | undefined] = [null, null], codeHash: string | null = null, isRequired = false): UseAbi {
        const [state, setAbi] = useState<AbiState>(() => fromInitial(initialValue, isRequired));
      
        useEffect(
          () => setAbi((state) =>
      Severity: Minor
      Found in packages/page-contracts/src/useAbi.ts - About 1 hr to fix

        Function useSortedTargetsImpl has 42 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function useSortedTargetsImpl (favorites: string[], withLedger: boolean): SortedTargets {
          const { api } = useApi();
          const { allAccounts } = useAccounts();
          const { counterForNominators, counterForValidators, historyDepth, maxNominatorsCount, maxValidatorsCount, minNominatorBond, minValidatorBond, totalIssuance } = useCallMulti<MultiResult>([
            api.query.staking.historyDepth,
        Severity: Minor
        Found in packages/page-staking/src/useSortedTargets.ts - About 1 hr to fix

          Function createErasString has 41 lines of code (exceeds 25 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 1 hr to fix

            Function NewStash has 41 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function NewStash (): React.ReactElement {
              const { t } = useTranslation();
              const [isVisible, toggleVisible] = useToggle();
              const [{ bondTx, stashId }, setBondInfo] = useState<BondInfo>({});
            
            
            Severity: Minor
            Found in packages/page-staking-legacy/src/Actions/NewStash.tsx - About 1 hr to fix

              Function createErasString has 41 lines of code (exceeds 25 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 1 hr to fix

                Function NewStash has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                function NewStash (): React.ReactElement {
                  const { t } = useTranslation();
                  const [isVisible, toggleVisible] = useToggle();
                  const [{ bondTx, stashId }, setBondInfo] = useState<BondInfo>({});
                
                
                Severity: Minor
                Found in packages/page-staking/src/Actions/NewStash.tsx - About 1 hr to fix

                  Function mergeStatus has 40 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  function mergeStatus (status: ActionStatusPartial[]): ActionStatus[] {
                    let others: ActionStatus | null = null;
                  
                    const initial = status
                      .reduce((result: StatusCount[], status): StatusCount[] => {
                  Severity: Minor
                  Found in packages/react-hooks/src/ctx/Queue.tsx - About 1 hr to fix

                    Function useOwnStashInfosImpl has 40 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    function useOwnStashInfosImpl (): StakerState[] | undefined {
                      const { api } = useApi();
                      const { allAccounts } = useAccounts();
                      const mountedRef = useIsMountedRef();
                      const ownStashes = useOwnStashes();
                    Severity: Minor
                    Found in packages/react-hooks/src/useOwnStashInfos.ts - About 1 hr to fix

                      Function groupLocks has 40 lines of code (exceeds 25 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 1 hr to fix

                        Function Account has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                        Open

                        function Account ({ allSlashes, className = '', info: { controllerId, destination, hexSessionIdNext, hexSessionIdQueue, isLoading, isOwnController, isOwnStash, isStashNominating, isStashValidating, nominating, sessionIds, stakingLedger, stashId }, isDisabled, minCommission, targets }: Props): React.ReactElement<Props> {
                          const { t } = useTranslation();
                          const { api } = useApi();
                          const { queueExtrinsic } = useQueue();
                          const [isBondExtraOpen, toggleBondExtra] = useToggle();
                        Severity: Minor
                        Found in packages/page-staking-legacy/src/Actions/Account/index.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 Account has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                        Open

                        function Account ({ allSlashes, className = '', info: { controllerId, destination, hexSessionIdNext, hexSessionIdQueue, isLoading, isOwnController, isOwnStash, isStashNominating, isStashValidating, nominating, sessionIds, stakingLedger, stashId }, isDisabled, minCommission, targets }: Props): React.ReactElement<Props> {
                          const { t } = useTranslation();
                          const { api } = useApi();
                          const { queueExtrinsic } = useQueue();
                          const [isBondExtraOpen, toggleBondExtra] = useToggle();
                        Severity: Minor
                        Found in packages/page-staking/src/Actions/Account/index.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 calcBlockTime has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                        Open

                        export function calcBlockTime (blockTime: BN, blocks: BN, t: (key: string, options?: { replace: Record<string, unknown> }) => string): Result {
                          // in the case of excessively large locks, limit to the max JS integer value
                          const value = bnMin(BN_MAX_INTEGER, blockTime.mul(blocks)).toNumber();
                        
                          // time calculations are using the absolute value (< 0 detection only on strings)
                        Severity: Minor
                        Found in packages/react-hooks/src/useBlockTime.ts - 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 toAddress has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                        Open

                        export function toAddress (value?: string | Uint8Array | null, allowIndices = false, bytesLength?: 20 | 32): string | undefined {
                          if (value) {
                            try {
                              const u8a = isHex(value)
                                ? hexToU8a(value)
                        Severity: Minor
                        Found in packages/react-components/src/util/toAddress.ts - 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 curveThreshold has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                        export function curveThreshold (curve: PalletReferendaCurve, input: BN, div: BN): BN {
                          // if divisor is zero, we return the max
                          if (div.isZero()) {
                            return BN_BILLION;
                          }
                        Severity: Minor
                        Found in packages/page-referenda/src/util.ts - About 1 hr to fix

                          Function approxChanges has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          export function approxChanges (threshold: VoteThreshold, sqrtElectorate: BN, state: ApproxState): Approx {
                            const isPassing = calcPassing(threshold, sqrtElectorate, state);
                          
                            // simple case, we have an aye > nay to determine passing
                            if (threshold.isSimpleMajority) {
                          Severity: Minor
                          Found in packages/page-democracy/src/util.ts - About 1 hr to fix

                            Function setAccounts has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                              public setAccounts (accounts: [string, AccountOverrides][]): void {
                                this.useAccounts = {
                                  allAccounts: accounts.map(([address]) => address),
                                  allAccountsHex: [],
                                  areAccountsLoaded: true,
                            Severity: Minor
                            Found in packages/test-support/src/utils/accountDefaults.ts - About 1 hr to fix

                              Function getBytesParams has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                              function getBytesParams (interimResult: PreimageStatus, someOptStatus: Option<PalletPreimageRequestStatus>): BytesParams {
                                const result = objectSpread<PreimageStatus>({}, interimResult, {
                                  status: someOptStatus.unwrapOr(null)
                                });
                              
                              
                              Severity: Minor
                              Found in packages/react-hooks/src/usePreimage.ts - About 1 hr to fix
                                Severity
                                Category
                                Status
                                Source
                                Language