Skip to content

Commit 84b50f2

Browse files
committed
frontend: preselect backup when there's only 1, and show message
of "Please select backup to continue" when there are more than 1 backups available.
1 parent f4cfb7e commit 84b50f2

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

frontends/web/src/locales/en/app.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
},
142142
"restoring": "Restoring backup…",
143143
"selectedBackup": "<strong>{{backupName}}</strong> created on {{createdDateTime}} will be restored.",
144+
"subtitle": "Please select backup to continue",
144145
"title": "Restore",
145146
"understand": "I understand that an incorrect recovery password will create a different wallet"
146147
},

frontends/web/src/routes/device/bitbox02/backups.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { ReactNode, useState } from 'react';
18+
import { ReactNode, useEffect, useState } from 'react';
1919
import { useTranslation } from 'react-i18next';
2020
import { useSync } from '../../../hooks/api';
2121
import { restoreBackup } from '../../../api/bitbox02';
@@ -55,6 +55,18 @@ export const BackupsV2 = ({
5555

5656
const backups = useSync(() => getBackupList(deviceID), subscribeBackupList(deviceID));
5757
const hasBackups = backups && backups.success && backups !== undefined;
58+
const hasMoreThanOneBackups = hasBackups && backups.backups.length > 1;
59+
60+
useEffect(() => {
61+
if (!hasBackups || backups.backups.length === 0) {
62+
return;
63+
}
64+
65+
if (backups.backups.length === 1) {
66+
setSelectedBackup(backups.backups[0].id);
67+
}
68+
69+
}, [backups, hasBackups]);
5870

5971
const restore = () => {
6072
if (!hasBackups) {
@@ -96,6 +108,7 @@ export const BackupsV2 = ({
96108
</Toast>
97109
)
98110
}
111+
{showRadio && hasMoreThanOneBackups ? <p className="m-none m-bottom-large">{t('backup.restore.subtitle')}</p> : null}
99112
<div className={backupStyle.backupsList}>
100113
{
101114
backups.backups.length ? (

frontends/web/src/routes/device/bitbox02/setup/restore.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ export const RestoreFromSDCardBackup = ({
4848
showRestore={true}
4949
showRadio={true}
5050
onSelectBackup={onSelectBackup}
51-
onRestoreBackup={onRestoreBackup}>
51+
onRestoreBackup={onRestoreBackup}
52+
>
5253
<Button
5354
secondary
5455
onClick={onBack}>

0 commit comments

Comments
 (0)