fix: better handle import errors
This commit is contained in:
@@ -375,9 +375,11 @@ class AccountMenuCtrl extends PureViewCtrl<{}, AccountMenuState> {
|
|||||||
if (!data) {
|
if (!data) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (data.auth_params || data.keyParams) {
|
if (data.version || data.auth_params || data.keyParams) {
|
||||||
const version = data.keyParams?.version || data.auth_params?.version;
|
const version = data.version || data.keyParams?.version || data.auth_params?.version;
|
||||||
if (!this.application!.protocolService!.supportedVersions().includes(version)) {
|
if (
|
||||||
|
!this.application!.protocolService!.supportedVersions().includes(version)
|
||||||
|
) {
|
||||||
await this.setState({ importData: null });
|
await this.setState({ importData: null });
|
||||||
alertDialog({ text: STRING_UNSUPPORTED_BACKUP_FILE_VERSION });
|
alertDialog({ text: STRING_UNSUPPORTED_BACKUP_FILE_VERSION });
|
||||||
return;
|
return;
|
||||||
@@ -419,12 +421,19 @@ class AccountMenuCtrl extends PureViewCtrl<{}, AccountMenuState> {
|
|||||||
loading: true
|
loading: true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const errorCount = await this.importJSONData(data, password);
|
const result = await this.application!.importData(
|
||||||
|
data,
|
||||||
|
password
|
||||||
|
);
|
||||||
this.setState({
|
this.setState({
|
||||||
importData: null
|
importData: null
|
||||||
});
|
});
|
||||||
if (errorCount > 0) {
|
if ('error' in result) {
|
||||||
const message = StringImportError(errorCount);
|
this.application!.alertService!.alert(
|
||||||
|
result.error
|
||||||
|
);
|
||||||
|
} else if (result.errorCount) {
|
||||||
|
const message = StringImportError(result.errorCount);
|
||||||
this.application!.alertService!.alert(
|
this.application!.alertService!.alert(
|
||||||
message
|
message
|
||||||
);
|
);
|
||||||
@@ -435,14 +444,6 @@ class AccountMenuCtrl extends PureViewCtrl<{}, AccountMenuState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async importJSONData(data: BackupFile, password?: string) {
|
|
||||||
const { errorCount } = await this.application!.importData(
|
|
||||||
data,
|
|
||||||
password
|
|
||||||
);
|
|
||||||
return errorCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
async downloadDataArchive() {
|
async downloadDataArchive() {
|
||||||
this.application!.getArchiveService().downloadBackup(this.getState().mutable.backupEncrypted);
|
this.application!.getArchiveService().downloadBackup(this.getState().mutable.backupEncrypted);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user