Merge pull request #119 from Forte11Cuba/fix/mint-issued-event-race-condition

fix: deliver mint Issued event before metadata await (closes #115)
This commit is contained in:
Forte11
2026-04-19 05:09:08 -06:00
committed by GitHub
2 changed files with 18 additions and 12 deletions
+15 -8
View File
@@ -1354,24 +1354,31 @@ class WalletProvider extends ChangeNotifier {
amount: amount,
description: description,
).listen(
(quote) async {
(quote) {
// Guardar invoice temprano en SharedPreferences
if (quote.state == MintQuoteState.unpaid) {
invoiceBolt11 = quote.request;
_savePendingMintInvoice(quote.id, quote.request, mintUrl, unit, amount);
}
// Cuando se completa, guardar metadata, confetti, limpiar pending
// Reenviar a la UI ANTES de cualquier await: Rust cierra el stream
// inmediatamente tras emitir Issued, y onDone corre durante el await
// de _saveMintMetadata, cerrando el controller antes de que el evento
// llegue al screen.
if (!controller.isClosed) {
controller.add(quote);
}
// Metadata async fire-and-forget (no bloquea el forward)
if (quote.state == MintQuoteState.issued && invoiceBolt11 != null) {
final saved = await _saveMintMetadata(wallet, invoiceBolt11!, quote.transactionId);
final invoice = invoiceBolt11!;
unawaited(
_saveMintMetadata(wallet, invoice, quote.transactionId).then((saved) {
// Only remove pending invoice if metadata was saved;
// otherwise _matchPendingMintInvoices can recover it on next startup
if (saved) _removePendingMintInvoice(quote.id);
}
// Reenviar a la UI (si sigue escuchando)
if (!controller.isClosed) {
controller.add(quote);
}),
);
}
},
onError: (error) {
+1 -2
View File
@@ -841,8 +841,7 @@ class _RequestScreenState extends State<RequestScreen> {
_status = RequestStatus.received;
_receivedAmount = amount;
});
final walletProvider = context.read<WalletProvider>();
walletProvider.confettiController.fire();
// Confetti se dispara globalmente desde WalletProvider._saveMintMetadata
// TODO: re-enable once CDK fixes NIP-17 (cashubtc/cdk#1807)
// Only remove pending Nostr request if this screen created one.
// Disabled while Nostr payment requests are disabled to avoid