Skip to content

Commit

Permalink
Merge pull request #1258 from input-output-hk/feature/ddw-514-improve…
Browse files Browse the repository at this point in the history
…-ntp-check-ux

[DDW-514] Improve NTP check UX
  • Loading branch information
nikolaglumac committed Jan 11, 2019
2 parents 2305264 + 4e769e6 commit 948c8a5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@ Changelog


### Features ### Features


- Improve NTP check UX ([PR 1258](https://github.com/input-output-hk/daedalus/pull/1258))
- Added support for "frontend-only" mode ([PR 1241](https://github.com/input-output-hk/daedalus/pull/1241), [PR 1260](https://github.com/input-output-hk/daedalus/pull/1260)) - Added support for "frontend-only" mode ([PR 1241](https://github.com/input-output-hk/daedalus/pull/1241), [PR 1260](https://github.com/input-output-hk/daedalus/pull/1260))
- Improved the lock-file UX by replacing "Daedalus is already running" dialog with focusing of the already running Daedalus instance ([PR 1229](https://github.com/input-output-hk/daedalus/pull/1229)) - Improved the lock-file UX by replacing "Daedalus is already running" dialog with focusing of the already running Daedalus instance ([PR 1229](https://github.com/input-output-hk/daedalus/pull/1229))
- Replaced in-app support request with links to support page ([PR 1199](https://github.com/input-output-hk/daedalus/pull/1199)) - Replaced in-app support request with links to support page ([PR 1199](https://github.com/input-output-hk/daedalus/pull/1199))
Expand Down
2 changes: 1 addition & 1 deletion source/renderer/app/components/status/NetworkStatus.js
Expand Up @@ -234,7 +234,7 @@ export default class NetworkStatus extends Component<Props, State> {
</span> |&nbsp; </span> |&nbsp;
<button <button
onClick={() => onForceCheckLocalTimeDifference()} onClick={() => onForceCheckLocalTimeDifference()}
disabled={isForceCheckingNodeTime} disabled={isForceCheckingNodeTime || !isConnected}
> >
{isForceCheckingNodeTime ? 'Checking...' : 'Check time'} {isForceCheckingNodeTime ? 'Checking...' : 'Check time'}
</button> </button>
Expand Down
1 change: 1 addition & 0 deletions source/renderer/app/config/timingConfig.js
Expand Up @@ -11,3 +11,4 @@ export const MAX_ALLOWED_STALL_DURATION = 2 * 60 * 1000; // 2 minutes | unit: mi
export const NETWORK_STATUS_REQUEST_TIMEOUT = 30 * 1000; // 30 seconds | unit: milliseconds export const NETWORK_STATUS_REQUEST_TIMEOUT = 30 * 1000; // 30 seconds | unit: milliseconds
export const NETWORK_STATUS_POLL_INTERVAL = 2000; // 2 seconds | unit: milliseconds export const NETWORK_STATUS_POLL_INTERVAL = 2000; // 2 seconds | unit: milliseconds
export const NTP_FORCE_CHECK_POLL_INTERVAL = 30 * 60 * 1000; // 30 minutes | unit: milliseconds export const NTP_FORCE_CHECK_POLL_INTERVAL = 30 * 60 * 1000; // 30 minutes | unit: milliseconds
export const NTP_IGNORE_CHECKS_GRACE_PERIOD = 30 * 1000; // 30 seconds | unit: milliseconds
34 changes: 29 additions & 5 deletions source/renderer/app/stores/NetworkStatusStore.js
Expand Up @@ -10,6 +10,7 @@ import {
NETWORK_STATUS_REQUEST_TIMEOUT, NETWORK_STATUS_REQUEST_TIMEOUT,
NETWORK_STATUS_POLL_INTERVAL, NETWORK_STATUS_POLL_INTERVAL,
NTP_FORCE_CHECK_POLL_INTERVAL, NTP_FORCE_CHECK_POLL_INTERVAL,
NTP_IGNORE_CHECKS_GRACE_PERIOD,
} from '../config/timingConfig'; } from '../config/timingConfig';
import { UNSYNCED_BLOCKS_ALLOWED } from '../config/numbersConfig'; import { UNSYNCED_BLOCKS_ALLOWED } from '../config/numbersConfig';
import { Logger } from '../utils/logging'; import { Logger } from '../utils/logging';
Expand Down Expand Up @@ -75,6 +76,9 @@ export default class NetworkStatusStore extends Store {
setup() { setup() {
// ========== IPC CHANNELS =========== // // ========== IPC CHANNELS =========== //


// Request node state
this._requestCardanoState();

// Request cached node status for fast bootstrapping of frontend // Request cached node status for fast bootstrapping of frontend
this._requestCardanoStatus(); this._requestCardanoStatus();


Expand All @@ -88,6 +92,7 @@ export default class NetworkStatusStore extends Store {
// ========== MOBX REACTIONS =========== // // ========== MOBX REACTIONS =========== //


this.registerReactions([ this.registerReactions([
this._updateNetworkStatusWhenConnected,
this._updateNetworkStatusWhenDisconnected, this._updateNetworkStatusWhenDisconnected,
this._updateNodeStatus, this._updateNodeStatus,
]); ]);
Expand All @@ -101,6 +106,13 @@ export default class NetworkStatusStore extends Store {
this._forceCheckTimeDifferencePollingInterval = setInterval( this._forceCheckTimeDifferencePollingInterval = setInterval(
this.forceCheckLocalTimeDifference, NTP_FORCE_CHECK_POLL_INTERVAL this.forceCheckLocalTimeDifference, NTP_FORCE_CHECK_POLL_INTERVAL
); );

// Ignore system time checks for the first 30 seconds:
this.ignoreSystemTimeChecks();
setTimeout(
() => this.ignoreSystemTimeChecks(false),
NTP_IGNORE_CHECKS_GRACE_PERIOD
);
} }


async restartNode() { async restartNode() {
Expand Down Expand Up @@ -130,6 +142,13 @@ export default class NetworkStatusStore extends Store {
if (!this.isConnected) this._updateNetworkStatus(); if (!this.isConnected) this._updateNetworkStatus();
}; };


_updateNetworkStatusWhenConnected = () => {
if (this.isConnected) {
Logger.info('NetworkStatusStore: Connected, forcing NTP check now...');
this._updateNetworkStatus({ force_ntp_check: true });
}
};

_updateNodeStatus = async () => { _updateNodeStatus = async () => {
if (!this.isConnected) return; if (!this.isConnected) return;
try { try {
Expand All @@ -146,11 +165,16 @@ export default class NetworkStatusStore extends Store {
return Date.now() - this._startTime; return Date.now() - this._startTime;
} }


_requestCardanoState = async () => {
Logger.info('NetworkStatusStore: requesting node state.');
const state = await cardanoStateChangeChannel.request();
Logger.info(`NetworkStatusStore: handling node state <${state}>.`);
await this._handleCardanoNodeStateChange(state);
};

_requestCardanoStatus = async () => { _requestCardanoStatus = async () => {
try { try {
Logger.info('NetworkStatusStore: requesting node status.'); Logger.info('NetworkStatusStore: requesting node status.');
const state = await cardanoStateChangeChannel.request();
await this._handleCardanoNodeStateChange(state);
const status = await cardanoStatusChannel.request(); const status = await cardanoStatusChannel.request();
Logger.info(`NetworkStatusStore: received cached node status: ${JSON.stringify(status)}`); Logger.info(`NetworkStatusStore: received cached node status: ${JSON.stringify(status)}`);
if (status) runInAction('assigning node status', () => Object.assign(this, status)); if (status) runInAction('assigning node status', () => Object.assign(this, status));
Expand Down Expand Up @@ -425,12 +449,12 @@ export default class NetworkStatusStore extends Store {
} }
}; };


@action ignoreSystemTimeChecks = () => { @action ignoreSystemTimeChecks = (flag: boolean = true) => {
this.isSystemTimeIgnored = true; this.isSystemTimeIgnored = flag;
}; };


forceCheckLocalTimeDifference = () => { forceCheckLocalTimeDifference = () => {
this._updateNetworkStatus({ force_ntp_check: true }); if (this.isConnected) this._updateNetworkStatus({ force_ntp_check: true });
}; };


// DEFINE COMPUTED VALUES // DEFINE COMPUTED VALUES
Expand Down

0 comments on commit 948c8a5

Please sign in to comment.