From 5349ec85501a0dc547affe3acca6f4be9f9c260c Mon Sep 17 00:00:00 2001 From: VardanHakobyan Date: Fri, 4 Jun 2021 16:52:58 +0400 Subject: [PATCH] refactor: reviewer's comment --- .../components/AccountMenuReact.tsx | 47 +++++++++---------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/app/assets/javascripts/components/AccountMenuReact.tsx b/app/assets/javascripts/components/AccountMenuReact.tsx index f9be7cdcc..132d7535d 100644 --- a/app/assets/javascripts/components/AccountMenuReact.tsx +++ b/app/assets/javascripts/components/AccountMenuReact.tsx @@ -441,19 +441,17 @@ const AccountMenu = observer(({ application, appState, closeAccountMenu }: Props if (!result) { return; - } else if ('error' in result) { - void alertDialog({ - text: result.error, - }); - } else if (result.errorCount) { - void alertDialog({ - text: StringImportError(result.errorCount), - }); - } else { - void alertDialog({ - text: STRING_IMPORT_SUCCESS, - }); } + + let statusText = STRING_IMPORT_SUCCESS; + if ('error' in result) { + statusText = result.error; + } else if (result.errorCount) { + statusText = StringImportError(result.errorCount); + } + void alertDialog({ + text: statusText + }); }; const importFileSelected = async (event: TargetedEvent) => { @@ -467,19 +465,20 @@ const AccountMenu = observer(({ application, appState, closeAccountMenu }: Props if (!data) { return; } - if (data.version || data.auth_params || data.keyParams) { - const version = - data.version || data.keyParams?.version || data.auth_params?.version; - if ( - application.protocolService.supportedVersions().includes(version) - ) { - await performImport(data); - } else { - setIsImportDataLoading(false); - void alertDialog({ text: STRING_UNSUPPORTED_BACKUP_FILE_VERSION }); - } - } else { + + const version = data.version || data.keyParams?.version || data.auth_params?.version; + if (!version) { await performImport(data); + return; + } + + if ( + application.protocolService.supportedVersions().includes(version) + ) { + await performImport(data); + } else { + setIsImportDataLoading(false); + void alertDialog({ text: STRING_UNSUPPORTED_BACKUP_FILE_VERSION }); } };