Skip to content

Commit 6ca06d4

Browse files
committed
Merge branch 'master' of github.com:wbobeirne/webln
2 parents b094cd9 + ad02311 commit 6ca06d4

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

README.md

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

3858
Providers must implement the interface provided in `webln/lib/provider`.
3959
The spec is as follows:
4060

41-
```.ts
61+
```ts
4262
export 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

src/provider.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ export interface SendPaymentResponse {
1616
preimage: string;
1717
}
1818

19+
export interface RequestInvoiceArgs {
20+
amount?: string | number;
21+
defaultAmount?: string | number;
22+
minimumAmount?: string | number;
23+
maximumAmount?: string | number;
24+
defaultMemo?: string;
25+
}
26+
1927
export interface RequestInvoiceResponse {
2028
paymentRequest: string;
2129
}
@@ -28,7 +36,7 @@ export interface WebLNProvider {
2836
enable(): Promise<void>;
2937
getInfo(): Promise<GetInfoResponse>;
3038
sendPayment(paymentRequest: string): Promise<SendPaymentResponse>;
31-
makeInvoice(amount: string): Promise<RequestInvoiceResponse>;
39+
makeInvoice(args: string | number | RequestInvoiceArgs): Promise<RequestInvoiceResponse>;
3240
signMessage(message: string): Promise<SignMessageResponse>;
3341
verifyMessage(signedMessage: string, rawMessage: string): Promise<void>;
3442
}

0 commit comments

Comments
 (0)