From 8c6685951ca66cd7a5e1021baab5af388d55fd0a Mon Sep 17 00:00:00 2001 From: cpl121 Date: Tue, 3 Oct 2023 08:13:28 +0200 Subject: [PATCH 1/4] feat: add "Verify Address" button for Ledger Nano --- .../modals/AccountActionsMenu.svelte | 42 ++++++++++++++++++- packages/shared/locales/en.json | 1 + 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/packages/desktop/components/modals/AccountActionsMenu.svelte b/packages/desktop/components/modals/AccountActionsMenu.svelte index ec9fef8c294..5e18e94a59e 100644 --- a/packages/desktop/components/modals/AccountActionsMenu.svelte +++ b/packages/desktop/components/modals/AccountActionsMenu.svelte @@ -3,14 +3,19 @@ import { selectedAccount } from '@core/account/stores' import { localize } from '@core/i18n' - import { activeAccounts, visibleActiveAccounts } from '@core/profile/stores' + import { activeAccounts, isActiveLedgerProfile, visibleActiveAccounts } from '@core/profile/stores' import { deleteAccount } from '@core/profile-manager/actions' import { Icon } from '@auxiliary/icon/enums' import { openPopup, PopupId } from '@auxiliary/popup' + import { profileManager } from '@core/profile-manager' + import { displayNotificationForLedgerProfile, ledgerNanoStatus } from '@core/ledger' + import { showAppNotification } from '@auxiliary/notification' export let modal: Modal = undefined + let error = '' + const showDeleteAccount = $selectedAccount?.index === $activeAccounts?.length - 1 && $visibleActiveAccounts?.length > 1 @@ -24,6 +29,40 @@ modal?.close() } + function onVerifyAddressClick(): void { + const ADDRESS_INDEX = 0 + try { + error = '' + if ($profileManager && $selectedAccount) { + if ($isActiveLedgerProfile && !$ledgerNanoStatus.connected) { + displayNotificationForLedgerProfile('warning') + return + } + $profileManager.generateEd25519Address($selectedAccount.index, ADDRESS_INDEX, { + internal: false, + ledgerNanoPrompt: true, + }) + showAppNotification({ + type: 'info', + message: localize('views.generateNewLedgerAddress.confirmedBody'), + }) + } + } catch (err) { + error = localize(err.error) + + if ($isActiveLedgerProfile) { + displayNotificationForLedgerProfile('error', true, true, err) + } else { + showAppNotification({ + type: 'error', + message: localize(err.error), + }) + } + } finally { + modal?.close() + } + } + function onDeleteAccountClick(): void { openPopup({ id: PopupId.DeleteAccount, @@ -39,6 +78,7 @@ +
diff --git a/packages/shared/locales/en.json b/packages/shared/locales/en.json index dcd65f675ed..6256db9ab95 100644 --- a/packages/shared/locales/en.json +++ b/packages/shared/locales/en.json @@ -1338,6 +1338,7 @@ "viewDownloads" : "View downloads", "viewStatus": "View status", "viewBalanceBreakdown": "View balance breakdown", + "verifyAddress": "Verify address", "showHiddenAccounts": "Show hidden wallets", "confirm": "Confirm", "hideNetworkStatistics": "Hide network statistics", From 295e7e3b71329185065767e99f6deae3a0f43858 Mon Sep 17 00:00:00 2001 From: cpl121 Date: Wed, 4 Oct 2023 09:11:58 +0200 Subject: [PATCH 2/4] feat: improvements --- .../modals/AccountActionsMenu.svelte | 54 ++++++++----------- 1 file changed, 22 insertions(+), 32 deletions(-) diff --git a/packages/desktop/components/modals/AccountActionsMenu.svelte b/packages/desktop/components/modals/AccountActionsMenu.svelte index 5e18e94a59e..cafa7df8157 100644 --- a/packages/desktop/components/modals/AccountActionsMenu.svelte +++ b/packages/desktop/components/modals/AccountActionsMenu.svelte @@ -9,13 +9,12 @@ import { Icon } from '@auxiliary/icon/enums' import { openPopup, PopupId } from '@auxiliary/popup' import { profileManager } from '@core/profile-manager' - import { displayNotificationForLedgerProfile, ledgerNanoStatus } from '@core/ledger' + import { checkOrConnectLedger } from '@core/ledger' import { showAppNotification } from '@auxiliary/notification' + import { handleError } from '@core/error/handlers' export let modal: Modal = undefined - let error = '' - const showDeleteAccount = $selectedAccount?.index === $activeAccounts?.length - 1 && $visibleActiveAccounts?.length > 1 @@ -31,36 +30,25 @@ function onVerifyAddressClick(): void { const ADDRESS_INDEX = 0 - try { - error = '' - if ($profileManager && $selectedAccount) { - if ($isActiveLedgerProfile && !$ledgerNanoStatus.connected) { - displayNotificationForLedgerProfile('warning') - return + checkOrConnectLedger(() => { + try { + if ($profileManager && $selectedAccount && $isActiveLedgerProfile) { + $profileManager.generateEd25519Address($selectedAccount.index, ADDRESS_INDEX, { + internal: false, + ledgerNanoPrompt: true, + }) + showAppNotification({ + type: 'info', + message: localize('views.generateNewLedgerAddress.confirmedBody'), + }) } - $profileManager.generateEd25519Address($selectedAccount.index, ADDRESS_INDEX, { - internal: false, - ledgerNanoPrompt: true, - }) - showAppNotification({ - type: 'info', - message: localize('views.generateNewLedgerAddress.confirmedBody'), - }) - } - } catch (err) { - error = localize(err.error) - - if ($isActiveLedgerProfile) { - displayNotificationForLedgerProfile('error', true, true, err) - } else { - showAppNotification({ - type: 'error', - message: localize(err.error), - }) + } catch (err) { + handleError(err) + } finally { + modal?.close() } - } finally { - modal?.close() - } + return Promise.resolve() + }) } function onDeleteAccountClick(): void { @@ -78,7 +66,9 @@ - + {#if $isActiveLedgerProfile} + + {/if}
From f2ed8574982e8903ba54982283d6bae218e6c954 Mon Sep 17 00:00:00 2001 From: cpl121 Date: Wed, 11 Oct 2023 09:35:07 +0200 Subject: [PATCH 3/4] refactor: improve literals --- .../desktop/components/modals/AccountActionsMenu.svelte | 8 ++++++-- packages/shared/locales/en.json | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/desktop/components/modals/AccountActionsMenu.svelte b/packages/desktop/components/modals/AccountActionsMenu.svelte index cafa7df8157..e71a0be2fce 100644 --- a/packages/desktop/components/modals/AccountActionsMenu.svelte +++ b/packages/desktop/components/modals/AccountActionsMenu.svelte @@ -39,7 +39,7 @@ }) showAppNotification({ type: 'info', - message: localize('views.generateNewLedgerAddress.confirmedBody'), + message: localize('general.verifyLedgerDepositAddress'), }) } } catch (err) { @@ -67,7 +67,11 @@ {#if $isActiveLedgerProfile} - + {/if} diff --git a/packages/shared/locales/en.json b/packages/shared/locales/en.json index 7d65bc27132..c63000e7a5d 100644 --- a/packages/shared/locales/en.json +++ b/packages/shared/locales/en.json @@ -1338,7 +1338,7 @@ "viewDownloads" : "View downloads", "viewStatus": "View status", "viewBalanceBreakdown": "View balance breakdown", - "verifyAddress": "Verify address", + "verifyDepositAddress": "Verify deposit address", "showHiddenAccounts": "Show hidden wallets", "confirm": "Confirm", "hideNetworkStatistics": "Hide network statistics", @@ -1665,7 +1665,8 @@ "jwt": "JSON web token", "internalTransaction": "Internal transaction", "coinType":"Coin type", - "custom": "Custom" + "custom": "Custom", + "verifyLedgerDepositAddress": "Please check the ledger device and verify that the deposit address matches the one displayed on the ledger device" }, "filters":{ "title": "Filters", From e1b25f807f37d13c716efd9931a99fd8817c2c13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bego=C3=B1a=20Alvarez?= Date: Wed, 11 Oct 2023 10:07:08 +0200 Subject: [PATCH 4/4] chore: change menu item order --- packages/desktop/components/modals/AccountActionsMenu.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/desktop/components/modals/AccountActionsMenu.svelte b/packages/desktop/components/modals/AccountActionsMenu.svelte index e71a0be2fce..b3199b6ab3b 100644 --- a/packages/desktop/components/modals/AccountActionsMenu.svelte +++ b/packages/desktop/components/modals/AccountActionsMenu.svelte @@ -66,6 +66,7 @@ + {#if $isActiveLedgerProfile} {/if} -
{#if showDeleteAccount}