oceanprotocol/react

View on GitHub

Showing 36 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 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 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 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 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 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

                            Similar blocks of code found in 2 locations. Consider refactoring.
                            Open

                            export function getBuyDTFeedback(dtSymbol: string): { [key: number]: string } {
                              return {
                                1: '1/3 Approving OCEAN ...',
                                2: `2/3 Buying ${dtSymbol} ...`,
                                3: `3/3 ${dtSymbol} bought.`
                            Severity: Major
                            Found in src/utils/feedback.ts and 1 other location - About 1 hr to fix
                            src/utils/feedback.ts on lines 63..69

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 69.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 2 locations. Consider refactoring.
                            Open

                            export function getSellDTFeedback(dtSymbol: string): { [key: number]: string } {
                              return {
                                1: '1/3 Approving OCEAN ...',
                                2: `2/3 Selling ${dtSymbol} ...`,
                                3: `3/3 ${dtSymbol} sold.`
                            Severity: Major
                            Found in src/utils/feedback.ts and 1 other location - About 1 hr to fix
                            src/utils/feedback.ts on lines 55..61

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 69.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 2 locations. Consider refactoring.
                            Open

                              return {
                                type: 'pool',
                                pools: [cheapestPoolAddress],
                                address: cheapestPoolAddress,
                                value: Number(cheapestPoolPrice),
                            Severity: Major
                            Found in src/utils/dtUtils.ts and 1 other location - About 1 hr to fix
                            src/utils/dtUtils.ts on lines 198..206

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 67.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 2 locations. Consider refactoring.
                            Open

                              return {
                                type: 'pool',
                                pools: [firstPoolAddress],
                                address: firstPoolAddress,
                                value: Number(firstPoolPrice),
                            Severity: Major
                            Found in src/utils/dtUtils.ts and 1 other location - About 1 hr to fix
                            src/utils/dtUtils.ts on lines 44..52

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 67.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            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
                              Severity
                              Category
                              Status
                              Source
                              Language