diff --git a/public/locales/en.json b/public/locales/en.json index 41fdeba..f6e942a 100644 --- a/public/locales/en.json +++ b/public/locales/en.json @@ -739,10 +739,9 @@ "contactsSkipped_plural": "{{count, number}} contacts were skipped.", "warnings": "There was <1>{{count, number}} warning while importing your backup.", - "warnings_plural": "There were <1>{{count, number}} warning while importing your backup.", + "warnings_plural": "There were <1>{{count, number}} warnings while importing your backup.", "errors": "There was <1>{{count, number}} error while importing your backup.", "errors_plural": "There were <1>{{count, number}} errors while importing your backup.", - "errorsAndWarnings": "There were <1>{{errors, number}} error(s) and <3>{{warnings, number}} warning(s) while importing your backup.", "treeHeaderWallets": "Wallets", "treeHeaderContacts": "Contacts", diff --git a/src/pages/backup/BackupResultsSummary.tsx b/src/pages/backup/BackupResultsSummary.tsx index dff7150..42b0d60 100644 --- a/src/pages/backup/BackupResultsSummary.tsx +++ b/src/pages/backup/BackupResultsSummary.tsx @@ -47,38 +47,22 @@ {/* TODO: Show contact counts too (only if >0) */} - {/* Errors/warnings */} -
- {warningCount > 0 && errorCount > 0 - ? ( - // Show errors and warnings - - There were - {{ errors: errorCount }} error(s) - and - {{ warnings: warningCount }} warning(s) - while importing your backup. - - ) - : (warningCount > 0 - ? ( - // Show just warnings - - There was - {{ count: warningCount }} warning - while importing your backup. - - ) - : (errorCount > 0 - ? ( - // Show just errors - - There was - {{ count: errorCount }} error - while importing your backup. - - ) - : <>))} -
+ {/* Errors */} + {errorCount > 0 &&
+ + There was + {{ count: errorCount }} error + while importing your backup. + +
} + + {/* Warnings */} + {warningCount > 0 &&
+ + There was + {{ count: warningCount }} warning + while importing your backup. + +
} ; } diff --git a/src/pages/backup/backupImport.ts b/src/pages/backup/backupImport.ts index 92b57b3..1f08b70 100644 --- a/src/pages/backup/backupImport.ts +++ b/src/pages/backup/backupImport.ts @@ -10,7 +10,7 @@ import { Backup, BackupFormatType, isBackupKristWebV1 } from "./backupFormats"; import { BackupResults } from "./backupResults"; -import { importV1Wallet } from "./backupImportV1"; +import { importV1Backup } from "./backupImportV1"; import Debug from "debug"; const debug = Debug("kristweb:backup-import"); @@ -107,29 +107,11 @@ // Attempt to add the wallets if (isBackupKristWebV1(backup)) { - // Import wallets from a KristWeb v1 backup - for (const uuid in backup.wallets) { - if (!uuid || !uuid.startsWith("Wallet-")) { - // Not a wallet - debug("skipping v1 wallet key %s", uuid); - continue; - } - - const rawWallet = backup.wallets[uuid]; - debug("importing v1 wallet uuid %s", uuid); - - try { - await importV1Wallet( - existingWallets, appMasterPassword, appSyncNode, addressPrefix, - backup, masterPassword, noOverwrite, - uuid, rawWallet, - results - ); - } catch (err) { - debug("error importing v1 wallet", err); - results.addErrorMessage("wallets", uuid, undefined, err); - } - } + await importV1Backup( + existingWallets, appMasterPassword, appSyncNode, addressPrefix, + backup, masterPassword, noOverwrite, + results + ); } else { debug("WTF: unsupported backup format %s", backup.type); } diff --git a/src/pages/backup/backupImportV1.ts b/src/pages/backup/backupImportV1.ts index 9788dae..13534fa 100644 --- a/src/pages/backup/backupImportV1.ts +++ b/src/pages/backup/backupImportV1.ts @@ -24,9 +24,49 @@ const _upgradeFormatName = (name: string): WalletFormatName => name === "krist" ? "api" : name as WalletFormatName; -/** - * Imports a single wallet in the KristWeb v1 format. - */ +/** Imports a KristWeb v1 backup. */ +export async function importV1Backup( + // Things regarding the app's existing state + existingWallets: WalletMap, + appMasterPassword: string, + appSyncNode: string, + addressPrefix: string, + + // Things related to the backup + backup: BackupKristWebV1, + masterPassword: string, + noOverwrite: boolean, + + results: BackupResults +): Promise { + // Import wallets + for (const uuid in backup.wallets) { + if (!uuid || !uuid.startsWith("Wallet-")) { + // Not a wallet + debug("skipping v1 wallet key %s", uuid); + continue; + } + + const rawWallet = backup.wallets[uuid]; + debug("importing v1 wallet uuid %s", uuid); + + try { + await importV1Wallet( + existingWallets, appMasterPassword, appSyncNode, addressPrefix, + backup, masterPassword, noOverwrite, + uuid, rawWallet, + results + ); + } catch (err) { + debug("error importing v1 wallet", err); + results.addErrorMessage("wallets", uuid, undefined, err); + } + } + + // TODO: Import contacts +} + +/** Imports a single wallet in the KristWeb v1 format. */ export async function importV1Wallet( // Things regarding the app's existing state existingWallets: WalletMap,