Skip to content

Fetch token rates in batches of 100#3650

Merged
mcmire merged 8 commits intomainfrom
fetch-token-rates-in-batches
Dec 12, 2023
Merged

Fetch token rates in batches of 100#3650
mcmire merged 8 commits intomainfrom
fetch-token-rates-in-batches

Conversation

@mcmire
Copy link
Copy Markdown
Contributor

@mcmire mcmire commented Dec 12, 2023

Explanation

In cases where users have an enormous amount of tokens, we don't want to slow down our Price API with large requests. To combat this, when fetching token rates, send requests in batches of 100.

References

Fixes #3573.

Changelog

(Updated in PR)

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate

In cases where users have an enormous amount of tokens, we don't want to
slow down our Price API with large requests. To combat this, when
fetching token rates, send requests in batches of 100.
@mcmire mcmire marked this pull request as ready for review December 12, 2023 16:06
@mcmire mcmire requested a review from a team as a code owner December 12, 2023 16:06
Gudahtt
Gudahtt previously approved these changes Dec 12, 2023
Copy link
Copy Markdown
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

LGTM!

[tokenContractAddress]:
tokenPrice.value * fallbackCurrencyToNativeCurrencyConversionRate,
[tokenContractAddress]: tokenValue
? tokenValue * fallbackCurrencyToNativeCurrencyConversionRate
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, I don't totally follow why this additional branch was needed here. Is it now possible for tokenValue to be falsey?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Realistically, no, but because I've changed #fetchAndMapExchangeRatesForUnsupportedNativeCurrency to use #fetchAndMapExchangeRatesForSupportedNativeCurrency, contractExchangeRates is now a type of ContractExchangeRates, and that is defined as:

interface ContractExchangeRates {
  [address: string]: number | undefined;
}

So that means that tokenValue here is number | undefined.

Copy link
Copy Markdown
Member

@Gudahtt Gudahtt Dec 12, 2023

Choose a reason for hiding this comment

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

Interesting.... that | undefined seems like a mistake, I don't see a case where it is undefined.

Pre-existing issue though, and not a blocker, this doesn't really hurt

@mcmire mcmire merged commit e1ff173 into main Dec 12, 2023
@mcmire mcmire deleted the fetch-token-rates-in-batches branch December 12, 2023 21:51
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.

[assets-controllers] Fetch token rates in batches to avoid hitting limits

2 participants