From 895b9598225d51f8df7b66b8376cb47c380d40f2 Mon Sep 17 00:00:00 2001 From: Daniel Ternyak Date: Fri, 6 Jul 2018 17:46:26 -0500 Subject: [PATCH] Only check for custom nodes locally once --- .../CustomNodeModal/CustomNodeModal.tsx | 39 ++++++++----------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/common/components/CustomNodeModal/CustomNodeModal.tsx b/common/components/CustomNodeModal/CustomNodeModal.tsx index f286c9f0..b686391a 100644 --- a/common/components/CustomNodeModal/CustomNodeModal.tsx +++ b/common/components/CustomNodeModal/CustomNodeModal.tsx @@ -71,7 +71,7 @@ class CustomNodeModal extends React.Component { constructor(props: Props) { super(props); - this.pollForDefaultNodes(); + this.checkForDefaultNodes(); } public componentDidUpdate(prevProps: Props) { @@ -251,27 +251,22 @@ class CustomNodeModal extends React.Component { ); } - private pollForDefaultNodes() { - const pollingInterval = 3000; - 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 } - ], - { includeDefaults: false } - ); - if (!this.timer) { - return; - } - this.setState({ - defaultNodes: results.filter(r => r.success).map((r, index) => ({ - ...r, - display: `${r.addr}:${r.port}`, - index - })) - }); - }, pollingInterval); + private async checkForDefaultNodes() { + const results = await exists( + [ + // tslint:disable-next-line:no-http-string + { type: 'http', addr: 'http://localhost', port: 8545, timeout: 3000 } + ], + { includeDefaults: false } + ); + + this.setState({ + defaultNodes: results.filter(r => r.success).map((r, index) => ({ + ...r, + display: `${r.addr}:${r.port}`, + index + })) + }); } private renderDefaultNodeDropdown() {