oceanprotocol/ocean.js

View on GitHub

Showing 193 of 201 total issues

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

  public async getRate(exchangeId: string): Promise<string> {
    const weiRate = await this.contract.getRate(exchangeId)
    return await this.unitsToAmount(null, weiRate, 18)
  }
Severity: Major
Found in src/contracts/FixedRateExchange.ts and 1 other location - About 1 hr to fix
src/contracts/AccessList.ts on lines 80..83

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 63.

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

  public async balance(address: string): Promise<string> {
    const balance = await this.contract.balanceOf(address)
    return await this.unitsToAmount(null, balance, 18)
  }
Severity: Major
Found in src/contracts/AccessList.ts and 1 other location - About 1 hr to fix
src/contracts/FixedRateExchange.ts on lines 256..259

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 63.

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

  public async getExchange(exchangeId: string): Promise<FixedPriceExchange> {
    const result: FixedPriceExchange = await this.contract.getExchange(exchangeId)
    const exchange: FixedPriceExchange = {
      active: result.active,
      datatoken: result.datatoken,
Severity: Minor
Found in src/contracts/FixedRateExchange.ts - About 1 hr to fix

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

        if (response?.ok) {
          const results: FileInfo[] = await response.json()
          for (const result of results) {
            files.push(result)
          }
    Severity: Major
    Found in src/services/Provider.ts and 1 other location - About 1 hr to fix
    src/services/Provider.ts on lines 279..285

    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 62.

    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

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

        if (response?.ok) {
          const results: FileInfo[] = await response.json()
          for (const result of results) {
            files.push(result)
          }
    Severity: Major
    Found in src/services/Provider.ts and 1 other location - About 1 hr to fix
    src/services/Provider.ts on lines 224..230

    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 62.

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

      public async calcBaseInGivenDatatokensOut(
        exchangeId: string,
        datatokenAmount: string,
        consumeMarketFee: string = '0'
      ): Promise<PriceAndFees> {
    Severity: Minor
    Found in src/contracts/FixedRateExchange.ts - About 1 hr to fix

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

        public async getPaymentCollector(dtAddress: string): Promise<string> {
          const dtContract = this.getContract(dtAddress)
          const paymentCollector = await dtContract.getPaymentCollector()
          return paymentCollector
        }
      Severity: Major
      Found in src/contracts/Datatoken.ts and 3 other locations - About 1 hr to fix
      src/contracts/Datatoken.ts on lines 742..746
      src/contracts/Datatoken.ts on lines 753..757
      src/contracts/Datatoken.ts on lines 764..768

      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 61.

      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 4 locations. Consider refactoring.
      Open

        public async getSymbol(dtAddress: string): Promise<string> {
          const dtContract = this.getContract(dtAddress)
          const symbol = await dtContract.symbol()
          return symbol
        }
      Severity: Major
      Found in src/contracts/Datatoken.ts and 3 other locations - About 1 hr to fix
      src/contracts/Datatoken.ts on lines 422..426
      src/contracts/Datatoken.ts on lines 753..757
      src/contracts/Datatoken.ts on lines 764..768

      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 61.

      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 4 locations. Consider refactoring.
      Open

        public async getNFTAddress(dtAddress: string): Promise<string> {
          const dtContract = this.getContract(dtAddress)
          const nftAddress = await dtContract.getERC721Address()
          return nftAddress
        }
      Severity: Major
      Found in src/contracts/Datatoken.ts and 3 other locations - About 1 hr to fix
      src/contracts/Datatoken.ts on lines 422..426
      src/contracts/Datatoken.ts on lines 742..746
      src/contracts/Datatoken.ts on lines 753..757

      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 61.

      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 4 locations. Consider refactoring.
      Open

        public async getName(dtAddress: string): Promise<string> {
          const dtContract = this.getContract(dtAddress)
          const name = await dtContract.name()
          return name
        }
      Severity: Major
      Found in src/contracts/Datatoken.ts and 3 other locations - About 1 hr to fix
      src/contracts/Datatoken.ts on lines 422..426
      src/contracts/Datatoken.ts on lines 742..746
      src/contracts/Datatoken.ts on lines 764..768

      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 61.

      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

        public async getDecimals(dtAddress: string): Promise<number> {
          const dtContract = this.getContract(dtAddress)
          const decimals = await dtContract.decimals()
          return decimals
        }
      Severity: Major
      Found in src/contracts/Datatoken.ts and 1 other location - About 1 hr to fix
      src/contracts/Datatoken.ts on lines 731..735

      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 61.

      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

        public async getId(dtAddress: string): Promise<number> {
          const dtContract = this.getContract(dtAddress)
          const id = await dtContract.getId()
          return id
        }
      Severity: Major
      Found in src/contracts/Datatoken.ts and 1 other location - About 1 hr to fix
      src/contracts/Datatoken.ts on lines 720..724

      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 61.

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

        public async buyDatatokens<G extends boolean = false>(
          exchangeId: string,
          datatokenAmount: string,
          maxBaseTokenAmount: string,
          consumeMarketAddress: string = ZERO_ADDRESS,
      Severity: Minor
      Found in src/contracts/FixedRateExchange.ts - About 1 hr to fix

        Function sellDatatokens has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          public async sellDatatokens<G extends boolean = false>(
            exchangeId: string,
            datatokenAmount: string,
            minBaseTokenAmount: string,
            consumeMarketAddress: string = ZERO_ADDRESS,
        Severity: Minor
        Found in src/contracts/FixedRateExchange.ts - About 1 hr to fix

          Function getConfig has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

            public getConfig(network: string | number, infuraProjectId?: string): Config {
              const filterBy = typeof network === 'string' ? 'network' : 'chainId'
          
              let config = configHelperNetworks.find((c) => c[filterBy] === network)
          
          
          Severity: Minor
          Found in src/config/ConfigHelper.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 getDownloadUrl has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            public async getDownloadUrl(
              did: string,
              serviceId: string,
              fileIndex: number,
              transferTxId: string,
          Severity: Minor
          Found in src/services/Provider.ts - About 1 hr to fix

            Function getComputeResultUrl has 30 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              public async getComputeResultUrl(
                providerUri: string,
                consumer: Signer,
                jobId: string,
                index: number
            Severity: Minor
            Found in src/services/Provider.ts - About 1 hr to fix

              Function validate has 30 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                public async validate(ddo: DDO, signal?: AbortSignal): Promise<ValidateMetadata> {
                  const status: ValidateMetadata = {
                    valid: false
                  }
                  let jsonResponse
              Severity: Minor
              Found in src/services/Aquarius.ts - About 1 hr to fix

                Function setMetadata has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  public async setMetadata<G extends boolean = false>(
                    nftAddress: string,
                    address: string,
                    metadataState: number,
                    metadataDecryptorUrl: string,
                Severity: Minor
                Found in src/contracts/NFT.ts - About 1 hr to fix

                  Function approve has 9 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                    signer: Signer,
                    config: Config,
                    account: string,
                    tokenAddress: string,
                    spender: string,
                  Severity: Major
                  Found in src/utils/TokenUtils.ts - About 1 hr to fix
                    Severity
                    Category
                    Status
                    Source
                    Language