feat: checksum validation added to adding watch only address

Fixes: #15779
This commit is contained in:
Sale Djenic 2024-07-30 15:01:16 +02:00 committed by saledjenic
parent 822410f6b6
commit fdd743a817
6 changed files with 53 additions and 11 deletions

View File

@ -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)
return self.walletAccountService.resolveSuggestedPathForKeypair(keyUid)
proc isChecksumValidForAddress*(self: Controller, address: string): bool =
return self.walletAccountService.isChecksumValidForAddress(address)

View File

@ -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()

View File

@ -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.}

View File

@ -362,4 +362,7 @@ QtObject:
self.delegate.removingSavedAddressConfirmed(address)
proc removingSavedAddressRejected*(self: View) {.slot.} =
self.setDisablePopup(false)
self.setDisablePopup(false)
proc isChecksumValidForAddress*(self: View, address: string): bool {.slot.} =
return self.delegate.isChecksumValidForAddress(address)

View File

@ -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()

View File

@ -155,6 +155,10 @@ BasePopupStore {
root.addAccountModule.startScanningForActivity()
}
function isChecksumValidForAddress(address) {
return root.addAccountModule.isChecksumValidForAddress(address)
}
validSeedPhrase: function(seedPhrase) {
return root.addAccountModule.validSeedPhrase(seedPhrase)
}