From 813165c4bb6ce397f52c101929d954e629794f8b Mon Sep 17 00:00:00 2001 From: maxym Date: Sun, 26 Nov 2023 00:26:57 +0100 Subject: [PATCH] feature: add update modal and block system modal --- app/components/common/Version.tsx | 38 ++++++++++- .../modal/UpdateApplicationWarningModal.tsx | 67 +++++++++++++++++++ desktop/main/autoUpdater.ts | 1 - desktop/main/createMainWindow.ts | 6 +- desktop/main/promptBeforeClose.ts | 9 ++- desktop/main/reactions/handleCloseApp.ts | 8 ++- desktop/main/sources/autoUpdate.ts | 12 ++-- desktop/main/startApp.ts | 7 +- shared/constants.ts | 4 +- 9 files changed, 134 insertions(+), 18 deletions(-) create mode 100644 app/screens/modal/UpdateApplicationWarningModal.tsx diff --git a/app/components/common/Version.tsx b/app/components/common/Version.tsx index ec4face74..389c1f852 100644 --- a/app/components/common/Version.tsx +++ b/app/components/common/Version.tsx @@ -21,6 +21,9 @@ import { getNetworkInfo } from '../../redux/network/selectors'; import { checkUpdates as checkUpdatesIco } from '../../assets/images'; import { AppThDispatch } from '../../types'; import updaterSlice from '../../redux/updater/slice'; +import { SECOND } from '../../../shared/constants'; +import { Loader } from '../../basicComponents'; +import UpdateApplicationWarningModal from '../../screens/modal/UpdateApplicationWarningModal'; import FeedbackButton from './Feedback'; const Container = styled.div` @@ -194,6 +197,29 @@ const UpdateStatus = () => { const isDownloading = useSelector(isUpdateDownloading); const isDownloaded = useSelector(isUpdateDownloaded); const error = useSelector(getError); + const [ + isOpenUpdateApplicationWarningModal, + setIsOpenUpdateApplicationWarningModal, + ] = useState(false); + const [ + showUpdateApplicationLoader, + setShowUpdateApplicationLoader, + ] = useState(false); + + const handleRestartNow = () => { + setIsOpenUpdateApplicationWarningModal(false); + setShowUpdateApplicationLoader(true); + eventsService.installUpdate(); + + setTimeout(() => { + setShowUpdateApplicationLoader(false); + }, 10 * SECOND); + }; + + const handlePostpone = () => { + setIsOpenUpdateApplicationWarningModal(false); + }; + if (!isDownloading && !isDownloaded) return null; if (progress !== null && !isDownloaded) { @@ -207,9 +233,19 @@ const UpdateStatus = () => { return ( <> Update is ready to install - eventsService.installUpdate()}> + setIsOpenUpdateApplicationWarningModal(true)} + > Restart Smapp + + {showUpdateApplicationLoader && ( + + )} ); } diff --git a/app/screens/modal/UpdateApplicationWarningModal.tsx b/app/screens/modal/UpdateApplicationWarningModal.tsx new file mode 100644 index 000000000..541eccd44 --- /dev/null +++ b/app/screens/modal/UpdateApplicationWarningModal.tsx @@ -0,0 +1,67 @@ +import React from 'react'; +import styled from 'styled-components'; +import Modal from '../../components/common/Modal'; +import { Button } from '../../basicComponents'; +import { smColors } from '../../vars'; + +const ButtonsWrapper = styled.div` + display: flex; + flex-direction: row; + justify-content: space-between; + margin: auto 0 15px 0; + padding-top: 30px; +`; + +const Message = styled.pre` + font-size: 14px; + line-height: 1.33em; + word-wrap: break-word; + white-space: pre-wrap; + overflow-y: auto; + margin-top: 15px; + + ul { + list-style: none; + margin-left: 10px; + } + li { + margin: 10px 0; + } + li:before { + content: '• '; + padding: 5px; + } +`; + +const UpdateApplicationWarningModal = ({ isOpen, onApprove, onCancel }) => { + if (!isOpen) return null; + + return ( + + +

+ Restarting now is CRITICAL and may impact your node’s + performance and rewards. +

+
    +
  • + Click RESTART NOW to apply + the update immediately. Delaying the update could result in + potential loss of rewards. +
  • +
  • + Click POSTPONE to delay + the update. Be aware that postponing may slow down your node’s + performance and future rewards. +
  • +
+
+ +