Skip to content

Conversation

Dunsin-cyber
Copy link
Contributor

@Dunsin-cyber Dunsin-cyber commented May 20, 2025

This PR addresses issue #300 by adding standalone pure HTML demos for the core Bitcoin Connect web components. The goal is to showcase how to use each component independently without any framework, making it easier for developers to understand and integrate them in basic setups.

✅ Added:

  • HTML demo for <bc-pay-button />
  • Demo for programmatically using bitcoin-connect

Each demo includes:

  • Proper usage of attributes like invoice, payment-methods, title, etc.

  • Minimal styling and code for clarity

📂 Location:

All demos are added to the demos/html/ directory.

This structure allows easier future expansion and clearer documentation for developers using the package without build tools or frameworks.

@Dunsin-cyber Dunsin-cyber force-pushed the feature/pure-html-demos branch from 32c8831 to 7b173af Compare May 20, 2025 23:32
@Dunsin-cyber
Copy link
Contributor Author

Hi @rolznz, I've implemented the corrections you suggested. Apologies for the delay in pushing, I needed to set up a personal Lightning channel with Alby Hub to properly test everything, and also took some time to better understand how the codebase works.

I ran into an issue with the bc:onpaid event not consistently firing when payments are made externally (i.e. outside the modal). I tried listening for the event like this:

 const waitForModal = setInterval(() => {
   const modal = document.querySelector('bc-modal');
   if (modal) {
     clearInterval(waitForModal);
     modal.addEventListener('bc:onpaid', (e) => {
       console.log('Payment succeeded!', e.detail);
       setPaid({
         preimage: e.detail.preimage,
       });
     });
   }
 }, 50);

However, it seems to only capture internal payments made through the modal, not external ones.

As a workaround, I implemented a polling mechanism that checks the invoice status every second to confirm when payment has been made.

would love your thought on improving this or if there's a preferred approach.

@rolznz
Copy link
Collaborator

rolznz commented May 25, 2025

Hi @Dunsin-cyber how you do the polling looks good

@Dunsin-cyber
Copy link
Contributor Author

Alright, thank you. I’d take this PR out of draft status and move it to review.

@Dunsin-cyber Dunsin-cyber marked this pull request as ready for review May 25, 2025 12:06
@Dunsin-cyber Dunsin-cyber changed the title Add standalone pure HTML demos for Bitcoin Connect web components Add HTML demos for Bitcoin Connect's core web components May 25, 2025
@Dunsin-cyber
Copy link
Contributor Author

@rolznz , When you have a moment, could you please review this and let me know if there are any other demo I should make?

@Dunsin-cyber
Copy link
Contributor Author

Just pushed a tidy-up @rolznz
Clarified the README and added clearer script references for the demos.

@Dunsin-cyber Dunsin-cyber force-pushed the feature/pure-html-demos branch from a675475 to 732d30e Compare June 17, 2025 15:28
@Dunsin-cyber
Copy link
Contributor Author

also @rolznz , I noticed that when using <bc-pay-button>, the bc:onpaid event doesn’t fire when listening directly on the button element. it only fires globally on window. This is because the event is dispatched from within launchPaymentModal (specifically from the bc-payment component), but it doesn't bubble up through the bc-pay-button itself.

To improve modularity and make it easier to listen for events in scoped components or apps using Web Components (or frameworks like React/Vue), I suggest forwarding the event from bc-pay-button like this:

const { setPaid } = launchPaymentModal({
  onPaid: (response) => {
    this._paid = true;
    this.dispatchEvent(new CustomEvent('bc:onpaid', {
      detail: response,
      bubbles: true,
      composed: true,
    }));
  },
  invoice: this.invoice,
  paymentMethods: this.paymentMethods,
});

This allows users to do:

payButton.addEventListener('bc:onpaid', (e) => {
  console.log('got paid', e.detail);
});

instead of having to rely on a global window listener, which can be problematic in apps with multiple buttons or more complex scopes.

@rolznz
Copy link
Collaborator

rolznz commented Jun 18, 2025

@Dunsin-cyber forwarding the events sounds good. Could you create a separate issue and PR for that?

Copy link
Collaborator

@rolznz rolznz left a comment

Choose a reason for hiding this comment

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

tACK

@rolznz rolznz merged commit 439a346 into getAlby:master Jun 18, 2025
2 checks passed
@Dunsin-cyber
Copy link
Contributor Author

@Dunsin-cyber forwarding the events sounds good. Could you create a separate issue and PR for that?

alright.

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