Skip to content

Commit

Permalink
Reconnect only if relevant property of active node was changed (#2188)
Browse files Browse the repository at this point in the history
* reconnect only if relevant property of active node was changed

* added comments
  • Loading branch information
myxmaster authored May 17, 2024
1 parent 73ff78f commit 8800627
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions views/Settings/NodeConfiguration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Clipboard from '@react-native-clipboard/clipboard';
import { inject, observer } from 'mobx-react';
import EncryptedStorage from 'react-native-encrypted-storage';
import cloneDeep from 'lodash/cloneDeep';
import differenceBy from 'lodash/differenceBy';
import { Route } from '@react-navigation/native';
import { StackNavigationProp } from '@react-navigation/stack';

Expand Down Expand Up @@ -415,8 +416,12 @@ export default class NodeConfiguration extends React.Component<
};

let nodes: any;
let originalNode: any;
if (settings.nodes) {
nodes = settings.nodes;
if (index != null) {
originalNode = nodes[index];
}
nodes[index !== null ? index : settings.nodes.length] = node;
} else {
nodes = [node];
Expand All @@ -433,14 +438,31 @@ export default class NodeConfiguration extends React.Component<
saved: true
});

if (nodes.length === 1) {
const activeNodeIndex = settings.selectedNode || 0;
if (index === activeNodeIndex) {
// updating active node
if (originalNode != null) {
const diff = differenceBy(
Object.entries(originalNode),
Object.entries(node),
(entry) => entry[0] + entry[1]
).filter(
(entry) =>
entry[0] !== 'nickname' && entry[0] !== 'photo'
);
if (diff.length === 0) {
// only nickname or photo was edited - no reconnect necessary
navigation.goBack();
return;
}
}
if (implementation === 'lightning-node-connect') {
BackendUtils.disconnect();
}
setConnectingStatus(true);
navigation.navigate('Wallet', { refresh: true });
} else {
navigation.navigate('Nodes', { refresh: true });
navigation.goBack();
}
});
};
Expand Down

0 comments on commit 8800627

Please sign in to comment.