Token/Asset selectors fixes

- clear search on close (AssetSelectorCompact)
- sectionProperty removed
- highlighting fixed in TokenSelectorPanel
- setCustom renamed to setSelection
- test data moved into Component object
This commit is contained in:
Michał Cieślak 2024-09-23 10:15:01 +02:00 committed by Michał
parent 249e1ae042
commit 00fe754c0d
13 changed files with 172 additions and 167 deletions

View File

@ -23,7 +23,7 @@ Pane {
} }
], ],
sectionText: "My assets on Mainnet" sectionName: "My assets on Mainnet"
}, },
{ {
tokensKey: "key_2", tokensKey: "key_2",
@ -41,7 +41,7 @@ Pane {
} }
], ],
sectionText: "My assets on Mainnet" sectionName: "My assets on Mainnet"
}, },
{ {
tokensKey: "key_2", tokensKey: "key_2",
@ -53,7 +53,7 @@ Pane {
tokensKey: "DAI", tokensKey: "DAI",
balances: [], balances: [],
sectionText: "Popular assets" sectionName: "Popular assets"
}, },
{ {
tokensKey: "key_3", tokensKey: "key_3",
@ -65,7 +65,7 @@ Pane {
tokensKey: "ZRX", tokensKey: "ZRX",
balances: [], balances: [],
sectionText: "Popular assets" sectionName: "Popular assets"
} }
] ]
@ -86,7 +86,6 @@ Pane {
width: 400 width: 400
model: assetsModel model: assetsModel
sectionProperty: "sectionText"
onSelected: console.log("asset selected:", key) onSelected: console.log("asset selected:", key)
} }

View File

@ -22,7 +22,7 @@ Pane {
} }
], ],
sectionText: "My assets on Mainnet" sectionName: "My assets on Mainnet"
}, },
{ {
tokensKey: "eth_key", tokensKey: "eth_key",
@ -39,7 +39,7 @@ Pane {
} }
], ],
sectionText: "My assets on Mainnet" sectionName: "My assets on Mainnet"
}, },
{ {
tokensKey: "dai_key", tokensKey: "dai_key",
@ -50,7 +50,7 @@ Pane {
iconSource: Constants.tokenIcon("DAI"), iconSource: Constants.tokenIcon("DAI"),
balances: [], balances: [],
sectionText: "Popular assets" sectionName: "Popular assets"
}, },
{ {
tokensKey: "zrx_key", tokensKey: "zrx_key",
@ -61,7 +61,7 @@ Pane {
iconSource: Constants.tokenIcon("ZRX"), iconSource: Constants.tokenIcon("ZRX"),
balances: [], balances: [],
sectionText: "Popular assets" sectionName: "Popular assets"
} }
] ]
@ -81,7 +81,6 @@ Pane {
anchors.centerIn: parent anchors.centerIn: parent
model: assetsModel model: assetsModel
sectionProperty: "sectionText"
onSelected: console.log("asset selected:", key) onSelected: console.log("asset selected:", key)
} }

View File

@ -29,7 +29,7 @@ Pane {
} }
], ],
sectionText: "" sectionName: ""
}, },
{ {
tokensKey: "eth_key", tokensKey: "eth_key",
@ -53,7 +53,7 @@ Pane {
} }
], ],
sectionText: "" sectionName: ""
}, },
{ {
tokensKey: "dai_key", tokensKey: "dai_key",
@ -64,7 +64,7 @@ Pane {
iconSource: Constants.tokenIcon("DAI"), iconSource: Constants.tokenIcon("DAI"),
balances: [], balances: [],
sectionText: "Popular assets" sectionName: "Popular assets"
}, },
{ {
tokensKey: "zrx_key", tokensKey: "zrx_key",
@ -75,7 +75,7 @@ Pane {
iconSource: Constants.tokenIcon("ZRX"), iconSource: Constants.tokenIcon("ZRX"),
balances: [], balances: [],
sectionText: "Popular assets" sectionName: "Popular assets"
} }
] ]
@ -102,7 +102,6 @@ Pane {
highlightedKey: "key_2" highlightedKey: "key_2"
model: assetsModel model: assetsModel
sectionProperty: "sectionText"
onSelected: console.log("selected:", key) onSelected: console.log("selected:", key)
} }

