From cf095050716f931c8f64faa625a5ddf10f73abe2 Mon Sep 17 00:00:00 2001 From: Sale Djenic Date: Fri, 5 Jan 2024 11:57:15 +0100 Subject: [PATCH] feat(savedaddresses): context menu - remove saved address Closes #13093 --- .../wallet_section/saved_addresses/module.nim | 5 +- .../wallet_section/saved_addresses/view.nim | 2 +- .../ui-test/src/screens/StatusWalletScreen.py | 2 +- .../screens/components/confirmation_popup.py | 4 + .../global_shared/scripts/settings_names.py | 2 +- .../global_shared/scripts/wallet_names.py | 1 + .../controls/SavedAddressesDelegate.qml | 56 ++++----- .../Wallet/popups/RemoveSavedAddressPopup.qml | 109 ++++++++++++++++++ ui/app/AppLayouts/Wallet/popups/qmldir | 1 + ui/app/mainui/AppMain.qml | 72 +++++------- 10 files changed, 180 insertions(+), 74 deletions(-) create mode 100644 ui/app/AppLayouts/Wallet/popups/RemoveSavedAddressPopup.qml diff --git a/src/app/modules/main/wallet_section/saved_addresses/module.nim b/src/app/modules/main/wallet_section/saved_addresses/module.nim index 59ecb75ff5..bf5e575b6a 100644 --- a/src/app/modules/main/wallet_section/saved_addresses/module.nim +++ b/src/app/modules/main/wallet_section/saved_addresses/module.nim @@ -73,8 +73,11 @@ method savedAddressUpdated*(self: Module, name: string, address: string, ens: st self.view.savedAddressAddedOrUpdated(item.isEmpty(), name, address, ens, errorMsg) method savedAddressDeleted*(self: Module, address: string, ens: string, errorMsg: string) = + var item = self.view.getModel().getItemByEnsOrAddress(address) + if item.isEmpty(): + item = self.view.getModel().getItemByEnsOrAddress(ens) self.loadSavedAddresses() - self.view.savedAddressDeleted(address, ens, errorMsg) + self.view.savedAddressDeleted(item.getName(), address, ens, errorMsg) method savedAddressNameExists*(self: Module, name: string): bool = return self.view.getModel().nameExists(name) diff --git a/src/app/modules/main/wallet_section/saved_addresses/view.nim b/src/app/modules/main/wallet_section/saved_addresses/view.nim index 708d4094ec..6cbcf9f056 100644 --- a/src/app/modules/main/wallet_section/saved_addresses/view.nim +++ b/src/app/modules/main/wallet_section/saved_addresses/view.nim @@ -46,7 +46,7 @@ QtObject: favourite: bool, chainShortNames: string) {.slot.} = self.delegate.createOrUpdateSavedAddress(name, address, ens, colorId, favourite, chainShortNames) - proc savedAddressDeleted*(self: View, address: string, ens: string, errorMsg: string) {.signal.} + proc savedAddressDeleted*(self: View, name: string, address: string, ens: string, errorMsg: string) {.signal.} proc deleteSavedAddress*(self: View, address: string, ens: string) {.slot.} = self.delegate.deleteSavedAddress(address, ens) diff --git a/test/ui-test/src/screens/StatusWalletScreen.py b/test/ui-test/src/screens/StatusWalletScreen.py index d66f980329..4256eb5e15 100644 --- a/test/ui-test/src/screens/StatusWalletScreen.py +++ b/test/ui-test/src/screens/StatusWalletScreen.py @@ -240,7 +240,7 @@ class AddressesView(BaseElement): self._delete_saved_address_menu_item.wait_until_appears() self._delete_saved_address_menu_item.click() self._delete_saved_address_menu_item.wait_until_hidden() - ConfirmationPopup().wait_until_appears().confirm() + ConfirmationPopup().wait_until_appears().confirmWithButton(Button('mainWallet_Saved_Addreses_More_Confirm_Delete')) class WalletAccountView(BaseElement): diff --git a/test/ui-test/src/screens/components/confirmation_popup.py b/test/ui-test/src/screens/components/confirmation_popup.py index 6cb0b76f67..8364d623c6 100644 --- a/test/ui-test/src/screens/components/confirmation_popup.py +++ b/test/ui-test/src/screens/components/confirmation_popup.py @@ -10,3 +10,7 @@ class ConfirmationPopup(BaseElement): def confirm(self): self._confirm_button.click() self.wait_until_hidden() + + def confirmWithButton(self, button): + button.click() + self.wait_until_hidden() diff --git a/test/ui-test/testSuites/global_shared/scripts/settings_names.py b/test/ui-test/testSuites/global_shared/scripts/settings_names.py index b79464ebd6..ba4ce2404e 100644 --- a/test/ui-test/testSuites/global_shared/scripts/settings_names.py +++ b/test/ui-test/testSuites/global_shared/scripts/settings_names.py @@ -90,7 +90,7 @@ edit_TextEdit = {"container": statusDesktop_mainWindow_overlay, "type": "TextEdi # Wallet Settings: mainWallet_Saved_Addreses_More_Edit = {"container": statusDesktop_mainWindow, "objectName": "editSavedAddress", "type": "StatusMenuItem"} mainWallet_Saved_Addreses_More_Delete = {"container": statusDesktop_mainWindow, "objectName": "deleteSavedAddress", "type": "StatusMenuItem"} -mainWallet_Saved_Addreses_More_Confirm_Delete = {"container": statusDesktop_mainWindow, "objectName": "confirmDeleteSavedAddress", "type": "StatusButton"} +mainWallet_Saved_Addreses_More_Confirm_Delete = {"container": statusDesktop_mainWindow, "objectName": "RemoveAccountPopup-ConfirmButton", "type": "StatusButton"} settings_Wallet_MainView_GeneratedAccounts = {"container": statusDesktop_mainWindow, "objectName": 'generatedAccounts', "type": 'Repeater'} settings_Wallet_AccountView_DeleteAccount = {"container": statusDesktop_mainWindow, "type": "StatusButton", "objectName": "deleteAccountButton"} settings_Wallet_AccountView_DeleteAccount_Confirm = {"container": statusDesktop_mainWindow, "type": "StatusButton", "objectName": "confirmDeleteAccountButton"} diff --git a/test/ui-test/testSuites/global_shared/scripts/wallet_names.py b/test/ui-test/testSuites/global_shared/scripts/wallet_names.py index f7c8a787e4..3dae835948 100644 --- a/test/ui-test/testSuites/global_shared/scripts/wallet_names.py +++ b/test/ui-test/testSuites/global_shared/scripts/wallet_names.py @@ -29,6 +29,7 @@ send_StatusRoundButton = {"container": "", "type": "StatusRoundButton", "unnamed savedAddressView_Delegate_menuButton = {"container": "", "objectName": RegularExpression("savedAddressView_Delegate_menuButton*"), "type": "StatusRoundButton", "visible": True} mainWallet_Saved_Addreses_More_Edit = {"container": statusDesktop_mainWindow, "objectName": "editSavedAddress", "type": "StatusMenuItem"} mainWallet_Saved_Addreses_More_Delete = {"container": statusDesktop_mainWindow, "objectName": "deleteSavedAddress", "type": "StatusMenuItem"} +mainWallet_Saved_Addreses_More_Confirm_Delete = {"container": statusDesktop_mainWindow, "objectName": "RemoveSavedAddressPopup-ConfirmButton", "type": "StatusButton"} # Wallet Account View mainWindow_StatusSectionLayout_ContentItem = {"container": statusDesktop_mainWindow, "objectName": "StatusSectionLayout", "type": "ContentItem", "visible": True} diff --git a/ui/app/AppLayouts/Wallet/controls/SavedAddressesDelegate.qml b/ui/app/AppLayouts/Wallet/controls/SavedAddressesDelegate.qml index 29b42d931f..d632d1e6b8 100644 --- a/ui/app/AppLayouts/Wallet/controls/SavedAddressesDelegate.qml +++ b/ui/app/AppLayouts/Wallet/controls/SavedAddressesDelegate.qml @@ -86,7 +86,7 @@ StatusListItem { radius: 8 icon.name: "more" onClicked: { - editDeleteMenu.openMenu(this, x - editDeleteMenu.width - statusListItemComponentsSlot.spacing, y + height + Style.current.halfPadding, + menu.openMenu(this, x - menu.width - statusListItemComponentsSlot.spacing, y + height + Style.current.halfPadding, { name: root.name, address: root.address, @@ -102,12 +102,12 @@ StatusListItem { ] StatusMenu { - id: editDeleteMenu - property string contactName - property string contactAddress + id: menu + property string name + property string address property bool storeFavourite - property string contactChainShortNames - property string contactEns + property string chainShortNames + property string ens property string colorId readonly property int maxHeight: 341 @@ -115,20 +115,21 @@ StatusListItem { contentWidth: 216 function openMenu(parent, x, y, model) { - contactName = model.name; - contactAddress = model.address; - storeFavourite = model.favourite; - contactChainShortNames = model.chainShortNames; - contactEns = model.ens; - colorId = model.colorId; + menu.name = model.name; + menu.address = model.address; + menu.storeFavourite = model.favourite; + menu.chainShortNames = model.chainShortNames; + menu.ens = model.ens; + menu.colorId = model.colorId; popup(parent, x, y); } onClosed: { - contactName = ""; - contactAddress = ""; - storeFavourite = false; - contactChainShortNames = "" - contactEns = "" + menu.name = ""; + menu.address = ""; + menu.storeFavourite = false; + menu.chainShortNames = "" + menu.ens = "" + menu.colorId = "" } StatusAction { text: qsTr("Edit saved address") @@ -137,12 +138,12 @@ StatusListItem { onTriggered: { Global.openAddEditSavedAddressesPopup({ edit: true, - address: editDeleteMenu.contactAddress, - name: editDeleteMenu.contactName, - favourite: editDeleteMenu.storeFavourite, - chainShortNames: editDeleteMenu.contactChainShortNames, - ens: editDeleteMenu.contactEns, - colorId: editDeleteMenu.colorId + address: menu.address, + name: menu.name, + favourite: menu.storeFavourite, + chainShortNames: menu.chainShortNames, + ens: menu.ens, + colorId: menu.colorId }) } } @@ -216,10 +217,11 @@ StatusListItem { objectName: "deleteSavedAddress" onTriggered: { Global.openDeleteSavedAddressesPopup({ - name: editDeleteMenu.contactName, - address: editDeleteMenu.contactAddress, - favourite: editDeleteMenu.storeFavourite, - ens: editDeleteMenu.contactEns + name: menu.name, + address: menu.address, + ens: menu.ens, + colorId: menu.colorId, + chainShortNames: menu.chainShortNames }) } } diff --git a/ui/app/AppLayouts/Wallet/popups/RemoveSavedAddressPopup.qml b/ui/app/AppLayouts/Wallet/popups/RemoveSavedAddressPopup.qml new file mode 100644 index 0000000000..276beae4d2 --- /dev/null +++ b/ui/app/AppLayouts/Wallet/popups/RemoveSavedAddressPopup.qml @@ -0,0 +1,109 @@ +import QtQuick 2.15 +import QtQuick.Controls 2.15 +import QtQml.Models 2.15 +import QtQuick.Layouts 1.15 + +import StatusQ.Core 0.1 +import StatusQ.Components 0.1 +import StatusQ.Core.Theme 0.1 +import StatusQ.Core.Utils 0.1 as StatusQUtils +import StatusQ.Controls 0.1 +import StatusQ.Popups.Dialog 0.1 + +import AppLayouts.Wallet 1.0 + +import utils 1.0 +import shared.controls 1.0 + +StatusDialog { + id: root + + property string name + property string address + property string ens + property string colorId + property string chainShortNames + + signal removeSavedAddress(string address, string ens) + + width: 521 + focus: visible + padding: Style.current.padding + + QtObject { + id: d + + readonly property real lineHeight: 1.2 + + function confirm() { + root.removeSavedAddress(root.address, root.ens) + } + } + + header: StatusDialogHeader { + headline.title: qsTr("Remove %1").arg(root.name) + headline.subtitle: { + if (root.ens.length > 0) + return root.ens + + return WalletUtils.colorizedChainPrefix(root.chainShortNames) + Utils.richColorText(StatusQUtils.Utils.elideText(root.address, 6, 4), Theme.palette.directColor1) + } + actions.closeButton.onClicked: root.close() + + leftComponent: StatusSmartIdenticon { + name: root.name + asset { + color: Utils.getColorForId(root.colorId) + charactersLen: { + let parts = root.name.split(" ") + if (parts.length > 1) { + return 2 + } + return 1 + } + isLetterIdenticon: true + useAcronymForLetterIdenticon: true + } + } + } + + contentItem: ColumnLayout { + spacing: Style.current.halfPadding + + StatusBaseText { + objectName: "RemoveSavedAddressPopup-Notification" + Layout.preferredWidth: parent.width + wrapMode: Text.WordWrap + textFormat: Text.RichText + font.pixelSize: Style.current.primaryTextFontSize + lineHeight: d.lineHeight + text: qsTr("Are you sure you want to remove %1 from your saved addresses? Transaction history relating to this address will no longer be labelled %1.").arg("%1".arg(root.name)) + } + } + + footer: StatusDialogFooter { + spacing: Style.current.padding + rightButtons: ObjectModel { + StatusFlatButton { + objectName: "RemoveSavedAddressPopup-CancelButton" + text: qsTr("Cancel") + type: StatusBaseButton.Type.Normal + onClicked: { + root.close() + } + } + StatusButton { + objectName: "RemoveSavedAddressPopup-ConfirmButton" + text: qsTr("Remove saved address") + type: StatusBaseButton.Type.Danger + focus: true + Keys.onReturnPressed: function(event) { + d.confirm() + } + onClicked: { + d.confirm() + } + } + } + } +} diff --git a/ui/app/AppLayouts/Wallet/popups/qmldir b/ui/app/AppLayouts/Wallet/popups/qmldir index 4ad982cb22..0f37c03e24 100644 --- a/ui/app/AppLayouts/Wallet/popups/qmldir +++ b/ui/app/AppLayouts/Wallet/popups/qmldir @@ -4,3 +4,4 @@ ActivityPeriodFilterSubMenu 1.0 filterSubMenus/ActivityPeriodFilterSubMenu.qml ActivityTypeFilterSubMenu 1.0 filterSubMenus/ActivityTypeFilterSubMenu.qml ReceiveModal 1.0 ReceiveModal.qml AddEditSavedAddressPopup 1.0 AddEditSavedAddressPopup.qml +RemoveSavedAddressPopup 1.0 RemoveSavedAddressPopup.qml diff --git a/ui/app/mainui/AppMain.qml b/ui/app/mainui/AppMain.qml index 1e442596b6..2af9128233 100644 --- a/ui/app/mainui/AppMain.qml +++ b/ui/app/mainui/AppMain.qml @@ -1725,7 +1725,7 @@ Item { mode = qsTr("editing") } - Global.displayToastMessage(qsTr("An error occurred while %1 %2 addresses").arg(mode).arg(name), + Global.displayToastMessage(qsTr("An error occurred while %1 %2 address").arg(mode).arg(name), "", "warning", false, @@ -1771,63 +1771,49 @@ Item { deleteSavedAddress.item.address = deleteSavedAddress.params.address?? "" deleteSavedAddress.item.ens = deleteSavedAddress.params.ens?? "" deleteSavedAddress.item.name = deleteSavedAddress.params.name?? "" - deleteSavedAddress.item.favourite = deleteSavedAddress.params.favourite?? false + deleteSavedAddress.item.colorId = deleteSavedAddress.params.colorId?? "blue" + deleteSavedAddress.item.chainShortNames = deleteSavedAddress.params.chainShortNames?? "" deleteSavedAddress.item.open() } - sourceComponent: StatusModal { - - property string address - property string ens - property string name - property bool favourite - - closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside - headerSettings.title: qsTr("Are you sure?") - headerSettings.subTitle: name - - - contentItem: StatusBaseText { - anchors.centerIn: parent - height: contentHeight + topPadding + bottomPadding - text: qsTr("Are you sure you want to remove '%1' from your saved addresses?").arg(name) - font.pixelSize: 15 - color: Theme.palette.directColor1 - wrapMode: Text.Wrap - topPadding: Style.current.padding - rightPadding: Style.current.padding - bottomPadding: Style.current.padding - leftPadding: Style.current.padding - } - + sourceComponent: WalletPopups.RemoveSavedAddressPopup { onClosed: { deleteSavedAddress.close() } - rightButtons: [ - StatusButton { - text: qsTr("Cancel") - onClicked: close() - }, - StatusButton { - type: StatusBaseButton.Type.Danger - objectName: "confirmDeleteSavedAddress" - text: qsTr("Delete") - onClicked: { - WalletStore.RootStore.deleteSavedAddress(address, ens) - close() - } - } - ] + onRemoveSavedAddress: { + WalletStore.RootStore.deleteSavedAddress(address, ens) + close() + } } Connections { target: WalletStore.RootStore.walletSectionSavedAddressesInst - function onSavedAddressDeleted(address: string, ens: string, errorMsg: string) { + function onSavedAddressDeleted(name: string, address: string, ens: string, errorMsg: string) { WalletStore.RootStore.deletingSavedAddress = false WalletStore.RootStore.lastDeletedSavedAddress = { address: address, ens: ens, error: errorMsg } + + if (!!errorMsg) { + + Global.displayToastMessage(qsTr("An error occurred while removing %1 address").arg(name), + "", + "warning", + false, + Constants.ephemeralNotificationType.danger, + "" + ) + return + } + + Global.displayToastMessage(qsTr("%1 was successfully removed from your saved addresses").arg(name), + "", + "checkmark-circle", + false, + Constants.ephemeralNotificationType.success, + "" + ) } } }