From fdd743a817fc9902efe82e7ada0549423a3f3629 Mon Sep 17 00:00:00 2001 From: Sale Djenic Date: Tue, 30 Jul 2024 15:01:16 +0200 Subject: [PATCH] feat: checksum validation added to adding watch only address Fixes: #15779 --- .../shared_modules/add_account/controller.nim | 5 ++- .../add_account/io_interface.nim | 3 ++ .../shared_modules/add_account/module.nim | 3 ++ .../shared_modules/add_account/view.nim | 5 ++- .../panels/WatchOnlyAddressSection.qml | 44 +++++++++++++++---- .../addaccount/stores/AddAccountStore.qml | 4 ++ 6 files changed, 53 insertions(+), 11 deletions(-) diff --git a/src/app/modules/shared_modules/add_account/controller.nim b/src/app/modules/shared_modules/add_account/controller.nim index d15557891d..14747214fc 100644 --- a/src/app/modules/shared_modules/add_account/controller.nim +++ b/src/app/modules/shared_modules/add_account/controller.nim @@ -250,4 +250,7 @@ proc getNumOfAddressesToGenerateForKeypair*(self: Controller, keyUid: string): i return self.walletAccountService.getNumOfAddressesToGenerateForKeypair(keyUid) proc resolveSuggestedPathForKeypair*(self: Controller, keyUid: string): string = - return self.walletAccountService.resolveSuggestedPathForKeypair(keyUid) \ No newline at end of file + return self.walletAccountService.resolveSuggestedPathForKeypair(keyUid) + +proc isChecksumValidForAddress*(self: Controller, address: string): bool = + return self.walletAccountService.isChecksumValidForAddress(address) \ No newline at end of file diff --git a/src/app/modules/shared_modules/add_account/io_interface.nim b/src/app/modules/shared_modules/add_account/io_interface.nim index 1dc55332de..15c6352af0 100644 --- a/src/app/modules/shared_modules/add_account/io_interface.nim +++ b/src/app/modules/shared_modules/add_account/io_interface.nim @@ -107,6 +107,9 @@ method removingSavedAddressConfirmed*(self: AccessInterface, address: string) {. method savedAddressDeleted*(self: AccessInterface, address: string, errorMsg: string) {.base.} = raise newException(ValueError, "No implementation available") +method isChecksumValidForAddress*(self: AccessInterface, address: string): bool {.base.} = + raise newException(ValueError, "No implementation available") + type DelegateInterface* = concept c c.onAddAccountModuleLoaded() diff --git a/src/app/modules/shared_modules/add_account/module.nim b/src/app/modules/shared_modules/add_account/module.nim index c951d60486..d9b9f9c066 100644 --- a/src/app/modules/shared_modules/add_account/module.nim +++ b/src/app/modules/shared_modules/add_account/module.nim @@ -736,4 +736,7 @@ method buildNewSeedPhraseKeypairAndAddItToOrigin*[T](self: Module[T]) = derivedFrom = genAcc.address) self.setItemForSelectedOrigin(item) +method isChecksumValidForAddress*[T](self: Module[T], address: string): bool = + return self.controller.isChecksumValidForAddress(address) + {.pop.} diff --git a/src/app/modules/shared_modules/add_account/view.nim b/src/app/modules/shared_modules/add_account/view.nim index 485013c2f7..3ccdb39f72 100644 --- a/src/app/modules/shared_modules/add_account/view.nim +++ b/src/app/modules/shared_modules/add_account/view.nim @@ -362,4 +362,7 @@ QtObject: self.delegate.removingSavedAddressConfirmed(address) proc removingSavedAddressRejected*(self: View) {.slot.} = - self.setDisablePopup(false) \ No newline at end of file + self.setDisablePopup(false) + + proc isChecksumValidForAddress*(self: View, address: string): bool {.slot.} = + return self.delegate.isChecksumValidForAddress(address) \ No newline at end of file diff --git a/ui/imports/shared/popups/addaccount/panels/WatchOnlyAddressSection.qml b/ui/imports/shared/popups/addaccount/panels/WatchOnlyAddressSection.qml index bbb9a898e5..2d1d01c22d 100644 --- a/ui/imports/shared/popups/addaccount/panels/WatchOnlyAddressSection.qml +++ b/ui/imports/shared/popups/addaccount/panels/WatchOnlyAddressSection.qml @@ -20,6 +20,16 @@ Column { addressInput.reset() } + QtObject { + id: d + + property bool incorrectChecksum: false + + function checkIfAddressChecksumIsValid(address) { + d.incorrectChecksum = !root.store.isChecksumValidForAddress(address) + } + } + StatusInput { id: addressInput objectName: "AddAccountPopup-WatchOnlyAddress" @@ -29,14 +39,27 @@ Column { label: qsTr("Ethereum address or ENS name") placeholderText: qsTr("Type or paste ETH address") input.multiline: true - input.rightComponent: StatusButton { - anchors.verticalCenter: parent.verticalCenter - borderColor: Theme.palette.primaryColor1 - size: StatusBaseButton.Size.Tiny - text: qsTr("Paste") - onClicked: { - addressInput.text = "" - addressInput.input.edit.paste() + input.rightComponent: Row { + spacing: 8 + + StatusIconWithTooltip { + visible: d.incorrectChecksum + icon: "warning" + width: 20 + height: 20 + color: Theme.palette.warningColor1 + tooltipText: qsTr("Checksum of the entered address is incorrect") + } + + StatusButton { + anchors.verticalCenter: parent.verticalCenter + borderColor: Theme.palette.primaryColor1 + size: StatusBaseButton.Size.Tiny + text: qsTr("Paste") + onClicked: { + addressInput.text = "" + addressInput.input.edit.paste() + } } } validators: [ @@ -46,8 +69,11 @@ Column { ] onTextChanged: { + d.incorrectChecksum = false if (addressInput.valid) { - root.store.changeWatchOnlyAccountAddressPostponed(text.trim()) + const trimmedText = text.trim() + root.store.changeWatchOnlyAccountAddressPostponed(trimmedText) + d.checkIfAddressChecksumIsValid(trimmedText) return } root.store.cleanWatchOnlyAccountAddress() diff --git a/ui/imports/shared/popups/addaccount/stores/AddAccountStore.qml b/ui/imports/shared/popups/addaccount/stores/AddAccountStore.qml index b5bdb18883..aef4f09dfd 100644 --- a/ui/imports/shared/popups/addaccount/stores/AddAccountStore.qml +++ b/ui/imports/shared/popups/addaccount/stores/AddAccountStore.qml @@ -155,6 +155,10 @@ BasePopupStore { root.addAccountModule.startScanningForActivity() } + function isChecksumValidForAddress(address) { + return root.addAccountModule.isChecksumValidForAddress(address) + } + validSeedPhrase: function(seedPhrase) { return root.addAccountModule.validSeedPhrase(seedPhrase) }