From 27aaa97ebd636ea8cb02e6c969c1a4bd0cce319a Mon Sep 17 00:00:00 2001 From: Khushboo Mehta Date: Wed, 31 Jul 2024 15:02:10 +0200 Subject: [PATCH] fix(@desktop/wallet): fix for Swap Input parameters reset when balances are reloaded fixes #15785 --- .../qmlTests/tests/tst_SwapInputPanel.qml | 35 +++++++++++++++++++ storybook/qmlTests/tests/tst_SwapModal.qml | 1 + .../adaptors/TokenSelectorViewAdaptor.qml | 1 + .../Wallet/panels/SwapInputPanel.qml | 11 ------ 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/storybook/qmlTests/tests/tst_SwapInputPanel.qml b/storybook/qmlTests/tests/tst_SwapInputPanel.qml index 9d8eff6d1d..71dc64cdf0 100644 --- a/storybook/qmlTests/tests/tst_SwapInputPanel.qml +++ b/storybook/qmlTests/tests/tst_SwapInputPanel.qml @@ -479,5 +479,40 @@ Item { compare(controlUnderTest.selectedHoldingId, tokenKeyToTest) compare(controlUnderTest.amountEnteredGreaterThanBalance, false) } + + function test_if_values_not_reset_on_modelReset() { + const tokenKeyToTest = "ETH" + let numberTestedString = "1.0001" + let modelItemToTest = ModelUtils.getByKey(d.tokenSelectorAdaptor.outputAssetsModel, "tokensKey", tokenKeyToTest) + controlUnderTest = createTemporaryObject(componentUnderTest, root, { + swapSide: SwapInputPanel.SwapSide.Pay, + tokenKey: tokenKeyToTest, + tokenAmount: numberTestedString + }) + verify(!!controlUnderTest) + waitForRendering(controlUnderTest) + + + const amountToSendInput = findChild(controlUnderTest, "amountToSendInput") + verify(!!amountToSendInput) + + let numberTested = LocaleUtils.numberFromLocaleString(numberTestedString, amountToSendInput.input.locale) + + compare(amountToSendInput.input.text, numberTestedString) + compare(controlUnderTest.value, numberTested) + compare(controlUnderTest.rawValue, AmountsArithmetic.fromNumber(amountToSendInput.input.text, modelItemToTest.decimals).toString()) + compare(controlUnderTest.valueValid, true) + compare(controlUnderTest.selectedHoldingId, tokenKeyToTest) + compare(controlUnderTest.amountEnteredGreaterThanBalance, false) + + d.tokenSelectorAdaptor.assetsModel.modelReset() + + compare(amountToSendInput.input.text, numberTestedString) + compare(controlUnderTest.value, numberTested) + compare(controlUnderTest.rawValue, AmountsArithmetic.fromNumber(amountToSendInput.input.text, modelItemToTest.decimals).toString()) + compare(controlUnderTest.valueValid, true) + compare(controlUnderTest.selectedHoldingId, tokenKeyToTest) + compare(controlUnderTest.amountEnteredGreaterThanBalance, false) + } } } diff --git a/storybook/qmlTests/tests/tst_SwapModal.qml b/storybook/qmlTests/tests/tst_SwapModal.qml index aa2ddb0978..6fdfd4beb5 100644 --- a/storybook/qmlTests/tests/tst_SwapModal.qml +++ b/storybook/qmlTests/tests/tst_SwapModal.qml @@ -1064,6 +1064,7 @@ Item { const receivePanel = findChild(controlUnderTest, "receivePanel") verify(!!receivePanel) + waitForRendering(receivePanel) const amountToSendInput = findChild(receivePanel, "amountToSendInput") verify(!!amountToSendInput) const bottomItemText = findChild(receivePanel, "bottomItemText") diff --git a/ui/app/AppLayouts/Wallet/adaptors/TokenSelectorViewAdaptor.qml b/ui/app/AppLayouts/Wallet/adaptors/TokenSelectorViewAdaptor.qml index 644513833d..ac8033ee8b 100644 --- a/ui/app/AppLayouts/Wallet/adaptors/TokenSelectorViewAdaptor.qml +++ b/ui/app/AppLayouts/Wallet/adaptors/TokenSelectorViewAdaptor.qml @@ -188,6 +188,7 @@ QObject { ConcatModel { id: concatModel + propagateResets: true sources: [ SourceModel { model: renamedTokensBySymbolModel diff --git a/ui/app/AppLayouts/Wallet/panels/SwapInputPanel.qml b/ui/app/AppLayouts/Wallet/panels/SwapInputPanel.qml index 84a35fee14..ad9dbdbe75 100644 --- a/ui/app/AppLayouts/Wallet/panels/SwapInputPanel.qml +++ b/ui/app/AppLayouts/Wallet/panels/SwapInputPanel.qml @@ -122,17 +122,6 @@ Control { } } - /* TODO: remove after https://github.com/status-im/status-desktop/issues/15604 is - implemented as this is hack to set token values correctly when model is reset */ - Connections { - target: holdingSelector.model - function onRowsInserted() { - if(!!tokenKey) { - root.reevaluateSelectedId() - } - } - } - background: Shape { id: shape