Skip to content

Commit 5ae3639

Browse files
committed
fix
1 parent e3e6528 commit 5ae3639

File tree

15 files changed

+112
-57
lines changed

15 files changed

+112
-57
lines changed

packages/neuron-ui/src/components/DataSetting/hooks.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ export const useDataPath = (network?: State.Network) => {
4747
})
4848
}, [setIsDialogOpen, type])
4949

50+
const onResync = useCallback(async () => {
51+
await stopProcessMonitor(type)
52+
return startProcessMonitor(type)
53+
}, [type])
54+
5055
const onConfirm = useCallback(
5156
(dataPath: string) => {
5257
setPrevPath(dataPath)
@@ -68,6 +73,7 @@ export const useDataPath = (network?: State.Network) => {
6873
onConfirm,
6974
isDialogOpen,
7075
openDialog,
76+
onResync,
7177
}
7278
}
7379

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

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
import React, { useCallback, useMemo } from 'react'
1+
import React, { useCallback, useMemo, useState } from 'react'
22
import { useTranslation } from 'react-i18next'
33
import ClearCache from 'components/ClearCache'
44
import { useDispatch, useState as useGlobalState } from 'states'
55
import { shell } from 'electron'
66
import Tooltip from 'widgets/Tooltip'
77
import { NetworkType } from 'utils/const'
88
import { Attention, More } from 'widgets/Icons/icon'
9+
import Toast from 'widgets/Toast'
910
import ModifyPathDialog from 'components/ModifyPathDialog'
11+
import AlertDialog from 'widgets/AlertDialog'
12+
import { isSuccessResponse } from 'utils'
1013
import { useDataPath } from './hooks'
1114

1215
import styles from './dataSetting.module.scss'
@@ -66,17 +69,31 @@ const DataSetting = () => {
6669
chain: { networkID },
6770
settings: { networks = [] },
6871
} = useGlobalState()
72+
const [notice, setNotice] = useState('')
73+
const [showLostDialog, setShowLostDialog] = useState(false)
6974
const network = useMemo(() => networks.find(n => n.id === networkID), [networkID, networks])
70-
const { isDialogOpen, openDialog, onSetting, prevPath, currentPath, onCancel, onConfirm } = useDataPath(network)
75+
const { isDialogOpen, openDialog, onSetting, prevPath, currentPath, onCancel, onConfirm, onResync } =
76+
useDataPath(network)
7177

7278
const openPath = useCallback(() => {
73-
if (prevPath) {
74-
shell.openPath(prevPath!)
75-
}
76-
}, [prevPath])
79+
shell.openPath(prevPath).then(res => {
80+
if (res) {
81+
setShowLostDialog(true)
82+
}
83+
})
84+
}, [prevPath, onResync])
7785
const isLightClient = network?.type === NetworkType.Light
7886
const hiddenDataPath = isLightClient || !network?.readonly
7987

88+
const handleResync = useCallback(() => {
89+
setShowLostDialog(false)
90+
onResync().then(res => {
91+
if (isSuccessResponse(res)) {
92+
openPath()
93+
}
94+
})
95+
}, [openPath])
96+
8097
return (
8198
<>
8299
<div className={styles.root}>
@@ -119,8 +136,24 @@ const DataSetting = () => {
119136
onCancel={onCancel}
120137
onConfirm={onConfirm}
121138
onSetting={onSetting}
139+
setNotice={setNotice}
122140
/>
123141
)}
142+
143+
{showLostDialog && (
144+
<AlertDialog
145+
show
146+
title={t('settings.data.sync-file-lost')}
147+
message={t('settings.data.sync-file-lost-notice')}
148+
type="warning"
149+
cancelText={t('settings.data.resync')}
150+
onCancel={handleResync}
151+
okText={t('settings.data.retry')}
152+
onOk={() => setShowLostDialog(false)}
153+
/>
154+
)}
155+
156+
<Toast content={notice} onDismiss={() => setNotice('')} />
124157
</>
125158
)
126159
}

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React, { useState, useCallback, useEffect } from 'react'
22
import { useTranslation } from 'react-i18next'
33
import Dialog from 'widgets/Dialog'
4-
import Button from 'widgets/Button'
54
import AlertDialog from 'widgets/AlertDialog'
65
import MigrateCkbDataDialog from 'widgets/MigrateCkbDataDialog'
76
import { setCkbNodeDataPath, getCkbNodeDataNeedSize } from 'services/remote'
@@ -15,12 +14,14 @@ const ModifyPathDialog = ({
1514
onCancel,
1615
onConfirm,
1716
onSetting,
17+
setNotice,
1818
}: {
1919
onCancel?: () => void
2020
prevPath: string
2121
currentPath: string
2222
onConfirm: (dataPath: string) => void
2323
onSetting: (onSuccess?: (path: string) => void) => void
24+
setNotice: (notice: string) => void
2425
}) => {
2526
const [t] = useTranslation()
2627
const [isMigrateOpen, setIsMigrateOpen] = useState(false)
@@ -36,7 +37,7 @@ const ModifyPathDialog = ({
3637
})
3738
}, [])
3839

