Only check for custom nodes locally once

This commit is contained in:
Daniel Ternyak 2018-07-06 17:46:26 -05:00
parent 06c8ae6e5b
commit 895b959822
No known key found for this signature in database
GPG Key ID: DF212D2DC5D0E245

View File

@ -71,7 +71,7 @@ class CustomNodeModal extends React.Component<Props, State> {
constructor(props: Props) { constructor(props: Props) {
super(props); super(props);
this.pollForDefaultNodes(); this.checkForDefaultNodes();
} }
public componentDidUpdate(prevProps: Props) { public componentDidUpdate(prevProps: Props) {
@ -251,27 +251,22 @@ class CustomNodeModal extends React.Component<Props, State> {
); );
} }
private pollForDefaultNodes() { private async checkForDefaultNodes() {
const pollingInterval = 3000; const results = await exists(
this.timer = window.setInterval(async () => { [
const results = await exists( // tslint:disable-next-line:no-http-string
[ { type: 'http', addr: 'http://localhost', port: 8545, timeout: 3000 }
// tslint:disable-next-line:no-http-string ],
{ type: 'http', addr: 'http://localhost', port: 8545, timeout: 3000 } { includeDefaults: false }
], );
{ includeDefaults: false }
); this.setState({
if (!this.timer) { defaultNodes: results.filter(r => r.success).map((r, index) => ({
return; ...r,
} display: `${r.addr}:${r.port}`,
this.setState({ index
defaultNodes: results.filter(r => r.success).map((r, index) => ({ }))
...r, });
display: `${r.addr}:${r.port}`,
index
}))
});
}, pollingInterval);
} }
private renderDefaultNodeDropdown() { private renderDefaultNodeDropdown() {