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

Embedded LND: remove listeners when changing to other connection #1817

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions backends/EmbeddedLND.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import LND from './LND';
import OpenChannelRequest from '../models/OpenChannelRequest';
import Base64Utils from './../utils/Base64Utils';
import { removeListeners } from '../utils/LndMobileUtils';

import lndMobile from '../lndmobile/LndMobileInjection';

Expand Down Expand Up @@ -167,6 +168,7 @@ export default class EmbeddedLND extends LND {
// subscribeTransactions = () => this.getRequest('/v1/transactions/subscribe');
// initChannelAcceptor = async (callback: any) =>
// await channelAcceptor(callback);
disconnect = () => removeListeners();

supportsMessageSigning = () => true;
supportsLnurlAuth = () => true;
Expand Down
5 changes: 5 additions & 0 deletions utils/LndMobileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ export async function initializeLnd(isTestnet?: boolean, rescan?: boolean) {
await initialize();
}

export function removeListeners() {
LndMobileEventEmitter.removeAllListeners &&
LndMobileEventEmitter.removeAllListeners('SubscribeState');
}

export async function startLnd(walletPassword: string) {
const { checkStatus, startLnd, decodeState, subscribeState } =
lndMobile.index;
Expand Down
4 changes: 3 additions & 1 deletion views/Settings/Nodes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ export default class Nodes extends React.Component<NodesProps, NodesState> {
}).then(() => {
if (
currentImplementation ===
'lightning-node-connect'
'lightning-node-connect' ||
currentImplementation ===
'embedded-lnd'
) {
BackendUtils.disconnect();
}
Expand Down