Skip to content

Commit

Permalink
Merge pull request #170 from getAlby/fix/lookup-invoice
Browse files Browse the repository at this point in the history
fix: lookup invoice does not return preimage
  • Loading branch information
rolznz authored Dec 19, 2023
2 parents 978530f + 832e006 commit 0a8282e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@getalby/sdk",
"version": "3.2.0",
"version": "3.2.1",
"description": "The SDK to integrate with Nostr Wallet Connect and the Alby API",
"repository": "https://github.com/getAlby/js-sdk.git",
"bugs": "https://github.com/getAlby/js-sdk/issues",
Expand Down Expand Up @@ -48,7 +48,7 @@
"@types/node": "^20.8.6",
"@typescript-eslint/eslint-plugin": "^6.3.0",
"@typescript-eslint/parser": "^6.3.0",
"@webbtc/webln-types": "^2.0.1",
"@webbtc/webln-types": "^3.0.0",
"browserify": "^17.0.0",
"eslint": "^8.46.0",
"eslint-config-prettier": "^9.0.0",
Expand Down
39 changes: 23 additions & 16 deletions src/webln/NostrWeblnProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,18 @@ const NWCs: Record<string, NostrWebLNOptions> = {
},
};

// TODO: move to webln-types package
export interface ListTransactionsArgs {
// TODO: review fields (replace with camelCase) and consider move to webln-types package
export type Transaction = Nip47Transaction;

// TODO: consider moving to webln-types package
export type ListTransactionsResponse = {
transactions: Transaction[];
};

// TODO: consider moving to webln-types package
export type ListTransactionsArgs = Nip47ListTransactionsArgs;

interface Nip47ListTransactionsArgs {
from?: number;
until?: number;
limit?: number;
Expand All @@ -46,8 +56,11 @@ export interface ListTransactionsArgs {
type?: "incoming" | "outgoing";
}

// TODO: move to webln-types package
export interface Transaction {
type Nip47ListTransactionsResponse = {
transactions: Nip47Transaction[];
};

type Nip47Transaction = {
type: string;
invoice: string;
description: string;
Expand All @@ -60,12 +73,7 @@ export interface Transaction {
created_at: number;
expires_at: number;
metadata?: Record<string, unknown>;
}

// TODO: move to webln-types package
export interface ListTransactionsResponse {
transactions: Transaction[];
}
};

interface NostrWebLNOptions {
authorizationUrl?: string; // the URL to the NWC interface for the user to confirm the session
Expand All @@ -89,11 +97,6 @@ type Nip47GetInfoResponse = {
methods: string[];
};

type Nip47ListTransactionsResponse = {
transactions: Nip47Transaction[];
};
type Nip47Transaction = Transaction;

type Nip47PayResponse = {
preimage: string;
};
Expand Down Expand Up @@ -392,9 +395,13 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider {

return this.executeNip47Request<LookupInvoiceResponse, Nip47Transaction>(
"lookup_invoice",
args,
{
invoice: args.paymentRequest,
payment_hash: args.paymentHash,
},
(result) => !!result.invoice,
(result) => ({
preimage: result.preimage,
paymentRequest: result.invoice,
paid: !!result.settled_at,
}),
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2211,10 +2211,10 @@
"@typescript-eslint/types" "6.4.0"
eslint-visitor-keys "^3.4.1"

"@webbtc/webln-types@^2.0.1":
version "2.0.1"
resolved "https://registry.yarnpkg.com/@webbtc/webln-types/-/webln-types-2.0.1.tgz#760756e2a50e63392c8b3d129b59d172cd11d5dc"
integrity sha512-magyMAiN8u7PsECuj7PfFsStMne30E3QiyNfurL4mTTHse3lmG2Pkh3hDv3jh+D3PTWMfCgv1WFUKVmEgKbBkA==
"@webbtc/webln-types@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@webbtc/webln-types/-/webln-types-3.0.0.tgz#448b2138423865087ba8859e9e6430fc2463b864"
integrity sha512-aXfTHLKz5lysd+6xTeWl+qHNh/p3qVYbeLo+yDN5cUDmhie2ZoGvkppfWxzbGkcFBzb6dJyQ2/i2cbmDHas+zQ==

JSONStream@^1.0.3, JSONStream@^1.3.5:
version "1.3.5"
Expand Down

0 comments on commit 0a8282e

Please sign in to comment.