Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: change range enum #56

Merged
merged 2 commits into from
Jul 3, 2024
Merged

refactor: change range enum #56

merged 2 commits into from
Jul 3, 2024

Conversation

yevhen-burkovskyi
Copy link
Contributor

No description provided.

Copy link

coderabbitai bot commented Jul 3, 2024

Walkthrough

This update involves modifications across various parts of the codebase, primarily focusing on refining enums, updating data types in DTOs, and schema validations. Notable changes include the removal of specific enum entries in DBTimeInterval and Range, altering data types in the GovOverviewDto and TokenInfoDto interfaces, and updating schema validations in the Supply and Governance services. These changes enhance data consistency, validation, and overall code structure.

Changes

File Change Summary
src/core/enums/db-time-interval.enum.ts Removed TWO_MINUTES entry from DBTimeInterval enum.
src/core/enums/range.enum.ts Removed FIVE_MIN, HOUR, and THREE_MONTH entries from Range enum.
src/core/schemas/range.schema.ts Introduced a new Joi schema definition for validating range values.
src/modules/governance/dto/gov-overview.dto.ts Changed totalProposals and currentProposals types from number to string.
src/modules/governance/services/governance.service.ts Updated totalProposals to use the raw string value and included string conversion in the accumulator.
src/modules/supply/services/supply.service.ts Removed initialization for Range.HOUR and modified the calculation logic for Range.YEAR.
src/modules/supply/supply.controller.ts Refactored schema imports to use a generic RangeSchema.
src/modules/token/dtos/token-info.dto.ts Updated apr type from string to number.
src/modules/token/services/token.service.ts Modified apr property to convert values using Number().
src/modules/token/token.controller.ts Updated to use RangeSchema instead of HistoricalPriceRange for schema validation.

Tip

AI model upgrade

gpt-4o model for reviews and chat is now live

OpenAI claims that this model is better at understanding and generating code than the previous models. Please join our Discord Community to provide any feedback or to report any issues.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@yevhen-burkovskyi yevhen-burkovskyi self-assigned this Jul 3, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3f700a1 and 7ae8a4f.

Files selected for processing (10)
  • src/core/enums/db-time-interval.enum.ts (1 hunks)
  • src/core/enums/range.enum.ts (1 hunks)
  • src/core/schemas/range.schema.ts (1 hunks)
  • src/modules/governance/dto/gov-overview.dto.ts (1 hunks)
  • src/modules/governance/services/governance.service.ts (2 hunks)
  • src/modules/supply/services/supply.service.ts (2 hunks)
  • src/modules/supply/supply.controller.ts (3 hunks)
  • src/modules/token/dtos/token-info.dto.ts (1 hunks)
  • src/modules/token/services/token.service.ts (2 hunks)
  • src/modules/token/token.controller.ts (2 hunks)
Files skipped from review due to trivial changes (2)
  • src/core/enums/db-time-interval.enum.ts
  • src/modules/governance/dto/gov-overview.dto.ts
Additional context used
Biome
src/modules/token/token.controller.ts

[error] 23-23: Decorators are not valid here.

Decorators are only valid on class declarations, class expressions, and class methods.
You can enable parameter decorators by setting the unsafeParameterDecoratorsEnabled option to true in your configuration file.

(parse)

src/modules/supply/supply.controller.ts

[error] 20-20: Decorators are not valid here.

Decorators are only valid on class declarations, class expressions, and class methods.
You can enable parameter decorators by setting the unsafeParameterDecoratorsEnabled option to true in your configuration file.

(parse)


[error] 33-33: Decorators are not valid here.

Decorators are only valid on class declarations, class expressions, and class methods.
You can enable parameter decorators by setting the unsafeParameterDecoratorsEnabled option to true in your configuration file.

(parse)


[error] 41-41: Decorators are not valid here.

Decorators are only valid on class declarations, class expressions, and class methods.
You can enable parameter decorators by setting the unsafeParameterDecoratorsEnabled option to true in your configuration file.

(parse)

Additional comments not posted (5)
src/core/enums/range.enum.ts (1)

1-7: LGTM! The enum simplification is clear and consistent.

