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

fix(fiat-services): fix fetching fiat rates for timestamps range #16754

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

vytick
Copy link
Contributor

@vytick vytick commented Jan 31, 2025

When fetching fiat rates and picking the best one for given timestamp, the range was increased by wrong number. This caused wrong selection of the closest fiat rate for the timestamp and also wrong 24h change computation.

Related Issue

Related to #15440

@vytick vytick added the no-project This label is used to specify that PR doesn't need to be added to a project label Jan 31, 2025
Copy link

coderabbitai bot commented Jan 31, 2025

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

error Error: http://10.0.0.28:4873/@trezor%2feslint: no such package available
at params.callback [as _callback] (/opt/yarn-v1.22.22/lib/cli.js:66685:18)
at self.callback (/opt/yarn-v1.22.22/lib/cli.js:141415:22)
at Request.emit (node:events:519:28)
at Request. (/opt/yarn-v1.22.22/lib/cli.js:142387:10)
at Request.emit (node:events:519:28)
at IncomingMessage. (/opt/yarn-v1.22.22/lib/cli.js:142309:12)
at Object.onceWrapper (node:events:633:28)
at IncomingMessage.emit (node:events:531:35)
at endReadableNT (node:internal/streams/readable:1698:12)
at process.processTicksAndRejections (node:internal/process/task_queues:90:21)

Walkthrough

The pull request modifies the coingecko.ts file in the suite-common/fiat-services directory. The primary change involves updating a time-related constant from representing one day in milliseconds to one day in seconds. Specifically, ONE_DAY_IN_MS has been replaced with ONE_DAY_IN_S, and the corresponding calculations in the getFiatRatesForTimestamps function have been adjusted to use seconds instead of milliseconds. This modification affects how historical rates are fetched from the CoinGecko API, ensuring that timestamp calculations are performed using the correct time unit.

Assessment against linked issues

Objective Addressed Explanation
Fix price update mechanism for XRP, SOL, ADA The change appears to be related to timestamp calculations, but it's unclear if this directly addresses the price update frequency issue
Investigate price update mechanism for non-blockbook coins No clear evidence that this change resolves the broader price update problem
Check price change indicator standard (7d vs 24h) This code change does not address the product-level decision about price change indicators

Note: The current code change seems to be a technical adjustment to time-based calculations, but it does not directly resolve the core issues raised in the linked issue about price updates and display standards.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

🪧 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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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: 0

🧹 Nitpick comments (1)
suite-common/fiat-services/src/coingecko.ts (1)

Line range hint 157-157: Consider normalizing timestamp units.

The function returns ts: new Date().getTime() in milliseconds while working with seconds elsewhere. Consider converting this to seconds for consistency:

-ts: new Date().getTime(),
+ts: Math.floor(new Date().getTime() / 1000),
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 01938fa and 2437ec4.

📒 Files selected for processing (1)
  • suite-common/fiat-services/src/coingecko.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: EAS Update
  • GitHub Check: run-desktop-tests (@group=wallet, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: run-desktop-tests (@group=other, trezor-user-env-unix)
  • GitHub Check: run-desktop-tests (@group=settings, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: run-desktop-tests (@group=device-management, trezor-user-env-unix)
  • GitHub Check: run-desktop-tests (@group=suite, trezor-user-env-unix)
  • GitHub Check: build-web
  • GitHub Check: build-web
  • GitHub Check: Setup and Cache Dependencies
  • GitHub Check: prepare_android_test_app
  • GitHub Check: Analyze with CodeQL (javascript)
🔇 Additional comments (3)
suite-common/fiat-services/src/coingecko.ts (3)

12-12: LGTM! Clear and accurate time constant.

The constant is correctly defined with a clear name indicating the unit (seconds) and a readable calculation.


139-140: LGTM! Correct timestamp range adjustment.

The range adjustment using ONE_DAY_IN_S is accurate and aligns with CoinGecko API's timestamp requirements.


139-140: Verify timestamp handling across the codebase.

Let's ensure that timestamp units are handled consistently across the codebase.

✅ Verification successful

Timestamp handling is consistent with CoinGecko API requirements

The timestamp calculations are correctly implemented in seconds, which is consistent with CoinGecko API requirements and the rest of the file's timestamp handling.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for timestamp-related code to verify consistent handling of units

# Look for getTime() usage which might expect milliseconds
echo "Searching for getTime() usage:"
rg "getTime\(\)" -A 2 -B 2

# Look for timestamp comparisons that might mix seconds and milliseconds
echo -e "\nSearching for timestamp comparisons:"
rg "timestamp[s]?\s*[<>=]" -A 2 -B 2

# Look for CoinGecko API related files that might handle timestamps
echo -e "\nSearching for CoinGecko related files:"
fd "coingecko" --type f

Length of output: 58545

Copy link

🚀 Expo preview is ready!

  • Project → trezor-suite-preview
  • Platforms → android, ios
  • Scheme → trezorsuitelite
  • Runtime Version → 24
  • More info

Learn more about 𝝠 Expo Github Action

@@ -136,8 +136,8 @@ export const getFiatRatesForTimestamps = async (
const sortedTimestamps = [...timestamps].sort((ts1, ts2) => ts1 - ts2);

// adjust from and to timestamps to get better range of data
const fromTimestamp = sortedTimestamps[0] - ONE_DAY_IN_MS;
const toTimestamp = sortedTimestamps[sortedTimestamps.length - 1] + ONE_DAY_IN_MS;
const fromTimestamp = sortedTimestamps[0] - ONE_DAY_IN_S;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you also rename it sortedTimestampsInSeconds?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-project This label is used to specify that PR doesn't need to be added to a project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants