stacker.news/components
ekzyis 310011f05d
Expose WebLN interface via React Context (#749)
* Add LNbits card

* Save LNbits Provider in WebLN context

* Check LNbits connection on save

* refactor: put LNbitsProvider into own file

* Pay invoices using WebLN provider from context

* Remove deprecated FIXME

* Try WebLN provider first

* Fix unhandled promise rejection

* Fix this in sendPayment

* Be optimistic regarding WebLN zaps

This wraps the WebLN payment promise with Apollo cache updates.

We will be optimistics and assume that the payment will succeed and update the cache accordingly.

When we notice that the payment failed, we undo this update.

* Bold strike on WebLN zap

If lightning strike animation is disabled, toaster will be used.

* Rename undo variable to amount

* Fix zap undo

* Add NWC card

* Attempt to check NWC connection using info event

* Fix NaN on zap

Third argument of update is reserved for context

* Fix TypeError in catch of QR code

* Add basic NWC payments

* Wrap LNbits getInfo with try/catch

* EOSE is enough to check NWC connection

* refactor: Wrap WebLN providers into own context

I should have done this earlier

* Show red indicator on error

* Fix useEffect return value

* Fix wrong usage of pubkey

The event pubkey is derived from the secret. Doesn't make sense to manually set it. It's also the wrong pubkey: we're not the wallet service.

* Use p tag in NWC request

* Add comment about required filter field

* Aesthetic changes to NWC sendPayment

* Add TODO about receipt verification

* Fix WebLN attempted again after error

* Fix undefined name

* Add code to mock NWC relay

* Revert "Bold strike on WebLN zap"

This reverts commit a9eb27daec0cd2ef30b56294b05e0056fb5b4184.

* Fix update undo

* Fix lightning strike before payment

* WIP: Wrap WebLN payments with toasts

* add toasts for pending, error, success
* while pending, invoice can be canceled
* there are still some race conditions between payiny the invoice / error on payment and invoice cancellation

* Fix invoice poll using stale value from cache

* Remove unnecessary if

* Make sure that pay_invoice is declared as supported

* Check if WebLN provider is enabled before calling sendPayment

* Fix bad retry

If WebLN payments failed due to insufficient balances, the promise resolved and thus the action was retried but failed immediately since the invoice (still) wasn't paid.

* Fix cache undo update

* Fix no cache update after QR payment

* refactor: Use fragments to undo cache updates

* Remove console.log

* Small changes to NWC relay mocking

* Return SendPaymentResponse

See https://www.webln.guide/building-lightning-apps/webln-reference/webln.sendpayment

* Also undo cache update on retry failure

* Disable NWC mocking

* Fix initialValue not set

But following warning is now shown in console:

"""
Warning: A component is changing a controlled input to be uncontrolled.
This is likely caused by the value changing from a defined to undefined, which should not happen.
Decide between using a controlled or uncontrolled input element for the lifetime of the component. More info: https://reactjs.org/link/controlled-components
"""

* Remove comment since only relevant for blastr (mutiny relay)

* Remove TODO

* Fix duplicate cache update

* Fix QR modal not closed after payment

* Ignore lnbits variable unused

* Use single relay connection for all NWC events

* Fix missing timer and subscription cleanup

* Remove TODO

Confirmed that nostr-tools verifies events and filters for us.

See https://github.com/nbd-wtf/nostr-tools/blob/master/abstract-relay.ts#L161

* Fix switch from controlled to uncontrolled input

* Show 'configure' on error

* Use budgetable instead of async

* Remove EOSE listener

Only nostr.mutinywallet.com didn't respond with info events due to implementation-specific reasons. This is no longer the case.

* Use invoice expiry for NWC timeout

I don't think there was a specific reason why I used 60 seconds initially.

* Validate LNbits config on save

* Validate NWC config on save

* Also show unattach if configuration is invalid

If unattach is only shown if configuration is valid, resetting the configuration is not possible while it's invalid. So we're stuck with a red wallet indicator.

* Fix detection of WebLN payment

It depended on a Apollo cache update function being available. But that is not the case for every WebLN payment.

* Fix formik bag lost

* Use payment instead of zap in toast

* autoscale capture svc by response time

* docs and changes for testing lnbits locally

* Rename configJSON to config

Naming of config object was inconsistent with saveConfig function which was annoying.

Also fixed other inconsistencies between LNbits and NWC provider.

* Allow setting of default payment provider

* Update TODO comment about provider priority

The list 'paymentMethods' is not used yet but is already implemented for future iterations.

* Add wallet security disclaimer

* Update labels

---------

Co-authored-by: Keyan <34140557+huumn@users.noreply.github.com>
Co-authored-by: keyan <keyan.kousha+huumn@gmail.com>
2024-02-08 12:33:13 -06:00
..
webln Expose WebLN interface via React Context (#749) 2024-02-08 12:33:13 -06:00
accordian-item.js territories 2023-12-04 21:34:06 -06:00
action-dropdown.js Quote reply support on text-based posts and comments (#526) 2023-10-03 20:12:12 -05:00
action-tooltip.js upgrade react-bootstrap 2023-07-24 13:53:53 -05:00
adv-post-form.js make fee button less of a hack 2023-11-10 18:18:10 -06:00
adv-post-form.module.css fix height of foward percent on validation err 2023-09-12 17:04:49 -05:00
avatar.js Image uploads (#576) 2023-11-06 14:53:33 -06:00
banners.js Expose WebLN interface via React Context (#749) 2024-02-08 12:33:13 -06:00
banners.module.css Add new visitor welcome banner (#418) 2023-09-11 16:29:45 -05:00
block-height.js Fix client-side error boundary (#623) 2023-11-19 14:24:56 -06:00
bolt11-info.js autowithdraw to lightning address 2024-01-11 13:10:07 -06:00
bookmark.js Toast (#431) 2023-08-25 18:21:51 -05:00
bounty-form.js refactor delete notification (#731) 2024-01-03 16:24:46 -06:00
cancel-button.js make fee button less of a hack 2023-11-10 18:18:10 -06:00
chain-fee.js floor the chain fee float 2023-12-21 17:45:03 -06:00
charts.js improve stat gathering 2024-01-19 15:19:26 -06:00
comment-edit.js refactor delete notification (#731) 2024-01-03 16:24:46 -06:00
comment.js Allow territory founders to pin items (#767) 2024-01-30 11:04:56 -06:00
comment.module.css Allow territory founders to pin items (#767) 2024-01-30 11:04:56 -06:00
comments.js Allow territory founders to pin items (#767) 2024-01-30 11:04:56 -06:00
countdown.js territories 2023-12-04 21:34:06 -06:00
dark-mode.js dark-mode needs to block block 2023-08-04 20:45:12 -05:00
delete.js Provide option to clear withdrawal invoices (#591) 2023-11-09 11:50:43 -06:00
discussion-form.js refactor delete notification (#731) 2024-01-03 16:24:46 -06:00
dont-link-this.js opt-in moderation for territory founders 2023-12-29 18:05:16 -06:00
error-boundary.js Fix client-side error boundary (#623) 2023-11-19 14:24:56 -06:00
fee-button.js make anon fees consistent 2023-12-10 16:56:22 -06:00
fee-button.module.css small receipt styling 2023-11-10 09:22:14 -06:00
footer-rewards.js allow viewing reward ranges 2023-08-29 19:13:21 -05:00
footer.js Remove plausible link (#762) 2024-01-17 18:11:00 -06:00
footer.module.css fix dark mode 2023-08-04 19:21:51 -05:00
form.js Expose WebLN interface via React Context (#749) 2024-02-08 12:33:13 -06:00
form.module.css Custom date selector for more pages (#567) 2023-11-08 18:15:36 -06:00
hat.js better organize user graphql types 2023-11-09 19:05:35 -06:00
header.js remove snow 2023-12-25 18:05:45 -06:00
header.module.css Fix link to profile matching current URL, not profile (#395) 2023-08-15 12:54:24 -05:00
hidden-wallet-summary.js merge non-normalized user subtypes fixing #645 2023-11-20 09:05:02 -06:00
image.js add ids to all toasts to help id rogue toasts 2024-01-28 13:26:32 -06:00
info.js upgrade react-bootstrap 2023-07-24 13:53:53 -05:00
invite.js full powered editing 2022-08-18 13:15:24 -05:00
invoice-status.js make anon posting less hidden, add anon info button explainer 2023-08-10 14:41:56 -05:00
invoice.js Expose WebLN interface via React Context (#749) 2024-02-08 12:33:13 -06:00
invoice.module.css ready for invoices 2021-05-06 16:15:22 -05:00
item-act.js Expose WebLN interface via React Context (#749) 2024-02-08 12:33:13 -06:00
item-full.js only open related posts when there aren't comments 2024-01-20 15:17:34 -06:00
item-info.js allow pins to be zapped but not from pin position 2024-02-03 15:27:36 -06:00
item-job.js mute territories 2023-12-30 17:16:09 -06:00
item.js allow pins to be zapped but not from pin position 2024-02-03 15:27:36 -06:00
item.module.css Allow territory founders to pin items (#767) 2024-01-30 11:04:56 -06:00
items.js Fix pinned items don't show up in home 2024-02-04 22:15:18 +01:00
items.module.css working search 2022-01-27 13:18:48 -06:00
job-form.js refactor delete notification (#731) 2024-01-03 16:24:46 -06:00
layout.js better search layout spacing 2023-10-26 13:01:01 -05:00
layout.module.css Revert "Revert "shield your eyes; massive, squashed refactor; nextjs/react/react-dom/apollo upgrades"" 2023-07-23 10:08:43 -05:00
lightning-auth.js remove slashtags completely 2023-08-17 13:40:21 -05:00
lightning-auth.module.css Notifications with nostr info (#368) 2023-08-08 13:19:31 -05:00
lightning.js Revert "halloween animation" 2023-11-01 11:57:55 -05:00
link-form.js refactor delete notification (#731) 2024-01-03 16:24:46 -06:00
logger.js Only close notifications manually on iOS (#729) 2024-01-03 11:56:29 -06:00
login-button.js remove slashtags completely 2023-08-17 13:40:21 -05:00
login.js remove slashtags completely 2023-08-17 13:40:21 -05:00
login.module.css more invite work 2021-10-15 13:05:34 -05:00
me.js merge non-normalized user subtypes fixing #645 2023-11-20 09:05:02 -06:00
modal.js refactor: replace recursion with promise sequence in `useInvoiceable` (#752) 2024-01-16 18:40:11 -06:00
more-footer.js search/related posts refinements 2024-01-17 17:39:48 -06:00
mute.js mutes 2023-09-28 15:02:25 -05:00
nostr-auth.js add timeouts for nostr extension calls 2023-12-19 16:01:48 -06:00
notifications.js improved comment linking 2024-01-17 19:03:49 -06:00
notifications.module.css remove list jitter by initially preferring ssr 2023-08-06 13:04:25 -05:00
page-loading.js Revert "Revert "shield your eyes; massive, squashed refactor; nextjs/react/react-dom/apollo upgrades"" 2023-07-23 10:08:43 -05:00
past-bounties.js upgrade react-bootstrap 2023-07-24 13:53:53 -05:00
pay-bounty.js unify zap/downzap/bounty mutation 2023-12-26 16:51:47 -06:00
pay-bounty.module.css upgrade react-bootstrap 2023-07-24 13:53:53 -05:00
payer-data.js LUD-18 Service Support (#518) 2023-10-03 14:35:53 -05:00
poll-form.js refactor delete notification (#731) 2024-01-03 16:24:46 -06:00
poll.js reuse debounce hook more places 2023-10-06 15:01:51 -05:00
poll.module.css increase poll choice length to 40 chars 2023-09-28 16:52:11 -05:00
post.js refine territory details on post form 2024-01-08 19:02:00 -06:00
price.js Add chain fees to price carousel (#658) 2023-12-20 16:06:22 -06:00
qr.js Expose WebLN interface via React Context (#749) 2024-02-08 12:33:13 -06:00
recent-header.js territories 2023-12-04 21:34:06 -06:00
related.js search/related posts refinements 2024-01-17 17:39:48 -06:00
reply.js improved comment linking 2024-01-17 19:03:49 -06:00
reply.module.css add spacing to comment reply button 2023-10-26 12:17:43 -05:00
root.js improve comment performance 2023-05-06 16:51:17 -05:00
search.js fix custom dates to use ms since epoch 2023-11-14 10:23:44 -06:00
search.module.css Add a date selector to the search function (#494) 2023-10-04 14:44:06 -05:00
seo.js use capture microservice 2024-01-30 18:22:40 -06:00
serviceworker.js Fix usage of hardcoded strings for sw message types (#730) 2024-01-03 14:02:01 -06:00
share.js improved comment linking 2024-01-17 19:03:49 -06:00
snl.js add removed snl banner 2023-08-25 18:43:50 -05:00
snow.js Christmas zaps (#707) 2023-12-24 16:49:41 -06:00
sub-select.js autowithdraw to lightning address 2024-01-11 13:10:07 -06:00
sub-select.module.css refine territory details on post form 2024-01-08 19:02:00 -06:00
subscribe.js Toast (#431) 2023-08-25 18:21:51 -05:00
subscribeUser.js Proposal: User Subscriptions: separate posts and comments (#470) 2023-09-18 13:20:02 -05:00
table-of-contents.js handle hash urls with 'view more' 2023-12-20 18:16:34 -06:00
territory-form.js fix clicks on billing types label not toggling correct radio 2024-02-03 16:59:37 -05:00
territory-header.js Allow territory founders to pin items (#767) 2024-01-30 11:04:56 -06:00
territory-payment-due.js territory billing notifications 2024-01-03 15:20:10 -06:00
text.js Format internal links as #<id> (#765) 2024-01-24 17:29:52 -06:00
text.module.css improved footnote styling and list styling 2024-01-28 13:26:32 -06:00
toast.js Use toast body as default tag 2024-02-01 16:17:54 +01:00
toast.module.css Add tag and cancel support to toasts 2024-02-01 16:17:54 +01:00
top-header.js fix custom dates to use ms since epoch 2023-11-14 10:23:44 -06:00
upvote.js Expose WebLN interface via React Context (#749) 2024-02-08 12:33:13 -06:00
upvote.module.css fix dark mode 2023-08-04 19:21:51 -05:00
usage-header.js fix custom dates to use ms since epoch 2023-11-14 10:23:44 -06:00
use-crossposter.js Add tag and cancel support to toasts 2024-02-01 16:17:54 +01:00
use-data.js remove list jitter by initially preferring ssr 2023-08-06 13:04:25 -05:00
use-debounce-callback.js remove unused debounce callback deps 2023-10-06 16:34:16 -05:00
use-no-initial-effect.js reuse debounce hook more places 2023-10-06 15:01:51 -05:00
use-quote-reply.js refine quote reply hook and #643 2023-11-21 12:35:37 -06:00
user-header.js better organize user graphql types 2023-11-09 19:05:35 -06:00
user-header.module.css upgrade react-bootstrap 2023-07-24 13:53:53 -05:00
user-list.js better organize user graphql types 2023-11-09 19:05:35 -06:00
wallet-card.js Expose WebLN interface via React Context (#749) 2024-02-08 12:33:13 -06:00