The removal of FIVE_MIN, HOUR, and THREE_MONTH values simplifies the Range enum without compromising its functionality.

src/core/schemas/range.schema.ts (1)

1-6: LGTM! The schema correctly validates the Range enum values.

The introduction of RangeSchema using Joi ensures valid range values.

src/modules/token/dtos/token-info.dto.ts (1)

5-5: LGTM! The change aligns with the expected data type for apr.

Changing apr from string to number in TokenInfoDto is logical and improves type consistency.

src/modules/supply/services/supply.service.ts (2)

32-32: Verify the impact of removing Range.HOUR.

Ensure that the removal of Range.HOUR from rangeTimeIntervalMap does not affect other parts of the codebase.

Verification successful

No impact from removing Range.HOUR.

The removal of Range.HOUR from rangeTimeIntervalMap does not affect other parts of the codebase as it is not used elsewhere.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the impact of removing `Range.HOUR`.

# Test: Search for the usage of `Range.HOUR`. Expect: No breaking changes.
rg --type typescript $'Range.HOUR'

Length of output: 68



Script:

#!/bin/bash
# Description: Verify the impact of removing `Range.HOUR`.

# Test: Search for the usage of `Range.HOUR` in all files.
rg 'Range.HOUR'

Length of output: 15


187-187: Verify the correctness of the new calculation logic for Range.YEAR.

Ensure that the new calculation logic in the calculatePastDateByRange method is correct and does not introduce any errors.

Verification successful

The new calculation logic for Range.YEAR in the calculatePastDateByRange method is correct and does not introduce any errors.

  • The logic correctly sets the date to one year earlier using date.setFullYear(date.getFullYear() - 1).
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correctness of the new calculation logic for `Range.YEAR`.

# Test: Check the usage of the `calculatePastDateByRange` method. Expect: Correct logic.
rg --type typescript $'calculatePastDateByRange'

Length of output: 82



Script:

#!/bin/bash
# Description: Verify the correctness of the new calculation logic for `Range.YEAR`.

# Test: Check the usage of the `calculatePastDateByRange` method. Expect: Correct logic.
rg --glob '*.ts' 'calculatePastDateByRange'

Length of output: 359



Script:

#!/bin/bash
# Description: Extract the implementation and usage context of the `calculatePastDateByRange` method.

# Extract the `calculatePastDateByRange` method implementation.
ast-grep --lang typescript --pattern $'private calculatePastDateByRange(range: Range): Date {
  $$$
}' --json

# Extract the surrounding context where `calculatePastDateByRange` is called.
rg --context 5 'calculatePastDateByRange' src/modules/supply/services/supply.service.ts

Length of output: 1633

src/modules/token/token.controller.ts Show resolved Hide resolved
src/modules/supply/supply.controller.ts Show resolved Hide resolved
src/modules/token/services/token.service.ts Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7ae8a4f and 637ee7c.

Files selected for processing (1)
  • src/modules/token/services/token.service.ts (2 hunks)
Additional context used
Biome
src/modules/token/services/token.service.ts

[error] 111-111: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.

See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.

(lint/suspicious/noGlobalIsNan)

@@ -109,7 +108,7 @@ export class TokenService implements OnModuleInit {
change: mcap!.change,
},
volume: res.volume_24h,
apr,
apr: isNaN(Number(apr)) ? 0 : Number(apr),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Number.isNaN instead of isNaN

isNaN is unsafe as it attempts a type coercion. Use Number.isNaN to ensure type safety.

-  apr: isNaN(Number(apr)) ? 0 : Number(apr),
+  apr: Number.isNaN(Number(apr)) ? 0 : Number(apr),
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
apr: isNaN(Number(apr)) ? 0 : Number(apr),
apr: Number.isNaN(Number(apr)) ? 0 : Number(apr),
Tools
Biome

[error] 111-111: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.

See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.

(lint/suspicious/noGlobalIsNan)

@yevhen-burkovskyi yevhen-burkovskyi merged commit cf98e2e into main Jul 3, 2024
11 checks passed
@yevhen-burkovskyi yevhen-burkovskyi deleted the refactor/range branch July 3, 2024 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants