oceanprotocol/react

View on GitHub

Showing 26 of 43 total issues

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

    function usePublish(): UsePublish {
      const { ocean, status, account, accountId } = useOcean()
      const [isLoading, setIsLoading] = useState(false)
      const [publishStep, setPublishStep] = useState<number | undefined>()
      const [publishStepText, setPublishStepText] = useState<string | undefined>()
    Severity: Major
    Found in src/hooks/usePublish/usePublish.ts - About 5 hrs to fix

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

        async function publish(
          asset: Metadata,
          serviceType: ServiceType,
          dataTokenOptions?: DataTokenOptions,
          timeout?: number,
      Severity: Major
      Found in src/hooks/usePublish/usePublish.ts - About 4 hrs to fix

        Function useMetadata has 85 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function useMetadata(asset?: DID | string | DDO): UseMetadata {
          const { ocean, config, status, networkId } = useOcean()
          const [internalDdo, setDDO] = useState<DDO>()
          const [internalDid, setDID] = useState<DID | string>()
          const [metadata, setMetadata] = useState<Metadata>()
        Severity: Major
        Found in src/hooks/useMetadata/useMetadata.ts - About 3 hrs to fix

          Function useCompute has 81 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function useCompute(): UseCompute {
            const { ocean, account, accountId } = useOcean()
            const [computeStep, setComputeStep] = useState<number | undefined>()
            const [computeStepText, setComputeStepText] = useState<string | undefined>()
            const [computeError, setComputeError] = useState<string | undefined>()
          Severity: Major
          Found in src/hooks/useCompute/useCompute.ts - About 3 hrs to fix

            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

              Function useConsume has 61 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function useConsume(): UseConsume {
                const { ocean, account, accountId } = useOcean()
                const [isLoading, setIsLoading] = useState(false)
                const [consumeStep, setConsumeStep] = useState<number | undefined>()
                const [consumeStepText, setConsumeStepText] = useState<string | undefined>()
              Severity: Major
              Found in src/hooks/useConsume/useConsume.ts - About 2 hrs to fix

                Function Trade has 56 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                export function Trade() {
                  const { ocean, accountId } = useOcean()
                  const {
                    createPricing,
                    buyDT,
                Severity: Major
                Found in example/src/Trade.tsx - About 2 hrs to fix

                  Function compute has 56 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    async function compute(
                      did: string,
                      computeService: ServiceCompute,
                      dataTokenAddress: string,
                      algorithmRawCode: string,
                  Severity: Major
                  Found in src/hooks/useCompute/useCompute.ts - About 2 hrs to fix

                    Function ConsumeDdo has 50 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    export function ConsumeDdo() {
                      const { ocean, accountId } = useOcean()
                      const { consumeStepText, consume, consumeError } = useConsume()
                      const { compute, computeStepText } = useCompute()
                      const [did, setDid] = useState<string | undefined>()
                    Severity: Minor
                    Found in example/src/ConsumeDdo.tsx - About 2 hrs to fix

                      Function useCompute has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                      Open

                      function useCompute(): UseCompute {
                        const { ocean, account, accountId } = useOcean()
                        const [computeStep, setComputeStep] = useState<number | undefined>()
                        const [computeStepText, setComputeStepText] = useState<string | undefined>()
                        const [computeError, setComputeError] = useState<string | undefined>()
                      Severity: Minor
                      Found in src/hooks/useCompute/useCompute.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 getCheapestExchangePrice has 47 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      export async function getCheapestExchangePrice(
                        ocean: Ocean,
                        dataTokenAddress: string
                      ): Promise<BestPrice> {
                        try {
                      Severity: Minor
                      Found in src/utils/dtUtils.ts - About 1 hr to fix

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

                        function usePublish(): UsePublish {
                          const { ocean, status, account, accountId } = useOcean()
                          const [isLoading, setIsLoading] = useState(false)
                          const [publishStep, setPublishStep] = useState<number | undefined>()
                          const [publishStepText, setPublishStepText] = useState<string | undefined>()
                        Severity: Minor
                        Found in src/hooks/usePublish/usePublish.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 consume has 43 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          async function consume(
                            did: DID | string,
                            dataTokenAddress: string,
                            serviceType: ServiceType = 'access',
                            marketFeeAddress: string,
                        Severity: Minor
                        Found in src/hooks/useConsume/useConsume.ts - About 1 hr to fix

                          Function getFirstPoolPrice has 43 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          export async function getFirstPoolPrice(
                            ocean: Ocean,
                            dataTokenAddress: string,
                            poolAddress?: string
                          ): Promise<BestPrice> {
                          Severity: Minor
                          Found in src/utils/dtUtils.ts - About 1 hr to fix

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

                            export async function getCheapestPoolPrice(
                              ocean: Ocean,
                              dataTokenAddress: string
                            ): Promise<BestPrice> {
                              const tokenPools = await ocean.pool.searchPoolforDT(dataTokenAddress)
                            Severity: Minor
                            Found in src/utils/dtUtils.ts - About 1 hr to fix

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

                              export function Publish() {
                                const { publish, publishStepText, isLoading } = usePublish()
                                const [ddo, setDdo] = useState<DDO | undefined | null>()
                              
                                const asset = {
                              Severity: Minor
                              Found in example/src/Publish.tsx - About 1 hr 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 getFirstExchangePrice has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                                  Open

                                  export async function getFirstExchangePrice(
                                    ocean: Ocean,
                                    dataTokenAddress: string
                                  ): Promise<BestPrice> {
                                    try {
                                  Severity: Minor
                                  Found in src/utils/dtUtils.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
                                      Severity
                                      Category
                                      Status
                                      Source
                                      Language