chore(status-pill): avoid requests queue
This commit is contained in:
parent
b30a0ccf50
commit
af7622ce17
|
@ -99,12 +99,15 @@ type State = {
|
||||||
showTooltip: boolean,
|
showTooltip: boolean,
|
||||||
};
|
};
|
||||||
|
|
||||||
const MINUTE_IN_MILI = 60000;
|
const INTERVAL_AFTER_READY = 60000;
|
||||||
|
const INTERVAL_BEFORE_READY = 10000;
|
||||||
|
|
||||||
class Component extends PureComponent<Props, State> {
|
class Component extends PureComponent<Props, State> {
|
||||||
timer: ?IntervalID = null;
|
timer: ?IntervalID = null;
|
||||||
|
|
||||||
constructor(props) {
|
requestOnTheFly: boolean = false;
|
||||||
|
|
||||||
|
constructor(props: Props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
|
@ -113,20 +116,18 @@ class Component extends PureComponent<Props, State> {
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
const { getBlockchainStatus } = this.props;
|
this.timer = setInterval(() => this.updateStatus(), INTERVAL_BEFORE_READY);
|
||||||
|
|
||||||
this.timer = setInterval(() => getBlockchainStatus(), 2000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate(prevProps: Props) {
|
componentDidUpdate(prevProps: Props) {
|
||||||
const { getBlockchainStatus, nodeSyncType } = this.props;
|
const { nodeSyncType } = this.props;
|
||||||
if (
|
if (
|
||||||
prevProps.nodeSyncType === NODE_SYNC_TYPES.SYNCING
|
prevProps.nodeSyncType === NODE_SYNC_TYPES.SYNCING
|
||||||
&& nodeSyncType === NODE_SYNC_TYPES.READY
|
&& nodeSyncType === NODE_SYNC_TYPES.READY
|
||||||
) {
|
) {
|
||||||
// if the status is "ready", we can increase the interval to avoid useless rpc calls
|
// if the status is "ready", we can increase the interval to avoid useless rpc calls
|
||||||
this.cleanUpdateInterval();
|
this.cleanUpdateInterval();
|
||||||
this.timer = setInterval(() => getBlockchainStatus(), MINUTE_IN_MILI);
|
this.timer = setInterval(() => this.updateStatus(), INTERVAL_AFTER_READY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,6 +135,22 @@ class Component extends PureComponent<Props, State> {
|
||||||
this.cleanUpdateInterval();
|
this.cleanUpdateInterval();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateStatus = () => {
|
||||||
|
if (this.requestOnTheFly) return;
|
||||||
|
|
||||||
|
this.requestOnTheFly = true;
|
||||||
|
|
||||||
|
const { getBlockchainStatus } = this.props;
|
||||||
|
|
||||||
|
getBlockchainStatus()
|
||||||
|
.then(() => {
|
||||||
|
this.requestOnTheFly = false;
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
this.requestOnTheFly = false;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
cleanUpdateInterval = () => {
|
cleanUpdateInterval = () => {
|
||||||
if (this.timer) {
|
if (this.timer) {
|
||||||
clearInterval(this.timer);
|
clearInterval(this.timer);
|
||||||
|
|
Loading…
Reference in New Issue