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

feat: add wallet rewards history #57

Merged
merged 1 commit into from
Jul 8, 2024

Conversation

yevhen-burkovskyi
Copy link
Contributor

No description provided.

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

coderabbitai bot commented Jul 8, 2024

Walkthrough

The update introduces a configuration for wallet reward history TTL with extensive integration across multiple parts of the application. It includes the addition of a method to fetch and cache wallet reward history in the Okp4Service and WalletCache, modifications in the GovernanceService for handling hashing using a utility function, and the creation of several new modules and interfaces for streamlined wallet reward history processing.

Changes

File/Module Change Summary
.env.example Added WALLET_REWARD_HISTORY_TTL configuration variable.
src/core/config/config.dto.ts Added walletRewardHistory property to CacheConfig interface.
src/core/config/config.schema.ts Introduced WALLET_REWARD_HISTORY_TTL in ConfigSchema.
src/core/config/config.ts Added configuration parameter walletRewardHistory to config object.
.../enums/endpoints.enum.ts Modified PROPOSAL_VOTES endpoint path and added TXS endpoint.
.../okp4.service.ts Added getWalletRewardsHistory method to Okp4Service class.
.../responses/rewards-history.response.ts Introduced RewardsHistoryResponse, Tx, and Event interfaces.
.../services/governance.service.ts Replaced createParamHash method with hash utility function for handling payloads.
.../wallet/dtos/get-wallet-rewards-history.dto.ts Introduced GetWalletRewardsHistoryDto interface.
.../wallet/enums/wallet-prefix.enum.ts Added WalletPrefix enum with values WALLET and REWARDS_HISTORY.
.../wallet/schemas/get-wallet-rewards-history.schema.ts Introduced schema for getting wallet rewards history using Joi validation.
.../wallet/wallet-cache.ts Added setWalletRewardHistory and getWalletRewardHistory methods in WalletCache class.
.../wallet/wallet-routes.enum.ts Added REWARD_HISTORY value to WalletRoutesEnum.
.../wallet/wallet.controller.ts Added getWalletRewardsHistory method and updated import paths for schemas and DTOs.
.../wallet/wallet.module.ts Included WalletCache and RedisService as providers.
.../wallet/wallet.service.ts Added methods for fetching and caching rewards history, updated constructor for WalletCache.
utils/create-hash.ts Introduced utility function hash for SHA-256 hashing of objects.
utils/extract-numbers.ts Added extract-numbers utility to extract numbers from a string.

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.

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: 4

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between cf98e2e and be482b8.

Files selected for processing (18)
  • .env.example (1 hunks)
  • src/core/config/config.dto.ts (1 hunks)
  • src/core/config/config.schema.ts (1 hunks)
  • src/core/config/config.ts (1 hunks)
  • src/core/lib/okp4/enums/endpoints.enum.ts (1 hunks)
  • src/core/lib/okp4/okp4.service.ts (2 hunks)
  • src/core/lib/okp4/responses/rewards-history.response.ts (1 hunks)
  • src/modules/governance/services/governance.service.ts (6 hunks)
  • src/modules/wallet/dtos/get-wallet-rewards-history.dto.ts (1 hunks)
  • src/modules/wallet/enums/wallet-prefix.enum.ts (1 hunks)
  • src/modules/wallet/schemas/get-wallet-rewards-history.schema.ts (1 hunks)
  • src/modules/wallet/wallet-cache.ts (1 hunks)
  • src/modules/wallet/wallet-routes.enum.ts (1 hunks)
  • src/modules/wallet/wallet.controller.ts (2 hunks)
  • src/modules/wallet/wallet.module.ts (1 hunks)
  • src/modules/wallet/wallet.service.ts (2 hunks)
  • utils/create-hash.ts (1 hunks)
  • utils/exctract-numbers.ts (1 hunks)
Files skipped from review due to trivial changes (7)
  • .env.example
  • src/core/config/config.dto.ts
  • src/modules/wallet/dtos/get-wallet-rewards-history.dto.ts
  • src/modules/wallet/enums/wallet-prefix.enum.ts
  • src/modules/wallet/schemas/get-wallet-rewards-history.schema.ts
  • src/modules/wallet/wallet-routes.enum.ts
  • utils/create-hash.ts
Additional context used
Biome
src/modules/wallet/wallet.service.ts

[error] 58-58: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

Additional comments not posted (17)
src/modules/wallet/wallet.module.ts (1)

6-7: LGTM! Ensure proper initialization of new providers.

The addition of WalletCache and RedisService as providers is correct. Verify that these services are properly initialized and configured.

Also applies to: 11-11

Verification successful

Initialization and Configuration Verified

The WalletCache and RedisService services are properly initialized and configured.

  • WalletCache correctly injects RedisService via its constructor.
  • RedisService is set up with necessary configurations for Redis operations.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the proper initialization and configuration of WalletCache and RedisService.

# Test: Check for the initialization of WalletCache and RedisService.
rg --type ts 'WalletCache|RedisService' src/modules/wallet/

Length of output: 808


Script:

#!/bin/bash
# Description: Verify the proper initialization and configuration of WalletCache and RedisService.

