fix(@desktop/wallet): Fixing issue in deleting characters from Input area

fixes #15418
This commit is contained in:
Khushboo Mehta 2024-07-11 14:55:04 +02:00 committed by Khushboo-dev-cpp
parent 758bba1ac0
commit 7caba84833
2 changed files with 40 additions and 1 deletions

View File

@ -1586,5 +1586,38 @@ Item {
// check if fetch occurs automatically after 15 seconds
fetchSuggestedRoutesCalled.wait()
}
function test_deleteing_input_characters_data() {
return [
{input: "0.001"},
{input: "1.00015"},
/* TODO uncomment after https://discord.com/channels/@me/927512790296563712/1260937239140241408
{input: "100.000000000000151001"},
{input: "1.0200000000000151001"} */
]
}
function test_deleteing_input_characters(data) {
root.swapFormData.fromTokenAmount = data.input
root.swapFormData.selectedAccountAddress = "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240"
root.swapFormData.selectedNetworkChainId = 11155111
root.swapFormData.fromTokensKey = "ETH"
const amountToSendInput = findChild(controlUnderTest, "amountToSendInput")
verify(!!amountToSendInput)
// Launch popup
launchAndVerfyModal()
waitForRendering(amountToSendInput)
//TODO: should not be needed after https://github.com/status-im/status-desktop/issues/15417
amountToSendInput.input.input.cursorPosition = data.input.length
for(let i =0; i< data.input.length; i++) {
keyClick(Qt.Key_Backspace)
let expectedAmount = data.input.substring(0, data.input.length - (i+1))
compare(amountToSendInput.input.text, expectedAmount)
}
}
}
}

View File

@ -113,7 +113,13 @@ Control {
return
}
let amountToSet = SQUtils.AmountsArithmetic.fromString(tokenAmount).toFixed().replace('.', LocaleUtils.userInputLocale.decimalPoint)
if (amountToSendInput.input.text !== amountToSet) {
/* When deleting characters after a decimal point
eg: 0.000001 being deleted we have 0.00000 and it should not be updated to 0
and thats why we compare with toFixed()
also when deleting a numbers last digit, we should not update the text to 0
instead it should remain empty as entered by the user*/
if (SQUtils.AmountsArithmetic.fromString(amountToSendInput.input.text).toFixed() !== amountToSet &&
!(amountToSet === "0" && !amountToSendInput.input.text)) {
amountToSendInput.input.text = amountToSet
}
}