View File

@ -12,6 +12,14 @@ Item {
width: 600 width: 600
height: 600 height: 600
Component {
id: selectorCmp
AssetSelector {
id: selector
anchors.centerIn: parent
readonly property var assetsData: [ readonly property var assetsData: [
{ {
tokensKey: "stt_key", tokensKey: "stt_key",
@ -28,7 +36,7 @@ Item {
} }
], ],
sectionText: "My assets on Mainnet" sectionName: "My assets on Mainnet"
}, },
{ {
tokensKey: "eth_key", tokensKey: "eth_key",
@ -45,7 +53,7 @@ Item {
} }
], ],
sectionText: "My assets on Mainnet" sectionName: "My assets on Mainnet"
}, },
{ {
tokensKey: "dai_key", tokensKey: "dai_key",
@ -56,25 +64,14 @@ Item {
iconSource: Constants.tokenIcon("DAI"), iconSource: Constants.tokenIcon("DAI"),
balances: [], balances: [],
sectionText: "Popular assets" sectionName: "Popular assets"
} }
] ]
ListModel { model: ListModel {
id: assetsModel Component.onCompleted: append(selector.assetsData)
Component.onCompleted: append(assetsData)
} }
Component {
id: selectorCmp
AssetSelector {
id: selector
anchors.centerIn: parent
model: assetsModel
readonly property SignalSpy selectedSpy: SignalSpy { readonly property SignalSpy selectedSpy: SignalSpy {
target: selector target: selector
signalName: "selected" signalName: "selected"
@ -89,8 +86,6 @@ Item {
function test_basic() { function test_basic() {
const selector = createTemporaryObject(selectorCmp, root) const selector = createTemporaryObject(selectorCmp, root)
selector.nonInteractiveKey = "eth_key" selector.nonInteractiveKey = "eth_key"
selector.sectionProperty = "sectionText"
compare(selector.isSelected, false) compare(selector.isSelected, false)
waitForRendering(selector) waitForRendering(selector)
@ -102,7 +97,6 @@ Item {
const panel = findChild(selector.Overlay.overlay, "searchableAssetsPanel") const panel = findChild(selector.Overlay.overlay, "searchableAssetsPanel")
compare(panel.model, selector.model) compare(panel.model, selector.model)
compare(panel.nonInteractiveKey, selector.nonInteractiveKey) compare(panel.nonInteractiveKey, selector.nonInteractiveKey)
compare(panel.sectionProperty, selector.sectionProperty)
} }
function test_basicSelection() { function test_basicSelection() {
@ -121,7 +115,7 @@ Item {
const listView = findChild(selector.Overlay.overlay, "assetsListView") const listView = findChild(selector.Overlay.overlay, "assetsListView")
verify(listView) verify(listView)
compare(listView.count, root.assetsData.length) compare(listView.count, selector.assetsData.length)
waitForRendering(listView) waitForRendering(listView)
const delegate1 = listView.itemAtIndex(0) const delegate1 = listView.itemAtIndex(0)
@ -196,7 +190,7 @@ Item {
waitForRendering(selector) waitForRendering(selector)
const imageUrl = Constants.tokenIcon("DAI") const imageUrl = Constants.tokenIcon("DAI")
selector.setCustom("Custom", imageUrl, "custom_key") selector.setSelection("Custom", imageUrl, "custom_key")
compare(selector.isSelected, true) compare(selector.isSelected, true)
compare(selector.selectedSpy.count, 0) compare(selector.selectedSpy.count, 0)

View File

@ -19,15 +19,6 @@ Item {
SearchableAssetsPanel { SearchableAssetsPanel {
id: panel id: panel
sectionProperty: "sectionText"
readonly property SignalSpy selectedSpy: SignalSpy {
target: panel
signalName: "selected"
}
}
}
readonly property var assetsData: [ readonly property var assetsData: [
{ {
tokensKey: "stt_key", tokensKey: "stt_key",
@ -51,7 +42,7 @@ Item {
} }
], ],
sectionText: "" sectionName: ""
}, },
{ {
tokensKey: "dai_key", tokensKey: "dai_key",
@ -62,7 +53,7 @@ Item {
iconSource: Constants.tokenIcon("DAI"), iconSource: Constants.tokenIcon("DAI"),
balances: [], balances: [],
sectionText: "Popular assets" sectionName: "Popular assets"
}, },
{ {
tokensKey: "zrx_key", tokensKey: "zrx_key",
@ -73,14 +64,19 @@ Item {
iconSource: Constants.tokenIcon("ZRX"), iconSource: Constants.tokenIcon("ZRX"),
balances: [], balances: [],
sectionText: "Popular assets" sectionName: "Popular assets"
} }
] ]
ListModel { model: ListModel {
id: model Component.onCompleted: append(panel.assetsData)
}
Component.onCompleted: append(root.assetsData) readonly property SignalSpy selectedSpy: SignalSpy {
target: panel
signalName: "selected"
}
}
} }
TestCase { TestCase {
@ -88,7 +84,7 @@ Item {
when: windowShown when: windowShown
function test_sections() { function test_sections() {
const control = createTemporaryObject(panelCmp, root, { model }) const control = createTemporaryObject(panelCmp, root)
const listView = findChild(control, "assetsListView") const listView = findChild(control, "assetsListView")
waitForRendering(listView) waitForRendering(listView)
@ -109,9 +105,36 @@ Item {
const sectionDelegate = TestUtils.findTextItem(listView, "Popular assets") const sectionDelegate = TestUtils.findTextItem(listView, "Popular assets")
verify(sectionDelegate) verify(sectionDelegate)
}
control.sectionProperty = "" function test_withNoSectionsModel() {
const model = createTemporaryQmlObject("import QtQuick 2.15; ListModel {}", root)
const control = createTemporaryObject(panelCmp, root, { model })
model.append(control.assetsData.map(
e => ({
tokensKey: e.tokensKey,
communityId: e.communityId,
name: e.name,
currencyBalanceAsString: e.currencyBalanceAsString,
symbol: e.symbol,
iconSource: e.iconSource,
balances: e.balances
})
)
)
const listView = findChild(control, "assetsListView")
waitForRendering(listView) waitForRendering(listView)
compare(listView.count, 3)
const delegate1 = listView.itemAtIndex(0)
const delegate2 = listView.itemAtIndex(1)
const delegate3 = listView.itemAtIndex(2)
verify(delegate1)
verify(delegate2)
verify(delegate3)
compare(delegate1.ListView.section, "") compare(delegate1.ListView.section, "")
compare(delegate2.ListView.section, "") compare(delegate2.ListView.section, "")
@ -119,7 +142,7 @@ Item {
} }
function test_search() { function test_search() {
const control = createTemporaryObject(panelCmp, root, { model }) const control = createTemporaryObject(panelCmp, root)
const listView = findChild(control, "assetsListView") const listView = findChild(control, "assetsListView")
waitForRendering(listView) waitForRendering(listView)
@ -154,7 +177,7 @@ Item {
} }
function test_highlightedKey() { function test_highlightedKey() {
const control = createTemporaryObject(panelCmp, root, { model }) const control = createTemporaryObject(panelCmp, root)
control.highlightedKey = "dai_key" control.highlightedKey = "dai_key"
const listView = findChild(control, "assetsListView") const listView = findChild(control, "assetsListView")
@ -176,7 +199,7 @@ Item {
} }
function test_nonInteractiveKey() { function test_nonInteractiveKey() {
const control = createTemporaryObject(panelCmp, root, { model }) const control = createTemporaryObject(panelCmp, root)
control.nonInteractiveKey = "dai_key" control.nonInteractiveKey = "dai_key"
const listView = findChild(control, "assetsListView") const listView = findChild(control, "assetsListView")

View File

@ -15,13 +15,11 @@ Control {
property alias model: searchableAssetsPanel.model property alias model: searchableAssetsPanel.model
property alias nonInteractiveKey: searchableAssetsPanel.nonInteractiveKey property alias nonInteractiveKey: searchableAssetsPanel.nonInteractiveKey
property alias sectionProperty: searchableAssetsPanel.sectionProperty
readonly property bool isSelected: button.selected readonly property bool isSelected: button.selected
signal selected(string key) signal selected(string key)
function setCustom(name: string, icon: url, key: string) { function setSelection(name: string, icon: url, key: string) {
button.name = name button.name = name
button.icon = icon button.icon = icon
button.selected = true button.selected = true

View File

@ -14,13 +14,11 @@ Control {
/** Expected model structure: see SearchableAssetsPanel::model **/ /** Expected model structure: see SearchableAssetsPanel::model **/
property alias model: searchableAssetsPanel.model property alias model: searchableAssetsPanel.model
property alias sectionProperty: searchableAssetsPanel.sectionProperty
readonly property bool isSelected: button.selected readonly property bool isSelected: button.selected
signal selected(string key) signal selected(string key)
function setCustom(name: string, symbol: string, icon: url, key: string) { function setSelection(name: string, symbol: string, icon: url, key: string) {
button.name = name button.name = name
button.subname = symbol button.subname = symbol
button.icon = icon button.icon = icon
@ -71,5 +69,7 @@ Control {
root.selected(key) root.selected(key)
} }
} }
onClosed: searchableAssetsPanel.clearSearch()
} }
} }

View File

@ -17,7 +17,7 @@ Control {
/** Expected model structure: see SearchableCollectiblesPanel::model **/ /** Expected model structure: see SearchableCollectiblesPanel::model **/
property alias collectiblesModel: tokenSelectorPanel.collectiblesModel property alias collectiblesModel: tokenSelectorPanel.collectiblesModel
readonly property bool isTokenSelected: d.isTokenSelected readonly property bool isTokenSelected: tokenSelectorButton.selected
signal assetSelected(string key) signal assetSelected(string key)
signal collectionSelected(string key) signal collectionSelected(string key)
@ -27,23 +27,16 @@ Control {
// TokensSelectorPanel.Tabs enum values. // TokensSelectorPanel.Tabs enum values.
property alias currentTab: tokenSelectorPanel.currentTab property alias currentTab: tokenSelectorPanel.currentTab
function setCustom(name: string, icon: url, key: string) { function setSelection(name: string, icon: url, key: string) {
d.isTokenSelected = true tokenSelectorButton.selected = true
tokenSelectorButton.name = name tokenSelectorButton.name = name
tokenSelectorButton.icon = icon tokenSelectorButton.icon = icon
tokenSelectorPanel.highlightedKey = key ?? "" tokenSelectorPanel.highlightedKey = key ?? ""
} }
QtObject {
id: d
property bool isTokenSelected: false
}
contentItem: TokenSelectorButton { contentItem: TokenSelectorButton {
id: tokenSelectorButton id: tokenSelectorButton
selected: d.isTokenSelected
forceHovered: dropdown.opened forceHovered: dropdown.opened
onClicked: dropdown.opened ? dropdown.close() : dropdown.open() onClicked: dropdown.opened ? dropdown.close() : dropdown.open()
@ -79,7 +72,7 @@ Control {
function setCurrentAndClose(name, icon) { function setCurrentAndClose(name, icon) {
tokenSelectorButton.name = name tokenSelectorButton.name = name
tokenSelectorButton.icon = icon tokenSelectorButton.icon = icon
d.isTokenSelected = true tokenSelectorButton.selected = true
dropdown.close() dropdown.close()
} }

View File

@ -27,13 +27,12 @@ Control {
balances [model] - submodel of balances per chain balances [model] - submodel of balances per chain
balanceAsString [string] - formatted balance per chain balanceAsString [string] - formatted balance per chain
iconUrl [url] - chain's icon iconUrl [url] - chain's icon
sectionName (optional) [string] - text to be rendered as a section
**/ **/
property alias model: sfpm.sourceModel property alias model: sfpm.sourceModel
property string highlightedKey property string highlightedKey
property string nonInteractiveKey property string nonInteractiveKey
property string sectionProperty
signal selected(string key) signal selected(string key)
function clearSearch() { function clearSearch() {
@ -84,7 +83,7 @@ Control {
Layout.preferredHeight: contentHeight Layout.preferredHeight: contentHeight
model: sfpm model: sfpm
section.property: root.sectionProperty section.property: "sectionName"
section.delegate: TokenSelectorSectionDelegate { section.delegate: TokenSelectorSectionDelegate {
width: ListView.view.width width: ListView.view.width

View File

@ -95,7 +95,6 @@ ColumnLayout {
Layout.fillWidth: true Layout.fillWidth: true
model: root.assetsModel model: root.assetsModel
sectionProperty: "sectionName"
onSelected: root.tokenSelected(key) onSelected: root.tokenSelected(key)
@ -108,7 +107,7 @@ ColumnLayout {
const entry = ModelUtils.getByKey(root.assetsModel, const entry = ModelUtils.getByKey(root.assetsModel,
"tokensKey", root.selectedTokenKey) "tokensKey", root.selectedTokenKey)
if (entry) { if (entry) {
assetSelector.setCustom(entry.name, entry.symbol, assetSelector.setSelection(entry.name, entry.symbol,
entry.iconSource, entry.tokensKey) entry.iconSource, entry.tokensKey)
root.tokenSelected(entry.tokensKey) root.tokenSelected(entry.tokensKey)
} else { } else {

View File

@ -53,7 +53,7 @@ Control {
if (entry) { if (entry) {
holdingSelector.currentTokensKey = root.tokenKey holdingSelector.currentTokensKey = root.tokenKey
holdingSelector.setCustom(entry.symbol, entry.iconSource, entry.tokensKey) holdingSelector.setSelection(entry.symbol, entry.iconSource, entry.tokensKey)
} else { } else {
holdingSelector.currentTokensKey = "" holdingSelector.currentTokensKey = ""
holdingSelector.reset() holdingSelector.reset()
@ -267,8 +267,6 @@ Control {
model: d.adaptor.outputAssetsModel model: d.adaptor.outputAssetsModel
nonInteractiveKey: root.nonInteractiveTokensKey nonInteractiveKey: root.nonInteractiveTokensKey
sectionProperty: "sectionName"
onSelected: currentTokensKey = key onSelected: currentTokensKey = key
} }

View File

@ -80,6 +80,8 @@ Control {
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
highlightedKey: root.highlightedKey
onSelected: root.assetSelected(key) onSelected: root.assetSelected(key)
} }
@ -91,6 +93,8 @@ Control {
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
highlightedKey: root.highlightedKey
onCollectibleSelected: root.collectibleSelected(key) onCollectibleSelected: root.collectibleSelected(key)
onCollectionSelected: root.collectionSelected(key) onCollectionSelected: root.collectionSelected(key)
} }

View File

@ -229,7 +229,7 @@ StatusDialog {
d.selectedHoldingType = Constants.TokenType.ERC20 d.selectedHoldingType = Constants.TokenType.ERC20
d.selectedHolding = entry d.selectedHolding = entry
holdingSelector.setCustom(entry.symbol, entry.iconSource, holdingSelector.setSelection(entry.symbol, entry.iconSource,
popup.preSelectedHoldingID) popup.preSelectedHoldingID)
holdingSelector.selectedItem = entry holdingSelector.selectedItem = entry
} else { } else {
@ -242,7 +242,7 @@ StatusDialog {
const id = entry.communityId ? entry.collectionUid : entry.uid const id = entry.communityId ? entry.collectionUid : entry.uid
holdingSelector.setCustom(entry.name, holdingSelector.setSelection(entry.name,
entry.imageUrl || entry.mediaUrl, entry.imageUrl || entry.mediaUrl,
id) id)
holdingSelector.selectedItem = entry holdingSelector.selectedItem = entry