# Check the implementation of WalletCache class to ensure proper initialization
ast-grep --lang typescript --pattern $'class WalletCache {
  constructor(private readonly redisService: RedisService) {
    $$$
  }
}' src/modules/wallet/wallet-cache.ts

# Check for the RedisService class or its configuration
rg --type ts 'class RedisService|RedisService' src/

Length of output: 2463


Script:

#!/bin/bash
# Description: Retrieve the contents of RedisService class for review.

# Display the contents of RedisService class.
cat src/core/lib/redis.service.ts

Length of output: 683

src/core/config/config.schema.ts (1)

26-26: LGTM! Ensure proper usage of the new configuration.

The addition of the WALLET_REWARD_HISTORY_TTL configuration is correct. Verify that this configuration is properly used in the application.

Verification successful

Proper usage of the new configuration verified.

The WALLET_REWARD_HISTORY_TTL configuration is correctly utilized in the application, specifically in the wallet service and wallet cache modules.

  • src/modules/wallet/wallet.service.ts: Referenced in the walletRewardHistoryView method.
  • src/modules/wallet/wallet-cache.ts: Used directly in redisService.setWithTTL.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of WALLET_REWARD_HISTORY_TTL configuration in the application.

# Test: Check for the usage of WALLET_REWARD_HISTORY_TTL in the application.
rg --type ts 'WALLET_REWARD_HISTORY_TTL' src/

Length of output: 224


Script:

#!/bin/bash
# Description: Verify the usage of walletRewardHistory configuration in the application.

# Test: Check for the usage of walletRewardHistory in the application.
rg --type ts 'walletRewardHistory' src/

Length of output: 587


Script:

#!/bin/bash
# Description: Verify the usage of walletRewardHistory configuration in the application.

# Test: Check for the context and usage of walletRewardHistory in wallet.service.ts.
rg --type ts 'walletRewardHistory' src/modules/wallet/wallet.service.ts

# Test: Check for the context and usage of walletRewardHistory in wallet-cache.ts.
rg --type ts 'walletRewardHistory' src/modules/wallet/wallet-cache.ts

Length of output: 427

src/modules/wallet/wallet-cache.ts (2)

31-33: LGTM!

The method follows best practices and the code changes are approved.


21-29: Specify the type of the parsed object for better type safety.

The type of the parsed object is not specified. Consider specifying the type of the parsed object for better type safety.

-  private async getObjectFromRedis<T>(key: string): Promise<T | null> {
+  private async getObjectFromRedis<T>(key: string): Promise<RewardsHistory | null> {

Likely invalid or redundant comment.

src/modules/wallet/wallet.controller.ts (2)

Line range hint 12-20:
LGTM!

The method follows best practices and the code changes are approved.


23-29: LGTM!

The method follows best practices and the code changes are approved.

src/core/lib/okp4/enums/endpoints.enum.ts (2)

19-19: LGTM!

The modification follows best practices and the code changes are approved.


20-20: LGTM!

The addition follows best practices and the code changes are approved.

src/core/config/config.ts (1)

33-33: LGTM!

The addition follows best practices and the code changes are approved.

src/modules/wallet/wallet.service.ts (3)

31-39: LGTM!

The getWalletRewardsHistory function correctly fetches wallet reward history from the cache or fetches and caches it if not present. The logic is clear and sound.


41-46: LGTM!

The fetchAndCacheRewardsHistory function effectively fetches wallet reward history, processes it, and caches the result using a hashed key. The logic is clear and efficient.


12-12: LGTM!

The constructor has been updated to include WalletCache, which is necessary for the caching functionality. The logic is clear and straightforward.

src/modules/governance/services/governance.service.ts (3)

71-71: LGTM!

The getProposals function correctly fetches proposals from the cache or fetches and caches them if not present. The logic is clear and sound.


101-101: LGTM!

The fetchProposals function effectively fetches proposals, processes them, and caches the result using a hashed key. The logic is clear and efficient.


204-204: LGTM!

The getProposalVotes function correctly fetches proposal votes from the cache or fetches and caches them if not present. The logic is clear and sound.

src/core/lib/okp4/okp4.service.ts (1)

312-335: LGTM!

The getWalletRewardsHistory function constructs the necessary parameters and fetches the wallet reward history using an external service. The logic is clear and sound.

utils/exctract-numbers.ts (1)

1-7: LGTM! Consider adding comments and unit tests.

The function implementation is correct and efficient. Adding comments would improve readability, and unit tests would ensure correctness.

+ // Extracts all digit sequences from the input string and returns them as an array of numbers.
+ // Returns an empty array if no digit sequences are found.

Would you like me to generate unit tests for this function or open a GitHub issue to track this task?

src/modules/wallet/wallet.service.ts Show resolved Hide resolved
src/modules/wallet/wallet-cache.ts Show resolved Hide resolved
src/modules/wallet/wallet-cache.ts Show resolved Hide resolved
@yevhen-burkovskyi yevhen-burkovskyi merged commit 80e20f5 into main Jul 8, 2024
11 checks passed
@yevhen-burkovskyi yevhen-burkovskyi deleted the feat/wallet-rewards-history branch July 8, 2024 15:43
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