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
This commit is contained in:
Lukáš Tinkl 2024-07-02 01:45:44 +02:00 committed by Lukáš Tinkl
parent a18056c7d1
commit 464af7a04d
3 changed files with 42 additions and 0 deletions

View File

@ -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 {

View File

@ -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)
}
}
}

View File

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