Skip to content

Check for balance before auto-selecting token options for purhcase#440

Merged
VGabriel45 merged 3 commits intomasterfrom
fix/checkout_button_enabled_while_no_funds
May 27, 2025
Merged

Check for balance before auto-selecting token options for purhcase#440
VGabriel45 merged 3 commits intomasterfrom
fix/checkout_button_enabled_while_no_funds

Conversation

@VGabriel45
Copy link
Contributor

No description provided.

@VGabriel45 VGabriel45 requested review from a team and 0xsequence-bot as code owners May 13, 2025 11:28
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented May 13, 2025

Deploying web-sdk-react-example with  Cloudflare Pages  Cloudflare Pages

Latest commit: d65e8f6
Status: ✅  Deploy successful!
Preview URL: https://d0f008f1.web-sdk-react-example.pages.dev
Branch Preview URL: https://fix-checkout-button-enabled.web-sdk-react-example.pages.dev

View logs

Copy link
Contributor

@SamueleA SamueleA left a comment

Choose a reason for hiding this comment

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

Two comments:

  1. The console.logs should be cleaned up prior to merging.

  2. I see from the title of the PR that there seems to be a problem with the state of the button. I'm assuming it's getting stuck in a particular state such as disabled?

That being said, the code being deleted shouldn't be deleted outright. It's meant to autoselect the first available option—either the main currency or a swap option—which was a QOL feature that was requested in the past. We should keep that functionality in.

I would say we need to go deeper on the bug we are trying to fix here. I lack details personally. Is it possible to have more details?

Just intuitively though… I know that recently the swap API has been changed and that, at least temporarily, it can return options for which the user doesn't have any funds. This wasn't the case before, and it's likely causing an unexpected side effect with this logic.

The deleted code in the PR seems to assume that the user always has enough funds when autoselecting the swap option (because it's not making any balance checks, unlike the main currency), but that's not true anymore. I can imagine the code auto-selecting a swap option for which the user does not have enough funds, which I believe would make the buy button stuck in a disabled state…

To recap, we shouldn't delete this code (though we could improve it—it looks so bad 😆), we should dig deeper into the bug which prompted this PR and keep in mind my hypothesis outlined above, since I think that might be the issue. Also, with hindsight, a line or two of comments for what the code is doing would have been helpful.

@VGabriel45
Copy link
Contributor Author

Two comments:

  1. The console.logs should be cleaned up prior to merging.
  2. I see from the title of the PR that there seems to be a problem with the state of the button. I'm assuming it's getting stuck in a particular state such as disabled?

That being said, the code being deleted shouldn't be deleted outright. It's meant to autoselect the first available option—either the main currency or a swap option—which was a QOL feature that was requested in the past. We should keep that functionality in.

I would say we need to go deeper on the bug we are trying to fix here. I lack details personally. Is it possible to have more details?

Just intuitively though… I know that recently the swap API has been changed and that, at least temporarily, it can return options for which the user doesn't have any funds. This wasn't the case before, and it's likely causing an unexpected side effect with this logic.

The deleted code in the PR seems to assume that the user always has enough funds when autoselecting the swap option (because it's not making any balance checks, unlike the main currency), but that's not true anymore. I can imagine the code auto-selecting a swap option for which the user does not have enough funds, which I believe would make the buy button stuck in a disabled state…

To recap, we shouldn't delete this code (though we could improve it—it looks so bad 😆), we should dig deeper into the bug which prompted this PR and keep in mind my hypothesis outlined above, since I think that might be the issue. Also, with hindsight, a line or two of comments for what the code is doing would have been helpful.

Thanks for the review @SamueleA. I'll look into this again, I think it was a quick fix for an issue we had which might not exist now because of some other fixes we did, I'll check and get back on this.

@VGabriel45 VGabriel45 changed the title fixed button state Check for balance before auto-selecting token options for purhcase May 22, 2025
@VGabriel45 VGabriel45 merged commit 8703490 into master May 27, 2025
2 checks passed
@VGabriel45 VGabriel45 deleted the fix/checkout_button_enabled_while_no_funds branch May 27, 2025 05:54
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.

3 participants