@@ -5,7 +5,7 @@ import { NutPayment } from "../cashu/pay/nut.js";
55import { sendReq } from "./req.js" ;
66import createDebug from "debug" ;
77import { NDKNWCGetInfoResult , NDKNWCRequestMap , NDKNWCResponseBase , NDKNWCResponseMap } from "./types.js" ;
8- import { CashuMint , CashuWallet } from "@cashu/cashu-ts" ;
8+ import { CashuMint , CashuWallet , MintQuoteResponse } from "@cashu/cashu-ts" ;
99
1010const d = createDebug ( "ndk-wallet:nwc" ) ;
1111
@@ -104,15 +104,28 @@ export class NDKNWCWallet extends EventEmitter<NDKWalletEvents> implements NDKWa
104104 }
105105
106106 const wallet = new CashuWallet ( new CashuMint ( mint ) , { unit } ) ;
107+ let quote : MintQuoteResponse | undefined ;
107108 try {
108- const quote = await wallet . createMintQuote ( amount ) ;
109+ quote = await wallet . createMintQuote ( amount ) ;
109110 d ( 'cashuPay quote' , quote ) ;
111+ } catch ( e ) {
112+ console . error ( 'error creating mint quote' , e ) ;
113+ throw e ;
114+ }
110115
116+ if ( ! quote ) throw new Error ( "Didnt receive a mint quote" ) ;
117+
118+ try {
111119 const res = await this . req ( "pay_invoice" , { invoice : quote . request } ) ;
112120 d ( 'cashuPay res' , res ) ;
121+ } catch ( e ) {
122+ console . error ( 'error paying invoice' , e ) ;
123+ throw e ;
124+ }
113125
114- // todo check that the amount of the invoice matches the amount we want to pay
126+ // todo check that the amount of the invoice matches the amount we want to pay
115127
128+ try {
116129 // mint the tokens
117130 const mintProofs = await wallet . mintProofs ( amount , quote . quote , {
118131 pubkey : payment . p2pk
@@ -124,7 +137,8 @@ export class NDKNWCWallet extends EventEmitter<NDKWalletEvents> implements NDKWa
124137 mint : mint
125138 } ;
126139 } catch ( e ) {
127- console . error ( 'error creating mint quote' , e ) ;
140+ console . error ( 'error minting tokens' , e ) ;
141+ throw e ;
128142 }
129143 }
130144 }
0 commit comments