Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve listener cleanup and subscription handling #2640

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions views/Receive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -661,12 +661,14 @@ export default class Receive extends React.Component<
e
);
if (error === 'EOF') {
this.listener?.remove();
return;
} else if (error) {
console.error(
'Got error from SubscribeInvoices',
[error]
);
this.listener?.remove();
return;
}

Expand Down Expand Up @@ -695,10 +697,11 @@ export default class Receive extends React.Component<
invoice.r_preimage
)
});
this.listener = null;
this.listener?.remove();
}
} catch (error) {
console.error(error);
this.listener?.remove();
}
}
);
Expand All @@ -714,12 +717,14 @@ export default class Receive extends React.Component<
e
);
if (error === 'EOF') {
this.listenerSecondary?.remove();
return;
} else if (error) {
console.error(
'Got error from SubscribeTransactions',
[error]
);
this.listenerSecondary?.remove();
return;
}

Expand Down Expand Up @@ -747,10 +752,11 @@ export default class Receive extends React.Component<
type: 'onchain',
tx: transaction.tx_hash
});
this.listenerSecondary = null;
this.listenerSecondary?.remove();
}
} catch (error) {
console.error(error);
this.listenerSecondary?.remove();
}
}
);
Expand All @@ -769,8 +775,21 @@ export default class Receive extends React.Component<
eventName,
(event: any) => {
if (event.result) {
if (
typeof event.result === 'string' &&
event.result.includes(
'rpc error: code = Canceled'
)
) {
this.listener?.remove();
return;
}
try {
const result = JSON.parse(event.result);
if (result === 'EOF') {
this.listener?.remove();
return;
}
if (result.settled) {
setWatchedInvoicePaid(result.amt_paid_sat);
if (orderId)
Expand All @@ -784,10 +803,11 @@ export default class Receive extends React.Component<
tx: result.payment_request,
preimage: result.r_preimage
});
this.listener = null;
this.listener?.remove();
}
} catch (error) {
console.error(error);
this.listener?.remove();
}
}
}
Expand All @@ -801,8 +821,21 @@ export default class Receive extends React.Component<
eventName2,
(event: any) => {
if (event.result) {
if (
typeof event.result === 'string' &&
event.result.includes(
'rpc error: code = Canceled'
)
) {
this.listenerSecondary?.remove();
return;
}
try {
const result = JSON.parse(event.result);
if (result === 'EOF') {
this.listenerSecondary?.remove();
return;
}
if (
result.dest_addresses.includes(
onChainAddress
Expand All @@ -822,10 +855,11 @@ export default class Receive extends React.Component<
type: 'onchain',
tx: result.tx_hash
});
this.listenerSecondary = null;
this.listenerSecondary?.remove();
}
} catch (error) {
console.error(error);
this.listenerSecondary?.remove();
}
}
}
Expand Down
Loading