Skip to content

Commit 98fe06c

Browse files
committed
feat: Adding check update to settings view
1 parent d0718c7 commit 98fe06c

7 files changed

Lines changed: 77 additions & 22 deletions

File tree

packages/neuron-ui/src/components/GeneralSetting/index.tsx

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,21 @@ import { useTranslation } from 'react-i18next'
33
import { Stack, PrimaryButton, Spinner, Text } from 'office-ui-fabric-react'
44
import { StateWithDispatch } from 'states/stateProvider/reducer'
55
import { addPopup } from 'states/stateProvider/actionCreators'
6-
import { clearCellCache } from 'services/remote'
6+
import { checkForUpdates, clearCellCache } from 'services/remote'
77

88
const GeneralSetting = ({ dispatch }: React.PropsWithoutRef<StateWithDispatch>) => {
99
const [t] = useTranslation()
1010
const [clearing, setClearing] = useState(false)
11+
const [checkingUpdates, setCheckingUpdates] = useState(false) // TODO: checkingUpdates should be fetched from backend
12+
13+
const checkUpdates = useCallback(() => {
14+
setCheckingUpdates(true)
15+
setTimeout(() => {
16+
checkForUpdates().finally(() => {
17+
setCheckingUpdates(false)
18+
})
19+
}, 100)
20+
}, [dispatch])
1121

1222
const clearCache = useCallback(() => {
1323
setClearing(true)
@@ -21,23 +31,42 @@ const GeneralSetting = ({ dispatch }: React.PropsWithoutRef<StateWithDispatch>)
2131

2232
return (
2333
<Stack tokens={{ childrenGap: 15 }}>
24-
<Stack horizontal horizontalAlign="start">
25-
<PrimaryButton
26-
onClick={clearCache}
27-
disabled={clearing}
28-
ariaDescription="Create new network configuration"
29-
styles={{
30-
root: {
31-
minWidth: 150,
32-
},
33-
}}
34-
>
35-
{clearing ? <Spinner /> : t('settings.general.clear-cache')}
36-
</PrimaryButton>
34+
<Stack>
35+
<Stack horizontal horizontalAlign="start">
36+
<PrimaryButton
37+
onClick={checkUpdates}
38+
disabled={checkingUpdates}
39+
ariaDescription="Check updates"
40+
styles={{
41+
root: {
42+
minWidth: 150,
43+
},
44+
}}
45+
>
46+
{checkingUpdates ? <Spinner /> : t('updates.check-updates')}
47+
</PrimaryButton>
48+
</Stack>
49+
</Stack>
50+
51+
<Stack>
52+
<Text as="p" variant="medium">
53+
{t('settings.general.clear-cache-description')}
54+
</Text>
55+
<Stack horizontal horizontalAlign="start">
56+
<PrimaryButton
57+
onClick={clearCache}
58+
disabled={clearing}
59+
ariaDescription="Clear cache"
60+
styles={{
61+
root: {
62+
minWidth: 150,
63+
},
64+
}}
65+
>
66+
{clearing ? <Spinner /> : t('settings.general.clear-cache')}
67+
</PrimaryButton>
68+
</Stack>
3769
</Stack>
38-
<Text as="p" variant="medium">
39-
{t('settings.general.clear-cache-description')}
40-
</Text>
4170
</Stack>
4271
)
4372
}

packages/neuron-ui/src/locales/en.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,10 @@
343343
"withdraw-alert": "Hint: these are only {{epochs}} epochs (~{{hours}} hours) until the end of your current lock period. If you wish to withdraw in current lock period, please send withdraw request in time. There are {{nextLeftEpochs}} epochs(~{{days}} days) until the end of your next lock period.",
344344
"insufficient-period-alert-title": "Referenced Header is Invalid",
345345
"insufficient-period-alert-message": "Only mature header can be referenced in transactions(Matureness requires 4 epochs)"
346+
},
347+
"updates": {
348+
"check-updates": "Check for Updates",
349+
"download-update": "Download Update"
346350
}
347351
}
348352
}

