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 } ]