1- import React , { useCallback , useState } from 'react'
1+ import React , { useContext , useCallback , useState } from 'react'
22import { useTranslation } from 'react-i18next'
33import { Stack , PrimaryButton , Spinner , Text , ProgressIndicator } from 'office-ui-fabric-react'
4+ import { NeuronWalletContext } from 'states/stateProvider'
45import { StateWithDispatch } from 'states/stateProvider/reducer'
56import { addPopup } from 'states/stateProvider/actionCreators'
67import { checkForUpdates , downloadUpdate , installUpdate , clearCellCache } from 'services/remote'
@@ -26,7 +27,7 @@ const UpdateDownloadStatus = ({
2627 < Stack horizontal horizontalAlign = "start" >
2728 < PrimaryButton
2829 onClick = { download }
29- disabled = { available }
30+ disabled = { ! available }
3031 styles = { {
3132 root : {
3233 minWidth : 180 ,
@@ -78,23 +79,19 @@ const UpdateDownloadStatus = ({
7879
7980const GeneralSetting = ( { dispatch } : React . PropsWithoutRef < StateWithDispatch > ) => {
8081 const [ t ] = useTranslation ( )
81- const [ clearing , setClearing ] = useState ( false )
82- const [ checkingUpdates , setCheckingUpdates ] = useState ( false ) // TODO: checkingUpdates should be fetched from backend
83- const [ downloadingUpdate ] = useState ( false )
82+ const { updater } = useContext ( NeuronWalletContext )
83+ const [ clearingCache , setClearingCache ] = useState ( false )
8484
8585 const checkUpdates = useCallback ( ( ) => {
86- setCheckingUpdates ( true )
87- setTimeout ( ( ) => {
88- checkForUpdates ( )
89- } , 100 )
90- } , [ dispatch ] )
86+ checkForUpdates ( )
87+ } , [ ] )
9188
9289 const clearCache = useCallback ( ( ) => {
93- setClearing ( true )
90+ setClearingCache ( true )
9491 setTimeout ( ( ) => {
9592 clearCellCache ( ) . finally ( ( ) => {
9693 addPopup ( 'clear-cache-successfully' ) ( dispatch )
97- setClearing ( false )
94+ setClearingCache ( false )
9895 } )
9996 } , 100 )
10097 } , [ dispatch ] )
@@ -103,20 +100,20 @@ const GeneralSetting = ({ dispatch }: React.PropsWithoutRef<StateWithDispatch>)
103100 < Stack tokens = { { childrenGap : 15 } } >
104101 < Stack >
105102 < Stack horizontal horizontalAlign = "start" >
106- { downloadingUpdate ? (
107- < UpdateDownloadStatus progress = { 1 } newVersion = "v0.25.2" />
103+ { updater . version !== '' || updater . downloadProgress >= 0 ? (
104+ < UpdateDownloadStatus progress = { updater . downloadProgress } newVersion = { updater . version } />
108105 ) : (
109106 < PrimaryButton
110107 onClick = { checkUpdates }
111- disabled = { checkingUpdates }
108+ disabled = { updater . checking }
112109 ariaDescription = "Check updates"
113110 styles = { {
114111 root : {
115112 minWidth : 180 ,
116113 } ,
117114 } }
118115 >
119- { checkingUpdates ? < Spinner /> : t ( 'updates.check-updates' ) }
116+ { updater . checking ? < Spinner /> : t ( 'updates.check-updates' ) }
120117 </ PrimaryButton >
121118 ) }
122119 </ Stack >
@@ -129,15 +126,15 @@ const GeneralSetting = ({ dispatch }: React.PropsWithoutRef<StateWithDispatch>)
129126 < Stack horizontal horizontalAlign = "start" >
130127 < PrimaryButton
131128 onClick = { clearCache }
132- disabled = { clearing }
129+ disabled = { clearingCache }
133130 ariaDescription = "Clear cache"
134131 styles = { {
135132 root : {
136133 minWidth : 180 ,
137134 } ,
138135 } }
139136 >
140- { clearing ? < Spinner /> : t ( 'settings.general.clear-cache' ) }
137+ { clearingCache ? < Spinner /> : t ( 'settings.general.clear-cache' ) }
141138 </ PrimaryButton >
142139 </ Stack >
143140 </ Stack >
0 commit comments