packages/neuron-ui/src/locales/zh.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,10 @@
343343
"withdraw-alert": "提示:本补贴申请距离 Nervos DAO 规则允许的最近一个锁定周期仅剩下 {{epochs}} 个 epoch (约 {{hours}} 小时)。 如果您希望在本锁定周期取出,请及时提交取出申请,以确保取出申请能在本锁定周期结束之前上链。下一个锁定周期的结束时间预计为 {{nextLeftEpochs}} 个 epochs (约 {{days}} 天)。",
344344
"insufficient-period-alert-title": "Header 引用无效",
345345
"insufficient-period-alert-message": "交易只能引用已成熟的 Header(成熟期为 4 个 epochs)"
346+
},
347+
"updates": {
348+
"check-updates": "检查更新",
349+
"download-update": "下载更新"
346350
}
347351
}
348352
}

packages/neuron-ui/src/services/remote/app.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ export const getNeuronWalletState = apiMethodWrapper<void>(api => () => api.load
55
export const handleViewError = apiMethodWrapper<string>(api => errorMessage => api.handleViewError(errorMessage))
66
export const contextMenu = apiMethodWrapper<{ type: string; id: string }>(api => params => api.contextMenu(params))
77

8+
export const checkForUpdates = apiMethodWrapper<void>(api => () => api.checkForUpdates())
89
export const clearCellCache = apiMethodWrapper<void>(api => () => api.clearCellCache())
910

1011
export default {
1112
getNeuronWalletState,
1213
handleViewError,
1314
contextMenu,
15+
checkForUpdates,
1416
clearCellCache,
1517
}

packages/neuron-wallet/src/controllers/api.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import env from 'env'
44
import i18n from 'utils/i18n'
55
import { popContextMenu } from './app/menu'
66
import { showWindow } from './app/show-window'
7-
import { TransactionsController, WalletsController, SyncController, NetworksController } from 'controllers'
7+
import { TransactionsController, WalletsController, SyncController, NetworksController, UpdateController } from 'controllers'
88
import { NetworkType, NetworkID, Network } from 'types/network'
99
import NetworksService from 'services/networks'
1010
import WalletsService from 'services/wallets'
@@ -271,6 +271,7 @@ export default class ApiController {
271271
}
272272

273273
// Dao
274+
274275
@MapApiResponse
275276
public static async getDaoCells(
276277
params: Controller.Params.GetDaoCellsParams
@@ -279,6 +280,12 @@ export default class ApiController {
279280
}
280281

281282
// settings
283+
284+
@MapApiResponse
285+
public static async checkForUpdates() {
286+
return new UpdateController().checkUpdates()
287+
}
288+
282289
@MapApiResponse
283290
public static async clearCellCache() {
284291
await SyncController.stopSyncing()

packages/neuron-wallet/src/controllers/app/menu.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ const updateApplicationMenu = (mainWindow: BrowserWindow | null) => {
7979
{
8080
enabled: isMainWindow,
8181
label: i18n.t('application-menu.neuron.check-updates'),
82-
click: (menuItem: MenuItem) => { new UpdateController().checkUpdates(menuItem) }
82+
click: (menuItem: MenuItem) => {
83+
new UpdateController().checkUpdates(menuItem)
84+
navTo(URL.Preference)
85+
}
8386
},
8487
separator,
8588
{
@@ -225,7 +228,10 @@ const updateApplicationMenu = (mainWindow: BrowserWindow | null) => {
225228
})
226229
helpSubmenu.push({
227230
label: i18n.t('application-menu.neuron.check-updates'),
228-
click: (menuItem: MenuItem) => { new UpdateController().checkUpdates(menuItem) }
231+
click: (menuItem: MenuItem) => {
232+
new UpdateController().checkUpdates(menuItem)
233+
navTo(URL.Preference)
234+
}
229235
})
230236
helpSubmenu.push({
231237
id: 'about',

packages/neuron-wallet/src/controllers/update.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ export default class UpdateController {
1212
this.bindEvents()
1313
}
1414

15-
public checkUpdates(sender: { enabled: boolean }) {
15+
// TODO: refactor: do not require sender
16+
public checkUpdates(sender: { enabled: boolean } | null = null) {
1617
this.sender = sender
17-
this.sender.enabled = false
18+
if (this.sender) {
19+
this.sender.enabled = false
20+
}
1821

1922
autoUpdater.checkForUpdates()
2023
}

0 commit comments

Comments
 (0)