Skip to content

Commit

Permalink
handle canceling of streamSubscriptions in Zaps
Browse files Browse the repository at this point in the history
  • Loading branch information
frnandu committed Dec 28, 2024
1 parent 6d092b0 commit 6d808d4
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/ndk/lib/domain_layer/usecases/zaps/zaps.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class Zaps {
relays: relays,
eventId: eventId);
}
InvoiceResponse? invoice = await fecthInvoice(
final invoice = await fecthInvoice(

Check warning on line 115 in packages/ndk/lib/domain_layer/usecases/zaps/zaps.dart

View check run for this annotation

Codecov / codecov/patch

packages/ndk/lib/domain_layer/usecases/zaps/zaps.dart#L115

Added line #L115 was not covered by tests
lud16Link: lud16Link!,
comment: comment,
amountSats: amountSats,
Expand All @@ -122,10 +122,10 @@ class Zaps {
return ZapResponse(error: "couldn't get invoice from $lnurl");
}
try {
PayInvoiceResponse payResponse = await _nwc.payInvoice(nwcConnection,
final payResponse = await _nwc.payInvoice(nwcConnection,

Check warning on line 125 in packages/ndk/lib/domain_layer/usecases/zaps/zaps.dart

View check run for this annotation

Codecov / codecov/patch

packages/ndk/lib/domain_layer/usecases/zaps/zaps.dart#L125

Added line #L125 was not covered by tests
invoice: invoice.invoice, timeout: Duration(seconds: 10));
if (payResponse.preimage.isNotEmpty && payResponse.errorCode == null) {
ZapResponse zapResponse = ZapResponse(payInvoiceResponse: payResponse);
final zapResponse = ZapResponse(payInvoiceResponse: payResponse);

Check warning on line 128 in packages/ndk/lib/domain_layer/usecases/zaps/zaps.dart

View check run for this annotation

Codecov / codecov/patch

packages/ndk/lib/domain_layer/usecases/zaps/zaps.dart#L128

Added line #L128 was not covered by tests
if (zapRequest != null &&
fetchZapReceipt &&
invoice.nostrPubkey != null &&
Expand All @@ -143,6 +143,9 @@ class Zaps {
final timeout = Timer(Duration(seconds: 30), () {
_requests
.closeSubscription(zapResponse.zapReceiptResponse!.requestId);
if (zapResponse.streamSubscription!=null) {
zapResponse.streamSubscription!.cancel();

Check warning on line 147 in packages/ndk/lib/domain_layer/usecases/zaps/zaps.dart

View check run for this annotation

Codecov / codecov/patch

packages/ndk/lib/domain_layer/usecases/zaps/zaps.dart#L146-L147

Added lines #L146 - L147 were not covered by tests
}
Logger.log
.w("timed out waiting for zap receipt for invoice $invoice");
});
Expand Down

0 comments on commit 6d808d4

Please sign in to comment.