diff --git a/storybook/qmlTests/tests/tst_SwapModal.qml b/storybook/qmlTests/tests/tst_SwapModal.qml index de7489ba27..170da96806 100644 --- a/storybook/qmlTests/tests/tst_SwapModal.qml +++ b/storybook/qmlTests/tests/tst_SwapModal.qml @@ -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) + } + } } } diff --git a/ui/app/AppLayouts/Wallet/panels/SwapInputPanel.qml b/ui/app/AppLayouts/Wallet/panels/SwapInputPanel.qml index d2043f6b91..926cdee4db 100644 --- a/ui/app/AppLayouts/Wallet/panels/SwapInputPanel.qml +++ b/ui/app/AppLayouts/Wallet/panels/SwapInputPanel.qml @@ -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 } }