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: WebLN QR fallback for anon users #1858

Merged
merged 12 commits into from
Mar 1, 2025

Conversation

Soxasora
Copy link
Member

@Soxasora Soxasora commented Feb 3, 2025

Description

Fixes #1758
When a WebLN wallet request fails (eg. cancelling a transaction) it can't be re-requested until next reload, throwing an error and prompting an invoice retry with QR that fails if the user is not logged in.

This fix checks for 'me' on useWalletPayment, throwing a new AnonWalletError that can be caught during QR fallback to show both the WebLN client and the QR payment

Screenshots

Screen.Recording.2025-02-10.at.09.45.51.mov

Additional Context

Fix specifically applied for WebLN

Checklist

Are your changes backwards compatible? Please answer below:
Yes, only affects WebLN wallet

On a scale of 1-10 how well and how have you QA'd this change and any features it might affect? Please answer below:
7, more testing

For frontend changes: Tested on mobile, light and dark mode? Please answer below:
n/a

Did you introduce any new environment variables? If so, call them out explicitly here:
No

@Soxasora Soxasora added the bug label Feb 3, 2025
@Soxasora Soxasora force-pushed the anon_webln_qr_fallback branch from 89da4b4 to 53f63c6 Compare February 3, 2025 11:06
@Soxasora Soxasora marked this pull request as ready for review February 4, 2025 19:53
@Soxasora Soxasora marked this pull request as draft February 6, 2025 14:38
@Soxasora Soxasora marked this pull request as ready for review February 8, 2025 12:24
@huumn huumn requested a review from ekzyis February 8, 2025 19:19
Copy link
Member

@ekzyis ekzyis left a comment

Choose a reason for hiding this comment

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

Mhh, it's a bit hard to understand the implications of these changes. For example, I am worried if the priority of the WebLN wallet makes a difference for these changes here.

I think a better way to fix #1758 is to make useWalletPayment aware of if we're logged in or not.

If we're not logged in, try to pay with WebLN if available (typeof window.webln !== 'undefined') and ignore the rest of the code. That it currently might not ignore it for anons because WebLN might have been enabled (wallets.length > 0) is the bug we should fix imo. 99% of our code for payments assumes you're logged in and thus that anons will never hit that code.

What anons can do in comparison to stackers is very limited (no sender and receiver fallbacks, no retries etc.) so I suspect if we (continue to) handle anons during payments immediately, it will be much easier to implement, maintain, read etc.

@Soxasora Soxasora force-pushed the anon_webln_qr_fallback branch 2 times, most recently from ed59dd3 to 0eaf9d4 Compare February 10, 2025 08:42
@Soxasora Soxasora force-pushed the anon_webln_qr_fallback branch from 0eaf9d4 to c819a05 Compare February 10, 2025 08:42
@Soxasora
Copy link
Member Author

Thanks a lot for the correct redirection, now we call WebLN's sendPayment when QR shows up! But only if we reached QR stage because of AnonWalletError that gets thrown by useWalletPayment if the user attempting to pay is Anon.

I think it's the correct behavior and gives a choice, if anything we could 'await' for sendPayment to throw an error to show the QR if we ever change idea.
Thanks again ^^

@ekzyis ekzyis self-requested a review February 12, 2025 15:20
Copy link
Member

@ekzyis ekzyis left a comment

Choose a reason for hiding this comment

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

You fixed the main issue in #1758:

However, if the WebLN prompt was canceled, we won't show a QR code because anon can't retry invoices.

But we can do better and always allow WebLN payments for anon, even if the wallet wasn't enabled while logged in:

I think anons should be able to use WebLN but that we only try it if it was enabled while signed in is weird.

So I suggested to change the order in which we check for errors.

Other than that, this is approved!

Copy link
Member

@ekzyis ekzyis left a comment

Choose a reason for hiding this comment

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

Approving this because this is more than enough to fix #1758, nice work!

But for the sake of a complete review, I want to mention that I noticed it would be nice if WebLN errors showed up in the QR code. I did not test, but I think that is not the case currently. I also noticed that the other throw statements should probably also use WalletError now. Since it's a small innocent change afaict, I went ahead and did that in ba93d34.

But these were nitpicks, mostly unrelated to the bug described in #1758 and not really important whatsoever so don't worry about not noticing them; just mentioning them to "open your third eye" regarding details even more (lol). We can do the WebLN<>QR error thing when we actually care about it if ever.

edit:

I see that you already considered this in #1858 (comment):

if anything we could 'await' for sendPayment to throw an error to show the QR if we ever change idea.

@Soxasora
Copy link
Member Author

Soxasora commented Feb 24, 2025

I noticed it would be nice if WebLN errors showed up in the QR code. I did not test, but I think that is not the case currently.

Ah yes, that was the case before pivoting to QR and WebLN together, catching the error during retry would show it in QR.

I agree with

We can do the WebLN<>QR error thing when we actually care about it if ever.

I went ahead and did that in ba93d34.
just mentioning them to "open your third eye" regarding details even more (lol)

:D I think I need to let go some of my conservativeness when touching the code, thanks a lot for the review ek ^^

@huumn huumn merged commit f72af08 into stackernews:master Mar 1, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

QR code fallbacks don't work for anon if WebLN enabled
3 participants