Skip to content

Commit

Permalink
refresh faucet config after reconnecting websocket (likely config cha…
Browse files Browse the repository at this point in the history
…nge)
  • Loading branch information
pk910 committed Sep 16, 2024
1 parent 30e3c53 commit 156daab
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions faucet-client/src/common/FaucetContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ export interface IFaucetContext {
hideDialog(dialogId: number): void;
getContainer(): HTMLElement;

refreshConfig(): void;

}
7 changes: 7 additions & 0 deletions faucet-client/src/components/FaucetPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export class FaucetPage extends React.PureComponent<IFaucetPageProps, IFaucetPag
private configRefreshInterval: NodeJS.Timer;
private faucetContainerElement: HTMLElement;
private lastConfigRefresh = 0;
private lastConfigRefreshStart = 0;
private statusAlertIdCounter = 0;
private notificationIdCounter = 0;
private dialogIdCounter = 0;
Expand Down Expand Up @@ -98,6 +99,7 @@ export class FaucetPage extends React.PureComponent<IFaucetPageProps, IFaucetPag
showDialog: (dialogProps: IFaucetDialogProps) => this.showDialog(dialogProps),
hideDialog: (dialogId: number) => this.hideDialog(dialogId),
getContainer: () => this.faucetContainerElement,
refreshConfig: () => this.loadFaucetConfig(),
};

this.state = {
Expand Down Expand Up @@ -138,6 +140,11 @@ export class FaucetPage extends React.PureComponent<IFaucetPageProps, IFaucetPag
}

private loadFaucetConfig() {
let now = (new Date()).getTime();
if(now - this.lastConfigRefreshStart < 10000)
return;
this.lastConfigRefreshStart = now;

this.pageContext.faucetApi.getFaucetConfig().then((faucetConfig) => {
this.lastConfigRefresh = (new Date()).getTime();
this.setState({
Expand Down
5 changes: 4 additions & 1 deletion faucet-client/src/components/mining/MiningPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ export class MiningPage extends React.PureComponent<IMiningPageProps, IMiningPag
"clientOpen": {
emmiter: this.powClient,
event: "open",
listener: () => this.updateConnectionState(true),
listener: () => {
this.props.pageContext.refreshConfig();
this.updateConnectionState(true);
},
},
"clientClose": {
emmiter: this.powClient,
Expand Down

0 comments on commit 156daab

Please sign in to comment.