oceanprotocol/react

View on GitHub
src/hooks/usePricing/usePricing.ts

Summary

Maintainability
D
1 day
Test Coverage

Function usePricing has 220 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function usePricing(ddo: DDO): UsePricing {
  const { ocean, accountId, config } = useOcean()
  const [pricingIsLoading, setPricingIsLoading] = useState(false)
  const [pricingStep, setPricingStep] = useState<number>()
  const [pricingStepText, setPricingStepText] = useState<string>()
Severity: Major
Found in src/hooks/usePricing/usePricing.ts - About 1 day to fix

    Function usePricing has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
    Wontfix

    function usePricing(ddo: DDO): UsePricing {
      const { ocean, accountId, config } = useOcean()
      const [pricingIsLoading, setPricingIsLoading] = useState(false)
      const [pricingStep, setPricingStep] = useState<number>()
      const [pricingStepText, setPricingStepText] = useState<string>()
    Severity: Minor
    Found in src/hooks/usePricing/usePricing.ts - About 5 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 buyDT has 66 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      async function buyDT(
        dtAmount: number | string
      ): Promise<TransactionReceipt | void> {
        if (!ocean || !accountId) return
    
    
    Severity: Major
    Found in src/hooks/usePricing/usePricing.ts - About 2 hrs to fix

      File usePricing.ts has 253 lines of code (exceeds 250 allowed). Consider refactoring.
      Wontfix

      import { DDO, Logger } from '@oceanprotocol/lib'
      import { useEffect, useState } from 'react'
      import { useOcean } from 'providers'
      import { PriceOptions } from './PriceOptions'
      import { TransactionReceipt } from 'web3-core'
      Severity: Minor
      Found in src/hooks/usePricing/usePricing.ts - About 2 hrs to fix

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

          async function createPricing(
            priceOptions: PriceOptions
          ): Promise<TransactionReceipt | void> {
            if (!ocean || !accountId || !dtSymbol) return
        
        
        Severity: Minor
        Found in src/hooks/usePricing/usePricing.ts - About 1 hr to fix

          Function sellDT has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            async function sellDT(
              dtAmount: number | string
            ): Promise<TransactionReceipt | void> {
              if (!ocean || !accountId) return
          
          
          Severity: Minor
          Found in src/hooks/usePricing/usePricing.ts - About 1 hr to fix

            There are no issues that match your filters.

            Category
            Status