Permalink
Browse files

Merge pull request #1258 from input-output-hk/feature/ddw-514-improve…

…-ntp-check-ux

[DDW-514] Improve NTP check UX
  • Loading branch information...
nikolaglumac committed Jan 11, 2019
2 parents 2305264 + 4e769e6 commit 948c8a58a826292cde72ccdfa10539497da08431
@@ -6,6 +6,7 @@ Changelog

### 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))
- 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))
@@ -234,7 +234,7 @@ export default class NetworkStatus extends Component<Props, State> {
</span> |&nbsp;
<button
onClick={() => onForceCheckLocalTimeDifference()}
disabled={isForceCheckingNodeTime}
disabled={isForceCheckingNodeTime || !isConnected}
>
{isForceCheckingNodeTime ? 'Checking...' : 'Check time'}
</button>
@@ -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_POLL_INTERVAL = 2000; // 2 seconds | 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
@@ -10,6 +10,7 @@ import {
NETWORK_STATUS_REQUEST_TIMEOUT,
NETWORK_STATUS_POLL_INTERVAL,
NTP_FORCE_CHECK_POLL_INTERVAL,
NTP_IGNORE_CHECKS_GRACE_PERIOD,
} from '../config/timingConfig';
import { UNSYNCED_BLOCKS_ALLOWED } from '../config/numbersConfig';
import { Logger } from '../utils/logging';
@@ -75,6 +76,9 @@ export default class NetworkStatusStore extends Store {
setup() {
// ========== IPC CHANNELS =========== //

// Request node state
this._requestCardanoState();

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

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

this.registerReactions([
this._updateNetworkStatusWhenConnected,
this._updateNetworkStatusWhenDisconnected,
this._updateNodeStatus,
]);
@@ -101,6 +106,13 @@ export default class NetworkStatusStore extends Store {
this._forceCheckTimeDifferencePollingInterval = setInterval(
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() {
@@ -130,6 +142,13 @@ export default class NetworkStatusStore extends Store {
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 () => {
if (!this.isConnected) return;
try {
@@ -146,11 +165,16 @@ export default class NetworkStatusStore extends Store {
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 () => {
try {
Logger.info('NetworkStatusStore: requesting node status.');
const state = await cardanoStateChangeChannel.request();
await this._handleCardanoNodeStateChange(state);
const status = await cardanoStatusChannel.request();
Logger.info(`NetworkStatusStore: received cached node status: ${JSON.stringify(status)}`);
if (status) runInAction('assigning node status', () => Object.assign(this, status));
@@ -425,12 +449,12 @@ export default class NetworkStatusStore extends Store {
}
};

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

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

// DEFINE COMPUTED VALUES

0 comments on commit 948c8a5

Please sign in to comment.