From 464af7a04d1d51d3fcb622918b002cb7672a3efe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Tinkl?= Date: Tue, 2 Jul 2024 01:45:44 +0200 Subject: [PATCH] fix(TokenSelector): Duplicate plain token entries - filter out plain tokens from the adaptor's if already present in the output model - add a corresponding regression test Fixes #15412 --- storybook/pages/TokenSelectorPage.qml | 8 ++++++++ .../tests/tst_TokenSelectorViewAdaptor.qml | 19 +++++++++++++++++++ .../adaptors/TokenSelectorViewAdaptor.qml | 15 +++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/storybook/pages/TokenSelectorPage.qml b/storybook/pages/TokenSelectorPage.qml index 8b3f262c3b..58299262e5 100644 --- a/storybook/pages/TokenSelectorPage.qml +++ b/storybook/pages/TokenSelectorPage.qml @@ -46,6 +46,14 @@ SplitView { image: "https://etherscan.io/token/images/horizonstate2_28.png" communityId: "" } + // DAI should be filtered out + ListElement { + key: "DAI" + name: "Dai Stablecoin" + symbol: "DAI" + image: "" + communityId: "" + } } QtObject { diff --git a/storybook/qmlTests/tests/tst_TokenSelectorViewAdaptor.qml b/storybook/qmlTests/tests/tst_TokenSelectorViewAdaptor.qml index e155d4ac91..d53b8b7496 100644 --- a/storybook/qmlTests/tests/tst_TokenSelectorViewAdaptor.qml +++ b/storybook/qmlTests/tests/tst_TokenSelectorViewAdaptor.qml @@ -22,6 +22,14 @@ Item { image: "https://cryptologos.cc/logos/aave-aave-logo.png" communityId: "" } + // DAI should be filtered out + ListElement { + key: "DAI" + name: "Dai Stablecoin" + symbol: "DAI" + image: "" + communityId: "" + } } QtObject { @@ -133,5 +141,16 @@ Item { // should have ~45.90 balance fuzzyCompare(delegate.currencyBalance, 45.90, 0.01) } + + function test_duplicatePlainTokens() { + verify(!!controlUnderTest) + + controlUnderTest.showAllTokens = true + const searchText = "DAI" + controlUnderTest.searchString = searchText + + // search yields 1 result + tryCompare(controlUnderTest.outputAssetsModel, "count", 1) + } } } diff --git a/ui/app/AppLayouts/Wallet/adaptors/TokenSelectorViewAdaptor.qml b/ui/app/AppLayouts/Wallet/adaptors/TokenSelectorViewAdaptor.qml index 9d8ef5d8dd..405385eb72 100644 --- a/ui/app/AppLayouts/Wallet/adaptors/TokenSelectorViewAdaptor.qml +++ b/ui/app/AppLayouts/Wallet/adaptors/TokenSelectorViewAdaptor.qml @@ -106,6 +106,21 @@ QObject { roleName: "communityId" value: "" enabled: !root.showCommunityAssets + }, + // duplicate tokens filter + FastExpressionFilter { + function hasDuplicateKey(tokensKey) { + return ModelUtils.indexOf(assetsObjectProxyModel, "tokensKey", tokensKey) > -1 + } + + expression: { + if (model.which_model === "plain_tokens_model") { + return !hasDuplicateKey(model.tokensKey) + } + return true + } + expectedRoles: ["which_model", "tokensKey"] + enabled: root.showAllTokens } ]