Skip to content

Commit ee81a7a

Browse files
committed
Show sync progress as percentage
1 parent af45f3e commit ee81a7a

1 file changed

Lines changed: 35 additions & 3 deletions

File tree

app/js/ui/app.js

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var App = (function() {
1111
var _pollTimer = null;
1212
var _lastPolledBlock = 0;
1313
var _pollBusy = false;
14+
var _syncStartBlock = 0;
1415
var POLL_INTERVAL_MS = 3000;
1516

1617
/**
@@ -215,13 +216,22 @@ var App = (function() {
215216
* Show initial connection status
216217
*/
217218
function _showConnectionStatus() {
219+
_updateSyncStatus(0, true);
220+
}
221+
222+
function _updateSyncStatus(percent, forceShow) {
218223
var statusEl = Helpers.$('connection-status');
219-
if (statusEl) {
220-
statusEl.textContent = Helpers.t('conn_connecting');
224+
if (!statusEl) return;
225+
226+
percent = Math.max(0, Math.min(100, Math.ceil(percent || 0)));
227+
statusEl.textContent = 'Синхронизация с Миром... ' + percent + '%';
228+
229+
if (forceShow || percent < 100) {
221230
statusEl.classList.add('show');
231+
} else {
222232
setTimeout(function() {
223233
statusEl.classList.remove('show');
224-
}, 3000);
234+
}, 1500);
225235
}
226236
}
227237

@@ -271,10 +281,18 @@ var App = (function() {
271281
}
272282

273283
if (headBlock <= _lastPolledBlock) {
284+
_syncStartBlock = 0;
285+
_updateSyncStatus(100);
274286
_pollBusy = false;
275287
return;
276288
}
277289

290+
if (_syncStartBlock === 0 || _lastPolledBlock < _syncStartBlock) {
291+
_syncStartBlock = _lastPolledBlock;
292+
}
293+
294+
_updateSyncStatus(_calculateSyncPercent(_lastPolledBlock, headBlock));
295+
278296
// Cap batch size to avoid overwhelming the node
279297
var startBlock = _lastPolledBlock + 1;
280298
var maxBatch = 10;
@@ -314,6 +332,7 @@ var App = (function() {
314332
console.log('App: Checkpoint save error:', cpErr);
315333
}
316334

335+
_updateSyncStatus(_calculateSyncPercent(endBlock, chainHead));
317336
_refreshActiveScreenAfterSync(eventsCollected);
318337

319338
// If there are more blocks to process, continue immediately
@@ -322,12 +341,25 @@ var App = (function() {
322341
var nextEnd = Math.min(chainHead, nextStart + 9);
323342
_processBlockBatch(nextStart, nextEnd, chainHead);
324343
} else {
344+
_syncStartBlock = 0;
345+
_updateSyncStatus(100);
325346
_pollBusy = false;
326347
}
327348
});
328349
});
329350
}
330351

352+
function _calculateSyncPercent(processedBlock, chainHead) {
353+
if (!chainHead || processedBlock >= chainHead) return 100;
354+
if (!_syncStartBlock || chainHead <= _syncStartBlock) return 100;
355+
356+
var done = processedBlock - _syncStartBlock;
357+
var total = chainHead - _syncStartBlock;
358+
if (total <= 0) return 100;
359+
360+
return (done / total) * 100;
361+
}
362+
331363
function _refreshActiveScreenAfterSync(eventsCollected) {
332364
var reactiveScreens = {
333365
home: true,

0 commit comments

Comments
 (0)