@@ -16,7 +16,9 @@ Apps that want to enable WebLN payments can use the client library in
1616
1717### requestProvider()
1818
19- Attempts to acquire and enable a WebLN provider.
19+ Attempts to acquire and enable a WebLN provider. It's recommended
20+ you wait to run this until after ` DOMContentLoaded ` to ensure that
21+ any client providers have had time to inject the WebLN instance.
2022
2123#### Arguments
2224
@@ -31,14 +33,32 @@ Promise<WebLNProvider> (see below) that's already been `enable()`d.
3133* If no providers are available
3234* If the provider rejects the ` enable() ` call (e.g. user doesn't confirm)
3335
36+ #### Example
37+
38+ ``` ts
39+ import { requestProvider } from ' webln/lib/client' ;
40+
41+ let webln;
42+ try {
43+ webln = await requestProvider ();
44+ } catch (err ) {
45+ // Handle users without WebLN
46+ }
47+
48+ // Elsewhere in the code...
49+ if (webln ) {
50+ // Call webln functions
51+ }
52+ ```
53+
3454
3555
3656## Provider Spec
3757
3858Providers must implement the interface provided in ` webln/lib/provider ` .
3959The spec is as follows:
4060
41- ``` . ts
61+ ``` ts
4262export interface WebLNProvider {
4363 /* Determines if the WebLNProvider will allow the page to use it */
4464 enable(): Promise <void >;
@@ -50,7 +70,7 @@ export interface WebLNProvider {
5070 sendPayment(paymentRequest : string ): Promise <SendPaymentResponse >;
5171
5272 /* Prompts the user to provide the page with an invoice */
53- makeInvoice(amount : string ): Promise <RequestInvoiceResponse >;
73+ makeInvoice(amount : string | number | RequestInvoiceArgs ): Promise <RequestInvoiceResponse >;
5474
5575 /* Prompts the user to sign a message with their private key */
5676 signMessage(message : string ): Promise <SignMessageResponse >;
@@ -60,9 +80,10 @@ export interface WebLNProvider {
6080}
6181```
6282
63- See the typescript definitions for more detail about response shapes. The spec
64- is far from complete, and will need more functions to be fully-fledged, but
65- these methods should cover most use-cases.
83+ See the [ typescript definitions] ( https://github.com/wbobeirne/webln/blob/master/src/provider.ts )
84+ for more detail about request objects and response shapes. The spec
85+ is far from complete, and will need more functions to be fully-fledged,
86+ but these methods should cover most use-cases.
6687
6788
6889## Contributing
0 commit comments