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(suite-common): sanitise fetching graph history rates for empty account #14506

Merged
merged 1 commit into from
Sep 25, 2024

Conversation

vytick
Copy link
Contributor

@vytick vytick commented Sep 24, 2024

When no start timestamp was selected for wallet with only empty accounts, it threw range error. This was because getTimestampsInTimeFrame would receive equal start date and end date. This can happen only if user has no account with txn history at all.

So in such case I check and change the start date to 1y ago, to work the same as when such option(1y) is selected.

Related Issue

Resolve #14502

Screenshots:

@vytick vytick added the mobile Suite Lite issues and PRs label Sep 24, 2024
@vytick vytick requested review from Nodonisko and a team as code owners September 24, 2024 11:32
// if there were no balance movements at all,
// findOldestBalanceMovementTimestamp resulted with start date being the same as end date
// use 1 year into past instead, otherwise getTimestampsInTimeFrame will throw range error
if (startOfTimeFrameDate.getTime() === endOfTimeFrameDate.getTime()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure if this si best fix. I think it may be better to just return early here since if there is no movement we know that graph will just zero all the time. I think return [] or return [{ date: 1, value: 0 }, {date: 2, value: 0}] should work and it will be faster because otherwise we will be fetching timestamps for that whole year.

Copy link
Contributor Author

@vytick vytick Sep 24, 2024

Choose a reason for hiding this comment

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

So in such case it should probably check for every time if there are no movements of any coin to return early for each option 1d/1w/1m/...

I was thinking about this, but it felt suboptimal for such edge case. And this is the same behaviour there is for 1y option.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. I'll modify the behaviour for empty history.

Copy link
Member

Choose a reason for hiding this comment

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

Another thing I'd be a little worried about is mutating startOfTimeFrameDate which is passed as parameter to this function. I'd rather define a new constant for it locally... But maybe it's ok, it's just harder to think about possible consequences. (But the mutation was there even before this PR, I know...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added check for empty account in 2091d87 and kept the timeframe update to better UX when touching the graph.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry but it seems unecessary complicated now, I need to take a proper look and think about it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I still think that best solution is return early if startOfTimeFrameDate === endOfTimeFrameDate because that's easy and will fix the issue. Don't care about the other timeframes it's not worth added complexity.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

simplified 49b17fd

@vytick
Copy link
Contributor Author

vytick commented Sep 25, 2024

/rebase

Copy link

@trezor-ci trezor-ci force-pushed the fix/common/graph/empty-account-rates branch from 49b17fd to e54ea11 Compare September 25, 2024 10:01
@vytick vytick merged commit f107c42 into develop Sep 25, 2024
24 checks passed
@vytick vytick deleted the fix/common/graph/empty-account-rates branch September 25, 2024 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mobile Suite Lite issues and PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error in graph on empty account with range "ALL"
3 participants