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

@ -251,3 +251,6 @@ proc getNumOfAddressesToGenerateForKeypair*(self: Controller, keyUid: string): i
proc resolveSuggestedPathForKeypair*(self: Controller, keyUid: string): string =
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

@ -363,3 +363,6 @@ QtObject:
proc removingSavedAddressRejected*(self: View) {.slot.} =
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,7 +39,19 @@ Column {
label: qsTr("Ethereum address or ENS name")
placeholderText: qsTr("Type or paste ETH address")
input.multiline: true
input.rightComponent: StatusButton {
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
@ -39,6 +61,7 @@ Column {
addressInput.input.edit.paste()
}
}
}
validators: [
StatusAddressOrEnsValidator {
errorMessage: qsTr("Please enter a valid Ethereum address or ENS name")
@ -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)
}