chores(@desktop/chat): add guard when buying stickers

Call the same function as to when we do a transaction to validate
the argument
This commit is contained in:
Anthony Laibe 2021-07-27 16:45:59 +02:00 committed by Iuri Matias
parent cd8b539dc6
commit 20b1bed309
2 changed files with 8 additions and 0 deletions

View File

@ -113,8 +113,15 @@ QtObject:
self.gasEstimateReturned(estimateResult.estimate, estimateResult.uuid)
proc buy*(self: StickersView, packId: int, address: string, price: string, gas: string, gasPrice: string, password: string): string {.slot.} =
try:
validateTransactionInput(address, address, "", price, gas, gasPrice, "", "ok")
except Exception as e:
error "Error buying sticker pack", msg = e.msg
return ""
var success: bool
let response = self.status.stickers.buyPack(packId, address, price, gas, gasPrice, password, success)
# TODO:
# check if response["error"] is not null and handle the error
result = $(%* { "result": %response, "success": %success })

View File

@ -145,6 +145,7 @@ proc validateTransactionInput*(from_addr, to_addr, assetAddress, value, gas, gas
if parseFloat(value) < 0: raise newException(ValueError, "value should be a number >= 0")
if parseInt(gas) <= 0: raise newException(ValueError, "gas should be a number > 0")
if parseFloat(gasPrice) <= 0: raise newException(ValueError, "gasPrice should be a number > 0")
if uuid.isEmptyOrWhitespace(): raise newException(ValueError, "uuid is required")
if assetAddress != "": # If a token is being used