|
|
@ -25,6 +25,7 @@ class SyncIndicator extends connect(store)(LitElement) { |
|
|
|
this.hasCoreRunning = true; |
|
|
|
this.hasCoreRunning = true; |
|
|
|
this.seenWelcomeSync = false; |
|
|
|
this.seenWelcomeSync = false; |
|
|
|
this.numberOfTries = 0; |
|
|
|
this.numberOfTries = 0; |
|
|
|
|
|
|
|
this.hasOpened = false |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static get styles() { |
|
|
|
static get styles() { |
|
|
@ -109,51 +110,59 @@ class SyncIndicator extends connect(store)(LitElement) { |
|
|
|
|
|
|
|
|
|
|
|
async getDaySummary() { |
|
|
|
async getDaySummary() { |
|
|
|
try { |
|
|
|
try { |
|
|
|
const endpoint = `${this.nodeUrl}/admin/summary/?apiKey=${this.myNode.apiKey}`; |
|
|
|
this.fetchingSummary = true |
|
|
|
const res = await fetch(endpoint); |
|
|
|
|
|
|
|
const data = await res.json(); |
|
|
|
|
|
|
|
let blockTimeInSeconds = null; |
|
|
|
|
|
|
|
if (data.blockCount) { |
|
|
|
|
|
|
|
const blockTime = 1440 / data.blockCount; |
|
|
|
|
|
|
|
blockTimeInSeconds = blockTime * 60; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const endpointLastBlock = `${this.nodeUrl}/blocks/last`; |
|
|
|
const endpointLastBlock = `${this.nodeUrl}/blocks/last`; |
|
|
|
const resLastBlock = await fetch(endpointLastBlock); |
|
|
|
const resLastBlock = await fetch(endpointLastBlock); |
|
|
|
const dataLastBlock = await resLastBlock.json(); |
|
|
|
const dataLastBlock = await resLastBlock.json(); |
|
|
|
const timestampNow = Date.now(); |
|
|
|
const timestampNow = Date.now(); |
|
|
|
const currentBlockTimestamp = dataLastBlock.timestamp; |
|
|
|
const currentBlockTimestamp = dataLastBlock.timestamp; |
|
|
|
if (blockTimeInSeconds && currentBlockTimestamp < timestampNow) { |
|
|
|
if (currentBlockTimestamp < timestampNow) { |
|
|
|
const diff = timestampNow - currentBlockTimestamp; |
|
|
|
const diff = timestampNow - currentBlockTimestamp; |
|
|
|
const inSeconds = diff / 1000; // millisecs to secs
|
|
|
|
const inSeconds = diff / 1000; // millisecs to secs
|
|
|
|
const inBlocks = inSeconds / blockTimeInSeconds; |
|
|
|
const inBlocks = inSeconds / 70; |
|
|
|
this.blocksBehind = parseInt(inBlocks); |
|
|
|
this.blocksBehind = parseInt(inBlocks); |
|
|
|
if (inBlocks >= 1000) { |
|
|
|
if (inBlocks >= 100) { |
|
|
|
this.isBehind = true; |
|
|
|
this.isBehind = true; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
this.isBehind = false; |
|
|
|
this.isBehind = false; |
|
|
|
|
|
|
|
this.blocksBehind = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
this.blocksBehind = 0; |
|
|
|
this.blocksBehind = 0; |
|
|
|
this.isBehind = false; |
|
|
|
this.isBehind = false; |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (error) {} |
|
|
|
} catch (error) {} finally { |
|
|
|
|
|
|
|
this.fetchingSummary = false |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async checkHowManyBlocksBehind() { |
|
|
|
async checkHowManyBlocksBehind() { |
|
|
|
try { |
|
|
|
try { |
|
|
|
this.getDaySummary(); |
|
|
|
this.getDaySummary(); |
|
|
|
this.interval = setInterval(() => { |
|
|
|
this.interval = setInterval(() => { |
|
|
|
|
|
|
|
if(this.fetchingSummary) return |
|
|
|
if (this.isBehind === false) { |
|
|
|
if (this.isBehind === false) { |
|
|
|
this.isBehind = null; |
|
|
|
this.isBehind = null; |
|
|
|
clearInterval(this.interval); |
|
|
|
clearInterval(this.interval); |
|
|
|
} |
|
|
|
} |
|
|
|
this.getDaySummary(); |
|
|
|
this.getDaySummary(); |
|
|
|
}, 60000); |
|
|
|
}, 20000); |
|
|
|
} catch (error) {} |
|
|
|
} catch (error) {} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
stateChanged(state) { |
|
|
|
stateChanged(state) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!this.seenWelcomeSync && state.app.nodeStatus && state.app.nodeStatus.syncPercent === 100 && this.hasOpened === false){ |
|
|
|
|
|
|
|
this.hasOpened = true |
|
|
|
|
|
|
|
this.dispatchEvent( |
|
|
|
|
|
|
|
new CustomEvent('open-welcome-modal-sync', { |
|
|
|
|
|
|
|
bubbles: true, |
|
|
|
|
|
|
|
composed: true, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
if ( |
|
|
|
if ( |
|
|
|
state.app.nodeStatus && |
|
|
|
state.app.nodeStatus && |
|
|
|
Object.keys(state.app.nodeStatus).length === 0 |
|
|
|
Object.keys(state.app.nodeStatus).length === 0 |
|
|
@ -163,9 +172,25 @@ class SyncIndicator extends connect(store)(LitElement) { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
this.numberOfTries = this.numberOfTries + 1; |
|
|
|
this.numberOfTries = this.numberOfTries + 1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else if(state.app.nodeStatus && state.app.nodeStatus.syncPercent === 100 && state.app.nodeStatus.syncPercent !== this.syncPercentage){ |
|
|
|
|
|
|
|
this.syncPercentage = state.app.nodeStatus.syncPercent; |
|
|
|
|
|
|
|
this.isSynchronizing = false; |
|
|
|
|
|
|
|
// if (
|
|
|
|
|
|
|
|
// this.isBehind === null
|
|
|
|
|
|
|
|
// ) {
|
|
|
|
|
|
|
|
// this.isBehind = false;
|
|
|
|
|
|
|
|
// this.blocksBehind = 0;
|
|
|
|
|
|
|
|
// if (!this.seenWelcomeSync) {
|
|
|
|
|
|
|
|
// this.dispatchEvent(
|
|
|
|
|
|
|
|
// new CustomEvent('open-welcome-modal-sync', {
|
|
|
|
|
|
|
|
// bubbles: true,
|
|
|
|
|
|
|
|
// composed: true,
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
} else if ( |
|
|
|
} else if ( |
|
|
|
state.app.nodeStatus && |
|
|
|
state.app.nodeStatus |
|
|
|
state.app.nodeStatus.syncPercent !== this.syncPercentage |
|
|
|
|
|
|
|
) { |
|
|
|
) { |
|
|
|
this.hasCoreRunning = true |
|
|
|
this.hasCoreRunning = true |
|
|
|
this.numberOfTries = 0 |
|
|
|
this.numberOfTries = 0 |
|
|
@ -173,24 +198,26 @@ class SyncIndicator extends connect(store)(LitElement) { |
|
|
|
|
|
|
|
|
|
|
|
if (state.app.nodeStatus.syncPercent !== 100) { |
|
|
|
if (state.app.nodeStatus.syncPercent !== 100) { |
|
|
|
this.isSynchronizing = true; |
|
|
|
this.isSynchronizing = true; |
|
|
|
} else { |
|
|
|
|
|
|
|
this.isSynchronizing = false; |
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// else {
|
|
|
|
|
|
|
|
// this.isSynchronizing = false;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (
|
|
|
|
|
|
|
|
// this.isBehind === null &&
|
|
|
|
|
|
|
|
// state.app.nodeStatus.syncPercent === 100
|
|
|
|
|
|
|
|
// ) {
|
|
|
|
|
|
|
|
// this.isBehind = false;
|
|
|
|
|
|
|
|
// this.blocksBehind = 0;
|
|
|
|
|
|
|
|
// if (!this.seenWelcomeSync) {
|
|
|
|
|
|
|
|
// this.dispatchEvent(
|
|
|
|
|
|
|
|
// new CustomEvent('open-welcome-modal-sync', {
|
|
|
|
|
|
|
|
// bubbles: true,
|
|
|
|
|
|
|
|
// composed: true,
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// } else
|
|
|
|
if ( |
|
|
|
if ( |
|
|
|
this.isBehind === null && |
|
|
|
|
|
|
|
state.app.nodeStatus.syncPercent === 100 |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
this.isBehind = false; |
|
|
|
|
|
|
|
this.blocksBehind = 0; |
|
|
|
|
|
|
|
if (!this.seenWelcomeSync) { |
|
|
|
|
|
|
|
this.dispatchEvent( |
|
|
|
|
|
|
|
new CustomEvent('open-welcome-modal-sync', { |
|
|
|
|
|
|
|
bubbles: true, |
|
|
|
|
|
|
|
composed: true, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else if ( |
|
|
|
|
|
|
|
!this.interval && |
|
|
|
!this.interval && |
|
|
|
this.isBehind === null && |
|
|
|
this.isBehind === null && |
|
|
|
state.app.nodeStatus.isSynchronizing && |
|
|
|
state.app.nodeStatus.isSynchronizing && |
|
|
@ -211,7 +238,6 @@ class SyncIndicator extends connect(store)(LitElement) { |
|
|
|
if(data === true){ |
|
|
|
if(data === true){ |
|
|
|
parentEpml.request('showSnackBar', get('tour.tour22')); |
|
|
|
parentEpml.request('showSnackBar', get('tour.tour22')); |
|
|
|
} |
|
|
|
} |
|
|
|
console.log({data}) |
|
|
|
|
|
|
|
} catch (error) { |
|
|
|
} catch (error) { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
@ -234,7 +260,7 @@ class SyncIndicator extends connect(store)(LitElement) { |
|
|
|
</p> |
|
|
|
</p> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
` |
|
|
|
` |
|
|
|
: (this.isBehind && this.isSynchronizing) |
|
|
|
: (this.blocksBehind > 1050 && this.isSynchronizing) |
|
|
|
? html` |
|
|
|
? html` |
|
|
|
<div class="parent"> |
|
|
|
<div class="parent"> |
|
|
|
<div class="column"> |
|
|
|
<div class="column"> |
|
|
|