Skip to content

Commit

Permalink
fix: invoice status change
Browse files Browse the repository at this point in the history
  • Loading branch information
apotdevin committed Mar 23, 2021
1 parent f32e90a commit cced708
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions server/schema/invoice/resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { randomBytes, createHash } from 'crypto';
import { once } from 'events';
import {
payViaRoutes,
createInvoice,
Expand Down Expand Up @@ -31,16 +30,20 @@ export const invoiceResolvers = {

const sub = subscribeToInvoice({ id, lnd });

await once(sub, 'invoice_updated');

return Promise.race([
once(sub, 'invoice_updated'),
new Promise(resolve => {
sub.on('invoice_updated', (data: any) => {
if (data.is_confirmed) {
resolve(true);
}
});
}),
new Promise((_, reject) =>
setTimeout(() => reject(new Error('timeout')), 90000)
),
])
.then((res: any) => {
if (res?.[0] && res[0].is_confirmed) {
if (res) {
return 'paid';
}
return 'not_paid';
Expand Down

0 comments on commit cced708

Please sign in to comment.