39-
const handleResynchronize = useCallback(async () => {
40+
const handleResync = useCallback(async () => {
4041
setFailureMessage('')
4142
onSetting(path => {
4243
setCkbNodeDataPath({
@@ -50,7 +51,7 @@ const ModifyPathDialog = ({
5051
}
5152
})
5253
})
53-
}, [onSetting, onConfirm])
54+
}, [onSetting, onConfirm, setFailureMessage])
5455

5556
if (isMigrateOpen) {
5657
return (
@@ -59,6 +60,8 @@ const ModifyPathDialog = ({
5960
currentPath={currentPath}
6061
onCancel={() => setIsMigrateOpen(false)}
6162
onConfirm={onConfirm}
63+
onClose={onCancel}
64+
setNotice={setNotice}
6265
/>
6366
)
6467
}
@@ -74,6 +77,7 @@ const ModifyPathDialog = ({
7477
confirmText={t('wizard.next')}
7578
className={styles.dialog}
7679
disabled={!currentPath}
80+
onClose={onCancel}
7781
>
7882
<div>
7983
<div className={styles.tip}>
@@ -82,7 +86,7 @@ const ModifyPathDialog = ({
8286
</div>
8387

8488
<div className={styles.pathItem}>
85-
<p>{currentPath}</p>
89+
<p>{currentPath || 'path/to/ckb_node_data'}</p>
8690
<button type="button" onClick={() => onSetting()}>
8791
{t('settings.data.browse')}
8892
</button>
@@ -97,25 +101,21 @@ const ModifyPathDialog = ({
97101
<Dialog
98102
show={!failureMessage}
99103
title={t('settings.data.modify-path')}
100-
showFooter={false}
101-
onCancel={onCancel}
102104
className={styles.dialog}
105+
onClose={onCancel}
106+
confirmText={t('settings.data.retain-previous-data')}
107+
onConfirm={() => setIsRetainPreviousData(true)}
108+
confirmProps={{ type: 'dashed' }}
109+
cancelText={t('settings.data.resync')}
110+
onCancel={handleResync}
111+
cancelProps={{ type: 'dashed' }}
103112
>
104113
<div>
105114
<div className={styles.tip}>
106115
<Attention />
107116
{t('settings.data.modify-path-notice', { needSize })}
108117
</div>
109118
<p className={styles.modifyTip}>{t('settings.data.modify-path-content')}</p>
110-
111-
<div className={styles.footer}>
112-
<Button type="dashed" label={t('settings.data.resynchronize')} onClick={handleResynchronize} />
113-
<Button
114-
type="dashed"
115-
label={t('settings.data.retain-previous-data')}
116-
onClick={() => setIsRetainPreviousData(true)}
117-
/>
118-
</div>
119119
</div>
120120
</Dialog>
121121
<AlertDialog

packages/neuron-ui/src/components/ModifyPathDialog/modifyPathDialog.module.scss

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,6 @@
4848
color: var(--main-text-color);
4949
}
5050

51-
.footer {
52-
background: var(--secondary-background-color);
53-
padding: 24px 0 20px;
54-
@include dialog-footer;
55-
56-
button {
57-
padding: 0 20px;
58-
}
59-
60-
button:nth-child(2) {
61-
margin-left: 24px;
62-
}
63-
}
64-
6551
.pathItem {
6652
display: flex;
6753
align-items: center;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ const Settings = () => {
116116

117117
useOnLocalStorageChange(onChange)
118118
return (
119-
<PageContainer head={t('navbar.settings')} notice={globalState.app.pageNotice}>
119+
<PageContainer head={t('navbar.settings')}>
120120
<div className={styles.container}>
121121
{items.map(([title, marginTop, ItemCmp]) => (
122122
<div className={styles.item} key={title}>

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,6 @@
504504
"modify-path": "تعديل المسار",
505505
"modify-path-notice": "يرجى التأكد من أن المساحة المتبقية على القرص أكبر من {{needSize}} جيجابايت لتخزين بيانات عقدة CKB.",
506506
"modify-path-content": "يمكنك اختيار مسار جديد لإعادة المزامنة أو نقل البيانات السابقة لمتابعة المزامنة.",
507-
"resynchronize": "إعادة المزامنة",
508507
"retain-previous-data": "احتفظ بالبيانات السابقة",
509508
"set-a-new-path": "تعيين مسار جديد",
510509
"browse": "تصفح",
@@ -515,7 +514,11 @@
515514
"migrate-step-2": "افتح المسار الذي تم تعيينه حديثًا.",
516515
"migrate-step-3": "نسخ جميع الملفات إلى المسار الجديد.",
517516
"click-here": "انقر هنا",
518-
"migrate-data-successful": "تم نقل البيانات بنجاح"
517+
"migrate-data-successful": "تم نقل البيانات بنجاح",
518+
"resync": "إعادة المزامنة",
519+
"retry": "إعادة المحاولة",
520+
"sync-file-lost": "تم فقدان ملف المزامنة",
521+
"sync-file-lost-notice": "يرجى استعادة الملف والمحاولة مرة أخرى، أو إعادة المزامنة."
519522
}
520523
},
521524
"password-request": {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,6 @@
504504
"modify-path": "Modify Path",
505505
"modify-path-notice": "Please ensure the remaining disk space is greater than {{needSize}} G for storing CKB Node Data.",
506506
"modify-path-content": "You can choose a new path to resynchronize or migrate previous data to continue synchronization.",
507-
"resynchronize": "Resynchronize",
508507
"retain-previous-data": "Retain previous data",
509508
"set-a-new-path": "Set a new path",
510509
"browse": "Browse",
@@ -515,7 +514,10 @@
515514
"migrate-step-2": "Open the newly set path.",
516515
"migrate-step-3": "Copy all files to the new path.",
517516
"click-here": "Click Here",
518-
"migrate-data-successful": "Migrate data successful"
517+
"resync": "Resync",
518+
"retry": "Retry",
519+
"sync-file-lost": "Sync file lost",
520+
"sync-file-lost-notice": "Please recover and retry, or resync."
519521
}
520522
},
521523
"password-request": {

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,6 @@
487487
"modify-path": "Modificar ruta",
488488
"modify-path-notice": "Por favor, asegúrese de que el espacio disponible en el disco sea mayor a {{needSize}} GB para almacenar los datos del Nodo CKB.",
489489
"modify-path-content": "Puedes elegir una nueva ruta para volver a sincronizar o migrar los datos anteriores para continuar la sincronización.",
490-
"resynchronize": "Volver a sincronizar",
491490
"retain-previous-data": "Conservar datos anteriores",
492491
"set-a-new-path": "Establecer una nueva ruta",
493492
"browse": "Explorar",
@@ -498,7 +497,11 @@
498497
"migrate-step-2": "Abrir la nueva ruta establecida.",
499498
"migrate-step-3": "Copiar todos los archivos al nuevo camino.",
500499
"click-here": "Haz clic aquí",
501-
"migrate-data-successful": "Migración de datos exitosa"
500+
"migrate-data-successful": "Migración de datos exitosa",
501+
"resync": "Reiniciar sincronización",
502+
"retry": "Reintentar",
503+
"sync-file-lost": "Archivo de sincronización perdido",
504+
"sync-file-lost-notice": "Por favor, recupere el archivo e intente de nuevo, o reinicie la sincronización."
502505
}
503506
},
504507
"password-request": {

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,6 @@
494494
"modify-path": "Modifier le chemin",
495495
"modify-path-notice": "Veuillez vous assurer que l'espace disque restant est supérieur à {{needSize}} Go pour stocker les données du nœud CKB.",
496496
"modify-path-content": "Vous pouvez choisir un nouveau chemin pour resynchroniser ou migrer les données précédentes afin de continuer la synchronisation.",
497-
"resynchronize": "Resynchroniser",
498497
"retain-previous-data": "Conserver les données précédentes",
499498
"set-a-new-path": "Définir un nouveau chemin",
500499
"browse": "Parcourir",
@@ -505,7 +504,11 @@
505504
"migrate-step-2": "Ouvrir le nouveau chemin défini.",
506505
"migrate-step-3": "Copier tous les fichiers vers le nouveau chemin.",
507506
"click-here": "Cliquez ici",
508-
"migrate-data-successful": "Migration des données réussie"
507+
"migrate-data-successful": "Migration des données réussie",
508+
"resync": "Resynchroniser",
509+
"retry": "Réessayer",
510+
"sync-file-lost": "Fichier de synchronisation perdu",
511+
"sync-file-lost-notice": "Veuillez récupérer le fichier et réessayer, ou resynchroniser."
509512
}
510513
},
511514
"password-request": {

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,6 @@
498498
"modify-path": "修改路徑",
499499
"modify-path-notice": "請確保剩餘的磁碟空間大於 {{needSize}} GB 以存儲 CKB 節點資料。",
500500
"modify-path-content": "您可以選擇一個新路徑重新同步或遷移以前的資料以繼續同步。",
501-
"resynchronize": "重新同步",
502501
"retain-previous-data": "保留先前的資料",
503502
"set-a-new-path": "設置新路徑",
504503
"browse": "瀏覽",
@@ -509,7 +508,11 @@
509508
"migrate-step-2": "打開新設置的路徑。",
510509
"migrate-step-3": "將所有檔案複製到新路徑。",
511510
"click-here": "點擊這裡",
512-
"migrate-data-successful": "資料遷移成功"
511+
"migrate-data-successful": "資料遷移成功",
512+
"resync": "重新同步",
513+
"retry": "重試",
514+
"sync-file-lost": "同步文件遺失",
515+
"sync-file-lost-notice": "請恢復文件並重試,或重新同步。"
513516
}
514517
},
515518
"password-request": {

0 commit comments

Comments
 (0)