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 = 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.} = method savedAddressDeleted*(self: AccessInterface, address: string, errorMsg: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method isChecksumValidForAddress*(self: AccessInterface, address: string): bool {.base.} =
raise newException(ValueError, "No implementation available")
type type
DelegateInterface* = concept c DelegateInterface* = concept c
c.onAddAccountModuleLoaded() c.onAddAccountModuleLoaded()

View File

@ -736,4 +736,7 @@ method buildNewSeedPhraseKeypairAndAddItToOrigin*[T](self: Module[T]) =
derivedFrom = genAcc.address) derivedFrom = genAcc.address)
self.setItemForSelectedOrigin(item) self.setItemForSelectedOrigin(item)
method isChecksumValidForAddress*[T](self: Module[T], address: string): bool =
return self.controller.isChecksumValidForAddress(address)
{.pop.} {.pop.}

View File

@ -363,3 +363,6 @@ QtObject:
proc removingSavedAddressRejected*(self: View) {.slot.} = 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() addressInput.reset()
} }
QtObject {
id: d
property bool incorrectChecksum: false
function checkIfAddressChecksumIsValid(address) {
d.incorrectChecksum = !root.store.isChecksumValidForAddress(address)
}
}
StatusInput { StatusInput {
id: addressInput id: addressInput
objectName: "AddAccountPopup-WatchOnlyAddress" objectName: "AddAccountPopup-WatchOnlyAddress"
@ -29,7 +39,19 @@ Column {
label: qsTr("Ethereum address or ENS name") label: qsTr("Ethereum address or ENS name")
placeholderText: qsTr("Type or paste ETH address") placeholderText: qsTr("Type or paste ETH address")
input.multiline: true 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 anchors.verticalCenter: parent.verticalCenter
borderColor: Theme.palette.primaryColor1 borderColor: Theme.palette.primaryColor1
size: StatusBaseButton.Size.Tiny size: StatusBaseButton.Size.Tiny
@ -39,6 +61,7 @@ Column {
addressInput.input.edit.paste() addressInput.input.edit.paste()
} }
} }
}
validators: [ validators: [
StatusAddressOrEnsValidator { StatusAddressOrEnsValidator {
errorMessage: qsTr("Please enter a valid Ethereum address or ENS name") errorMessage: qsTr("Please enter a valid Ethereum address or ENS name")
@ -46,8 +69,11 @@ Column {
] ]
onTextChanged: { onTextChanged: {
d.incorrectChecksum = false
if (addressInput.valid) { if (addressInput.valid) {
root.store.changeWatchOnlyAccountAddressPostponed(text.trim()) const trimmedText = text.trim()
root.store.changeWatchOnlyAccountAddressPostponed(trimmedText)
d.checkIfAddressChecksumIsValid(trimmedText)
return return
} }
root.store.cleanWatchOnlyAccountAddress() root.store.cleanWatchOnlyAccountAddress()

View File

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