Skip to content

Commit

Permalink
Merge pull request #67 from getAlby/feat/nwc-make-invoice
Browse files Browse the repository at this point in the history
Feat/nwc make invoice
  • Loading branch information
rolznz authored Aug 18, 2023
2 parents f4b34f3 + 47eea6f commit faccfd2
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/webln/NostrWeblnProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider {
// TODO: use NIP-47 get_info call
async getInfo(): Promise<GetInfoResponse> {
return {
methods: ["getInfo", "sendPayment", "getBalance"],
methods: ["getInfo", "sendPayment", "addinvoice", "getBalance"],
node: {} as WebLNNode,
supports: ["lightning"],
version: "NWC"
Expand Down Expand Up @@ -205,8 +205,21 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider {
lnurl(lnurl: string): Promise<{ status: 'OK'; } | { status: 'ERROR'; reason: string; }> {
throw new Error('Method not implemented.');
}
makeInvoice(args: string | number | RequestInvoiceArgs): Promise<RequestInvoiceResponse> {
throw new Error('Method not implemented.');
makeInvoice(args: string | number | RequestInvoiceArgs) {
this.checkConnected();

const requestInvoiceArgs: RequestInvoiceArgs | undefined = typeof args === "object" ? (args as RequestInvoiceArgs) : undefined;
const amount = requestInvoiceArgs?.amount ?? (typeof args === 'string' ? parseInt(args) : args as number);

if (!amount) {
throw new Error("No amount specified");
}

return this.executeNip47Request<RequestInvoiceResponse>("make_invoice", "addinvoice", {
amount,
description: requestInvoiceArgs?.defaultMemo
// TODO: description hash and expiry?
}, result => !!result.invoice, result => ({ paymentRequest: result.invoice }));
}
request(method: RequestMethod, args?: unknown): Promise<unknown> {
throw new Error('Method not implemented.');
Expand Down

0 comments on commit faccfd2

Please sign in to comment.