Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DDW-256] No disk space overlay #1157

Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
54832c3
[DDW-256] No disk space overlay
thedanheller Nov 1, 2018
7e4462b
[DDW-256] Overlay styling
thedanheller Nov 5, 2018
c37eecd
[DDW-256] Function to check disk space - not checking
thedanheller Nov 5, 2018
e3b20bc
[DDW-256] manage:translations
thedanheller Nov 5, 2018
2f4cfb3
[DDW-256] diskSpaceRequired coming from the main process
thedanheller Nov 5, 2018
d20e95e
[DDW-256] Adds the `prettysize` dependency
thedanheller Nov 7, 2018
dc2025f
Merge branch 'develop' into feature/ddw-256-implement-better-handling…
thedanheller Nov 7, 2018
b4fa27b
[DDW-256] Correct copy
thedanheller Nov 7, 2018
6762a22
[DDW-256] WIP cardano wiring up
thedanheller Nov 7, 2018
2a7ef50
[DDW-256] Correct copy
thedanheller Nov 8, 2018
89727cf
[DDW-256] CHANGELOG
thedanheller Nov 8, 2018
a0c85ec
[DDW-256] Debugging
thedanheller Nov 12, 2018
ff229f8
[DDW-256] Windows sync folder
thedanheller Nov 12, 2018
149cd78
Merge branch 'develop' into feature/ddw-256-implement-better-handling…
thedanheller Nov 12, 2018
cd7510a
Revert "[DDW-256] Windows sync folder"
thedanheller Nov 13, 2018
c45a1e3
[DDW-256] IPC communication
thedanheller Nov 13, 2018
81d9d38
Merge branch 'develop' into feature/ddw-256-implement-better-handling…
thedanheller Nov 21, 2018
12dce1d
[DDW-256] debugging
thedanheller Nov 21, 2018
74f08aa
[DDW-256] Cardano disk space required - arbitrary number
thedanheller Nov 22, 2018
c1afe69
[DDW-256] Removes incorrect Cardano handling
thedanheller Nov 22, 2018
9e1abb8
[DDW-256] Adjustments
thedanheller Nov 22, 2018
6cb1ff2
[DDW-256] Removes dummy checking and adjustments
thedanheller Nov 23, 2018
fcdb509
Merge branch 'develop' into feature/ddw-256-implement-better-handling…
thedanheller Nov 23, 2018
29a8ff8
[DDW-256] Removes dummy checking and better naming
thedanheller Nov 23, 2018
d6f0777
[DDW-256] Periodically checking
thedanheller Nov 23, 2018
3425986
Merge branch 'develop' into feature/ddw-256-implement-better-handling…
thedanheller Nov 26, 2018
06a652d
[DDW-256] Trigger checking on Daedalus start
thedanheller Nov 26, 2018
2f3a0a8
[DDW-256] Staging logging
thedanheller Nov 26, 2018
1858131
[DDW-256] Moves checking to main index for Cardano control
thedanheller Nov 26, 2018
2d8134a
Merge branch 'develop' into feature/ddw-256-implement-better-handling…
thedanheller Nov 27, 2018
f805343
[DDW-256] Adjustments and debugging
thedanheller Nov 27, 2018
b5af531
[DDW-256] Adjustments and debugging
thedanheller Nov 27, 2018
cc4b10f
Merge branch 'develop' into feature/ddw-256-implement-better-handling…
thedanheller Nov 27, 2018
105faa7
[DDW-256] Debugging adjustments
thedanheller Nov 27, 2018
4f463bf
[DDW-256] Set disk space manually for debugging
thedanheller Nov 28, 2018
12eee92
[DDW-256] More debugging
thedanheller Nov 28, 2018
f0b9272
[DDW-256] Removes debugging
thedanheller Nov 28, 2018
a0a1a40
[DDW-256] New Overlay text - TBC
thedanheller Nov 28, 2018
64f558b
[DDW-256] Stopping / Restarting Cardano Node
thedanheller Nov 29, 2018
eb28701
[DDW-256] CHANGELOG
thedanheller Nov 29, 2018
da5290e
[DDW-259] Correct CHANGELOG entry placement
thedanheller Nov 30, 2018
8499aa4
[DDW-259] Correct copy and calculations
thedanheller Dec 5, 2018
f9398a2
Merge branch 'develop' into feature/ddw-256-implement-better-handling…
thedanheller Dec 5, 2018
4c41b57
[DDW-259] Correct imports path
thedanheller Dec 5, 2018
de5f2e1
[DDW-259] Correct ipcRenderer import
thedanheller Dec 5, 2018
ae5e9fa
Merge branch 'develop' into feature/ddw-256-implement-better-handling…
thedanheller Dec 7, 2018
c4f2641
[DDW-256] Japanese translation
thedanheller Dec 7, 2018
b8d954e
Merge branch 'develop' into feature/ddw-256-implement-better-handling…
thedanheller Dec 11, 2018
dbe9fa5
[DDW-256] Acceptance tests
thedanheller Dec 11, 2018
def88ba
Merge branch 'develop' into feature/ddw-256-implement-better-handling…
nikolaglumac Dec 12, 2018
144df03
Merge branch 'develop' into feature/ddw-256-implement-better-handling…
nikolaglumac Dec 12, 2018
65c4111
Merge branch 'develop' into feature/ddw-256-implement-better-handling…
thedanheller Dec 12, 2018
55992e2
Merge branch 'develop' into feature/ddw-256-implement-better-handling…
nikolaglumac Dec 12, 2018
1264982
Merge branch 'feature/ddw-256-implement-better-handling-for-no-disksp…
thedanheller Dec 12, 2018
90f0e25
[DDW-256] Acceptance tests
thedanheller Dec 12, 2018
434d490
[DDW-256] Acceptance tests - adjustments
thedanheller Dec 13, 2018
e674078
[DDW-256] Acceptance tests - adjustments
thedanheller Dec 13, 2018
79f6a6b
[DDW-256] Reverting main/index
thedanheller Dec 13, 2018
71bc48c
Merge branch 'develop' into feature/ddw-256-implement-better-handling…
nikolaglumac Dec 14, 2018
2aba3af
Merge branch 'develop' into feature/ddw-256-implement-better-handling…
nikolaglumac Dec 14, 2018
43b7142
[DDW-256] Merges in latest develop and fixes conflicts
nikolaglumac Dec 14, 2018
c3db9d4
Merge branch 'feature/ddw-256-implement-better-handling-for-no-disksp…
thedanheller Dec 14, 2018
7757f70
[DDW-256] Main Index changes
thedanheller Dec 18, 2018
a258f6d
Merge branch 'develop' into feature/ddw-256-implement-better-handling…
thedanheller Dec 18, 2018
e25eb7c
[DDW-256] Removes @watch tag
thedanheller Dec 18, 2018
aab7b1a
Merge branch 'develop' into feature/ddw-256-implement-better-handling…
thedanheller Dec 20, 2018
25ca9f5
Merge branch 'develop' into feature/ddw-256-implement-better-handling…
thedanheller Jan 2, 2019
689aad2
Merge branch 'develop' into feature/ddw-256-implement-better-handling…
thedanheller Jan 3, 2019
c6b7630
[DDW-256] Acceptance tests
thedanheller Jan 3, 2019
9d21ae9
[DDW-256] FLOW errors
thedanheller Jan 3, 2019
3cab383
[DDW-256] Bug that would not make the initial check
thedanheller Jan 3, 2019
8a9a4e1
[DDW-256] CHANGELOG edit
nikolaglumac Jan 4, 2019
ee1c533
[DDW-256] Initial checking
thedanheller Jan 4, 2019
96365dd
Merge branch 'develop' into feature/ddw-256-implement-better-handling…
nikolaglumac Jan 7, 2019
c23b0d0
Merge branch 'develop' into feature/ddw-256-implement-better-handling…
nikolaglumac Jan 7, 2019
6bb467c
Merge branch 'develop' into feature/ddw-256-implement-better-handling…
nikolaglumac Jan 7, 2019
489fb85
Merge branch 'develop' into feature/ddw-256-implement-better-handling…
thedanheller Jan 7, 2019
28d129d
Merge branch 'feature/ddw-256-implement-better-handling-for-no-disksp…
thedanheller Jan 7, 2019
968f1c9
[DDW-256] Flow error
thedanheller Jan 7, 2019
4f293e0
Merge branch 'develop' into feature/ddw-256-implement-better-handling…
nikolaglumac Jan 7, 2019
49e5b95
[DDW-256] Code style improvements
nikolaglumac Jan 7, 2019
b6935d7
[DDW-256] Logging improvement
nikolaglumac Jan 7, 2019
df06034
[DDW-256] More descriptive acceptance test scenarios
thedanheller Jan 7, 2019
ad4f51e
Merge branch 'feature/ddw-256-implement-better-handling-for-no-disksp…
thedanheller Jan 7, 2019
48b8a34
[DDW-256] Moves the cardano status checking into the`onCheckDiskSpace…
thedanheller Jan 7, 2019
4a3f259
[DDW-256] Stops pollers when no disk space
thedanheller Jan 7, 2019
87c419f
[DDW-256] Flow error
thedanheller Jan 7, 2019
2f749f6
[DDW-256] Trigger rebuild
nikolaglumac Jan 8, 2019
04e14e6
[DDW-256] Fix flow issues
nikolaglumac Jan 8, 2019
3bce4ce
[DDW-256] Refactors dynamically typed constants to Flow-typed
thedanheller Jan 8, 2019
dc567ef
Merge branch 'feature/ddw-256-implement-better-handling-for-no-disksp…
thedanheller Jan 8, 2019
e21e374
[DDW-256] Improves cardano restarting
thedanheller Jan 8, 2019
b1917da
[DDW-256] Handle disk space as exported const
thedanheller Jan 8, 2019
05dd713
[DDW-256] Comment about `frontendOnlyMode`
thedanheller Jan 8, 2019
1535e00
[DDW-256] Misspelling
thedanheller Jan 8, 2019
b1b2447
[DDW-256] Prevents stopping cardano node if it was already stopped
thedanheller Jan 8, 2019
f13c64c
[DDW-256] Correct japanese translation
thedanheller Jan 8, 2019
69af57d
[DDW-256] Code style improvements
nikolaglumac Jan 9, 2019
245017e
[DDW-256] Fix handle disk space cardano stopping/restarting logic
nikolaglumac Jan 9, 2019
c4f6f0a
[DDW-256] Code style improvement
nikolaglumac Jan 9, 2019
bf5588e
[DDW-256] Don't show report-issue notification on connecting/syncing …
nikolaglumac Jan 9, 2019
13bf4a6
[DDW-256] Merge latest develop and fix conflicts
nikolaglumac Jan 10, 2019
3855350
[DDW-256] Prevent NTP force check polling while there is not enough d…
nikolaglumac Jan 11, 2019
8d49ef8
[DDW-256] Use correct frontendOnlyMode
nikolaglumac Jan 11, 2019
e2b5922
[DDW-256] Improve timers
nikolaglumac Jan 11, 2019
23de0d7
[DDW-256] Improve disk space check intervals logic
nikolaglumac Jan 14, 2019
66bbf7b
Merge branch 'develop' into feature/ddw-256-implement-better-handling…
nikolaglumac Jan 14, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -35,6 +35,7 @@ Changelog
- Improved the transaction details text selection ([PR 1073](https://github.com/input-output-hk/daedalus/pull/1073), [PR 1095](https://github.com/input-output-hk/daedalus/pull/1095))
- Integrated Cardano V1 API endpoints ([PR 1018](https://github.com/input-output-hk/daedalus/pull/1018), [PR 1031](https://github.com/input-output-hk/daedalus/pull/1031), [PR 1037](https://github.com/input-output-hk/daedalus/pull/1037), [PR 1042](https://github.com/input-output-hk/daedalus/pull/1042), [PR 1045](https://github.com/input-output-hk/daedalus/pull/1045), [PR 1070](https://github.com/input-output-hk/daedalus/pull/1070), [PR 1078](https://github.com/input-output-hk/daedalus/pull/1078), [PR 1079](https://github.com/input-output-hk/daedalus/pull/1079), [PR 1080](https://github.com/input-output-hk/daedalus/pull/1080), [PR 1088](https://github.com/input-output-hk/daedalus/pull/1088))
- Refactored and improved `NetworkStatus` store to use V1 API data ([PR 1081](https://github.com/input-output-hk/daedalus/pull/1081))
- Implemented a better handling for no disk space error ([PR 1157](https://github.com/input-output-hk/daedalus/pull/1157))

### Fixes

Expand Down
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -99,6 +99,7 @@
"postcss": "6.0.14",
"postcss-modules": "1.1.0",
"postcss-modules-values": "1.3.0",
"prettysize": "1.1.0",
"raw-loader": "0.5.1",
"react-intl-translations-manager": "5.0.1",
"resolve-url": "0.2.1",
Expand All @@ -122,6 +123,7 @@
"bip39": "2.3.0",
"blakejs": "1.1.0",
"bs58": "4.0.1",
"check-disk-space": "1.5.0",
"classnames": "2.2.5",
"electron-debug": "1.4.0",
"electron-log": "2.2.14",
Expand Down
9 changes: 9 additions & 0 deletions source/common/ipc/check-disk-space.js
@@ -0,0 +1,9 @@
// @flow
export const DISK_SPACE_STATUS_CHANNEL = 'disk-space-status';

export type CheckDiskSpaceResponse = {
diskSpaceAvailable: number,
diskSpaceRequired: number,
diskSpaceMissing: number,
notEnoughSpace: boolean,
};
9 changes: 7 additions & 2 deletions source/main/cardano/setup.js
Expand Up @@ -17,8 +17,9 @@ import { safeExitWithCode } from '../utils/safeExitWithCode';
import type {
TlsConfig,
CardanoNodeState,
CardanoStatus
CardanoStatus,
} from '../../common/types/cardanoNode.types';
import { CardanoNodeStates } from '../../common/types/cardanoNode.types';
import type { LauncherConfig } from '../config';
import {
NODE_KILL_TIMEOUT,
Expand All @@ -45,7 +46,11 @@ const startCardanoNode = (node: CardanoNode, launcherConfig: Object) => {
return node.start(config);
};

const restartCardanoNode = async (node: CardanoNode) => {
export const restartCardanoNode = async (node: CardanoNode) => {
if (
node.state === CardanoNodeStates.STARTING ||
node.state === CardanoNodeStates.RUNNING
) return false;
try {
await node.restart();
} catch (error) {
Expand Down
33 changes: 27 additions & 6 deletions source/main/index.js
Expand Up @@ -6,6 +6,7 @@ import { includes } from 'lodash';
import { Logger } from '../common/logging';
import { setupLogging } from './utils/setupLogging';
import { makeEnvironmentGlobal } from './utils/makeEnvironmentGlobal';
import HandleDiskSpace from './utils/HandleDiskSpace';
thedanheller marked this conversation as resolved.
Show resolved Hide resolved
import { createMainWindow } from './windows/main';
import { winLinuxMenu } from './menus/win-linux';
import { osxMenu } from './menus/osx';
Expand All @@ -16,12 +17,13 @@ import { GO_TO_ADA_REDEMPTION_SCREEN_CHANNEL } from '../common/ipc/go-to-ada-red
import { GO_TO_NETWORK_STATUS_SCREEN_CHANNEL } from '../common/ipc/go-to-network-status-screen';
import mainErrorHandler from './utils/mainErrorHandler';
import { launcherConfig } from './config';
import { setupCardano } from './cardano/setup';
import { setupCardano, restartCardanoNode } from './cardano/setup';
import { CardanoNode } from './cardano/CardanoNode';
import { safeExitWithCode } from './utils/safeExitWithCode';
import { ensureXDGDataIsSet } from './cardano/config';
import { acquireDaedalusInstanceLock } from './utils/lockFiles';
import { CardanoNodeStates } from '../common/types/cardanoNode.types';
import type { CheckDiskSpaceResponse } from '../common/ipc/check-disk-space';

// Global references to windows to prevent them from being garbage collected
let mainWindow: BrowserWindow;
Expand Down Expand Up @@ -86,7 +88,30 @@ app.on('ready', async () => {
}

setupLogging();
mainErrorHandler();

// Detect safe mode
const isInSafeMode = includes(process.argv.slice(1), '--safe-mode');

mainWindow = createMainWindow(isInSafeMode);

const onCheckDiskSpace = ({ notEnoughSpace }: CheckDiskSpaceResponse) => {
if (notEnoughSpace) {
cardanoNode.stop();
} else {
restartCardanoNode(cardanoNode);
}
};

const handleCheckDiskSpace = HandleDiskSpace(mainWindow, onCheckDiskSpace);

const onMainError = (error: string) => {
if (error.indexOf('ENOSPC') > -1) {
handleCheckDiskSpace();
return false;
}
};

mainErrorHandler(onMainError);

Logger.info(`========== Daedalus is starting at ${new Date().toString()} ==========`);

Expand All @@ -98,10 +123,6 @@ app.on('ready', async () => {
makeEnvironmentGlobal(process.env);
await installChromeExtensions(environment.isDev());

// Detect safe mode
const isInSafeMode = includes(process.argv.slice(1), '--safe-mode');

mainWindow = createMainWindow(isInSafeMode);
cardanoNode = setupCardano(launcherConfig, mainWindow);

if (environment.isWatchMode()) {
Expand Down
69 changes: 69 additions & 0 deletions source/main/utils/HandleDiskSpace.js
@@ -0,0 +1,69 @@
// @flow
import { BrowserWindow } from 'electron';
import checkDiskSpace from 'check-disk-space';
import { DISK_SPACE_STATUS_CHANNEL } from '../../common/ipc/check-disk-space';
import environment from '../../common/environment';
import { Logger } from '../../common/logging';

export default (
thedanheller marked this conversation as resolved.
Show resolved Hide resolved
mainWindow: BrowserWindow,
onCheckDiskSpace?: Function,
) => {

const DISK_SPACE_REQUIRED = 2147483648; // 2Gb
const DISK_SPACE_REQUIRED_MARGIN =
DISK_SPACE_REQUIRED - (DISK_SPACE_REQUIRED * 10 / 100); // 2Gb - 10%
const DISK_SPACE_CHECK_LONG_INTERVAL = 600000; // 10 minutes
const DISK_SPACE_CHECK_SHORT_INTERVAL = 10000; // 10 seconds

const path = environment.isWindows() ? 'C:' : '/';
let diskSpaceCheckInterval;
let notEnoughSpace = false;

const handleCheckDiskSpace = async () => {

const { free: diskSpaceAvailable } = await checkDiskSpace(path);
let diskSpaceMissing = DISK_SPACE_REQUIRED - diskSpaceAvailable;
diskSpaceMissing = diskSpaceMissing > -1 ? diskSpaceMissing : 0;

if (diskSpaceAvailable <= DISK_SPACE_REQUIRED_MARGIN) {
if (!notEnoughSpace) {
setDiskSpaceIntervalChecking(DISK_SPACE_CHECK_SHORT_INTERVAL);
}
notEnoughSpace = true;
} else if (diskSpaceAvailable >= DISK_SPACE_REQUIRED) {
if (notEnoughSpace) {
setDiskSpaceIntervalChecking(DISK_SPACE_CHECK_LONG_INTERVAL);
}
notEnoughSpace = false;
}
const response = {
diskSpaceAvailable,
diskSpaceRequired: DISK_SPACE_REQUIRED,
notEnoughSpace,
diskSpaceMissing,
};

Logger.info(JSON.stringify(response, null, 2));

if (typeof onCheckDiskSpace === 'function') {
onCheckDiskSpace(response);
}
mainWindow.webContents.send(DISK_SPACE_STATUS_CHANNEL, response);
};

const setDiskSpaceIntervalChecking = (interval) => {
clearInterval(diskSpaceCheckInterval);
diskSpaceCheckInterval =
setInterval(async () => {
handleCheckDiskSpace();
}, interval);
};
setDiskSpaceIntervalChecking(DISK_SPACE_CHECK_LONG_INTERVAL);

// Initial checking
handleCheckDiskSpace();

return handleCheckDiskSpace;

};
15 changes: 13 additions & 2 deletions source/main/utils/mainErrorHandler.js
Expand Up @@ -3,14 +3,25 @@ import { app } from 'electron';
import unhandled from 'electron-unhandled';
import { Logger, stringifyError } from '../../common/logging';

export default () => {
export default (onError?: Function) => {

Logger.info('mainErrorHandler.js started ==========--------=====');

unhandled({
logger: (error: any) => Logger.error(`unhandledException::main: ${stringifyError(error)}`),
showDialog: false
});

process.on('uncaughtException', (error: any) => {
Logger.error(`uncaughtException: ${stringifyError(error)}`);

const err = `${stringifyError(error)}`;

Logger.error(`uncaughtException: ${err}`);

if (typeof onError === 'function') {
onError.trigger(this, err);
}

});

app.on('gpu-process-crashed', (event: any, killed: boolean) => {
Expand Down
20 changes: 20 additions & 0 deletions source/renderer/app/components/loading/Loading.js
Expand Up @@ -8,6 +8,7 @@ import classNames from 'classnames';
import { Button } from 'react-polymorph/lib/components/Button';
import { ButtonSkin } from 'react-polymorph/lib/skins/simple/ButtonSkin';
import SystemTimeErrorOverlay from './SystemTimeErrorOverlay';
import NoDiskSpaceOverlay from './NoDiskSpaceOverlay';
import LoadingSpinner from '../widgets/LoadingSpinner';
import daedalusLogo from '../../assets/images/daedalus-logo-loading-grey.inline.svg';
import { CardanoNodeStates } from '../../../../common/types/cardanoNode.types';
Expand Down Expand Up @@ -100,6 +101,10 @@ type Props = {
hasBeenConnected: boolean,
isConnected: boolean,
isSynced: boolean,
diskSpaceAvailable: number,
diskSpaceRequired: number,
diskSpaceMissing: number,
notEnoughSpace: boolean,
syncPercentage: number,
loadingDataForNextScreenMessage: ReactIntlMessage,
hasLoadedCurrentLocale: boolean,
Expand Down Expand Up @@ -317,6 +322,10 @@ export default class Loading extends Component<Props, State> {
apiIcon,
isConnected,
isSynced,
diskSpaceAvailable,
diskSpaceRequired,
diskSpaceMissing,
notEnoughSpace,
hasLoadedCurrentLocale,
hasLoadedCurrentTheme,
handleReportIssue,
Expand Down Expand Up @@ -365,6 +374,17 @@ export default class Loading extends Component<Props, State> {

return (
<div className={componentStyles}>
{
notEnoughSpace &&
(
<NoDiskSpaceOverlay
diskSpaceAvailable={diskSpaceAvailable}
diskSpaceRequired={diskSpaceRequired}
diskSpaceMissing={diskSpaceMissing}
notEnoughSpace={notEnoughSpace}
/>
)
}
{showReportIssue && (
<div className={styles.reportIssue}>
<h1 className={styles.reportIssueText}>
Expand Down
@@ -0,0 +1,59 @@
@import "../../themes/mixins/animations";

.component {
align-items: center;
background-color: var(--theme-loading-no-disk-space-background-color);
bottom: 0;
box-shadow: 0 5px 20px 0 rgba(0, 0, 0, 0.25);
color: var(--theme-loading-no-disk-space-text-color);
display: flex;
flex-direction: column;
justify-content: center;
left: 0;
padding: 50px;
position: absolute;
right: 0;
text-align: center;
top: 0;
z-index: 1;

.icon {
margin-bottom: 36px;
object-fit: contain;
& > svg {
height: 110px;
width: 110px;
path {
fill: var(--theme-loading-no-disk-space-attention-icon-color);
}
path:nth-child(1) {
opacity: 0.2;
}
path:nth-child(2) {
opacity: 0.6;
}
}
}

h1, p, button {
font-family: var(--font-regular);
}

h1 {
font-size: 20px;
line-height: 1.2;
margin-bottom: 8.5px;
}

p {
font-size: 16px;
line-height: 1.38;
margin-bottom: 20px;
opacity: 0.8;
}

b {
font-weight: bold;
}

}
63 changes: 63 additions & 0 deletions source/renderer/app/components/loading/NoDiskSpaceOverlay.js
@@ -0,0 +1,63 @@
// @flow
import React, { Component } from 'react';
import SVGInline from 'react-svg-inline';
import { observer } from 'mobx-react';
import { defineMessages, intlShape, FormattedHTMLMessage } from 'react-intl';
import prettysize from 'prettysize';
import attentionIcon from '../../assets/images/attention-big-light.inline.svg';
import styles from './NoDiskSpaceErrorOverlay.scss';

const messages = defineMessages({
overlayContent: {
id: 'noDiskSpace.error.overlayContent',
defaultMessage: '!!!<b>There is not enough disk space left on your device.</b><br />Daedalus requires at least {diskSpaceRequired} to operate. Please free up some disk space to continue.',
description: 'Content of No disk space overlay'
},
overlayTitle: {
id: 'noDiskSpace.error.overlayTitle',
defaultMessage: '!!!Not enough disk space',
description: 'Title of No disk space overlay'
},
});

type Props = {
diskSpaceAvailable: number,
diskSpaceRequired: number,
diskSpaceMissing: number,
};

@observer
export default class NoDiskSpaceErrorOverlay extends Component<Props> {

static contextTypes = {
intl: intlShape.isRequired,
};

render() {
const { intl } = this.context;
const {
/* diskSpaceAvailable, */ diskSpaceRequired/* , diskSpaceMissing */
} = this.props;

return (
<div className={styles.component}>

<SVGInline svg={attentionIcon} className={styles.icon} />

<div>
<h1>{intl.formatMessage(messages.overlayTitle)}</h1>

<p>
<FormattedHTMLMessage
{...messages.overlayContent}
values={{ diskSpaceRequired: prettysize(diskSpaceRequired) }}
/>
</p>

</div>

</div>
);
}

}