Skip to content

Earn button fixes#5452

Merged
samholmes merged 6 commits intodevelopfrom
sam/earn-staking-button-bug
Feb 14, 2025
Merged

Earn button fixes#5452
samholmes merged 6 commits intodevelopfrom
sam/earn-staking-button-bug

Conversation

@samholmes
Copy link
Contributor

@samholmes samholmes commented Feb 12, 2025

This include the fixes for the Earn button, but it also includes some fixes to the error handling for coingecko API queries for the chart data because those were immediately apparent while fixing the original intent.

CHANGELOG

Does this branch warrant an entry to the CHANGELOG?

  • Yes
  • No

Dependencies

none

Requirements

If you have made any visual changes to the GUI. Make sure you have:

  • Tested on iOS device
  • Tested on Android device
  • Tested on small-screen device (iPod Touch)
  • Tested on large-screen device (tablet)

if ('status' in marketChartRange) {
if (marketChartRange.status.error_code === 429) {
// Rate limit error, use our API key as a fallback
if (!fetchUrl.includes('x_cg_pro_api_key')) {
Copy link
Contributor

@peachbits peachbits Feb 12, 2025

Choose a reason for hiding this comment

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

Can you remove the dummy coingecko key from the config cleaner and add a check for it's existence here? Passing a dummy value to the api will produce a 10002 error which is unhandled here and produces an error (an uglier error message with this commit's change). Instead, if the key doesn't exist we should just try the fetch again without an api key.

const { countryCode } = this.state

const showStaking = this.isStakingAvailable()
const hideStaking = !isStakingSupported(this.props.wallet.currencyInfo.pluginId, this.props.currencyCode)
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a remaining corner case that any asset with the currency code FIO (like a custom token) will show the earn button and navigate to actual FIO staking. The FIO plugin special currency info has isStakingSupported: true so that special case in the helper function can be removed.

if (!fetchUrl.includes('x_cg_pro_api_key')) {
if (!fetchUrl.includes('x_cg_pro_api_key') && ENV.COINGECKO_API_KEY !== '') {
fetchUrl = `${COINGECKO_URL_PRO}${fetchPath}&x_cg_pro_api_key=${ENV.COINGECKO_API_KEY}`
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

The continue should be moved outside of the apikey block so that rate-limited requests without keys can be retried as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The continue retries the request. Why should it be outside of the retry path?

Copy link
Contributor

Choose a reason for hiding this comment

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

It needs to be in the 429 block but outside of the apikey block

@samholmes
Copy link
Contributor Author

/rebase

Unknown errors shouldn't be caught by sub-routines, but rather should
be handled at the top of the call-stack.

Errors were not properly logged or shown to the user with this incorrect
try-catch usage. Without it, the user is presented with errors
correctly because it uses the right handler.
Fixes incorrect logic about when to show staking button caused by recent
refactor.
The ActivityIndicator in the earn button was incorrectly centered. The
styles were inappropriate altogether.
Do or do not, there is not try-catch – Yoda

Failure is not an option – Ed Harris
@samholmes samholmes enabled auto-merge February 14, 2025 00:23
@samholmes samholmes force-pushed the sam/earn-staking-button-bug branch from 2f34dc7 to 5a23422 Compare February 14, 2025 00:23
@samholmes samholmes merged commit 849a0e3 into develop Feb 14, 2025
2 checks passed
@samholmes samholmes deleted the sam/earn-staking-button-bug branch February 14, 2025 00:38
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