fix(@desktop/wallet): fix switch accounts after opening collectible details

Moved logic for CollectibleDetailView to Nim module.
This commit is contained in:
Dario Gabriel Lipicar 2022-11-22 16:31:07 -03:00 committed by dlipicar
parent 2bf2861631
commit ecd799c209
20 changed files with 375 additions and 46 deletions

View File

@ -1,3 +1,5 @@
import ./item
type type
AccessInterface* {.pure inheritable.} = ref object of RootObj AccessInterface* {.pure inheritable.} = ref object of RootObj
## Abstract class for any input/interaction with this module. ## Abstract class for any input/interaction with this module.
@ -17,6 +19,9 @@ method fetch*(self: AccessInterface, collectionSlug: string) {.base.} =
method setCurrentAddress*(self: AccessInterface, address: string) {.base.} = method setCurrentAddress*(self: AccessInterface, address: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method getCollectible*(self: AccessInterface, collectionSlug: string, id: int) : Item {.base.} =
raise newException(ValueError, "No implementation available")
# View Delegate Interface # View Delegate Interface
# Delegate for the view must be declared here due to use of QtObject and multi # Delegate for the view must be declared here due to use of QtObject and multi
# inheritance, which is not well supported in Nim. # inheritance, which is not well supported in Nim.

View File

@ -57,6 +57,9 @@ proc initItem*(
result.rankings = rankings result.rankings = rankings
result.stats = stats result.stats = stats
proc initItem*: Item =
result = initItem(-1, "", "", "transparent", "Collectibles", "", @[], @[], @[])
proc `$`*(self: Item): string = proc `$`*(self: Item): string =
result = fmt"""Collectibles( result = fmt"""Collectibles(
id: {self.id}, id: {self.id},

View File

@ -100,3 +100,9 @@ QtObject:
self.items = items self.items = items
self.endResetModel() self.endResetModel()
self.countChanged() self.countChanged()
proc getItemByID*(self: Model, id: int): Item =
for item in self.items:
if(item.getId() == id):
return item
return initItem()

View File

@ -56,3 +56,6 @@ method fetch*(self: Module, collectionSlug: string) =
c.statistics.map(t => initTrait(t.traitType, t.value, t.displayType, t.maxValue)), c.statistics.map(t => initTrait(t.traitType, t.value, t.displayType, t.maxValue)),
)) ))
self.view.setItems(collectionSlug, items) self.view.setItems(collectionSlug, items)
method getCollectible*(self: Module, collectionSlug: string, id: int): Item =
return self.view.getCollectible(collectionSlug, id)

View File

@ -34,8 +34,14 @@ QtObject:
proc fetch*(self: View, collectionSlug: string) {.slot.} = proc fetch*(self: View, collectionSlug: string) {.slot.} =
self.delegate.fetch(collectionSlug) self.delegate.fetch(collectionSlug)
proc getModelForCollection*(self: View, collectionSlug: string): QObject {.slot.} = proc getModelForCollectionPrivate(self: View, collectionSlug: string): Model =
if not self.models.hasKey(collectionSlug): if not self.models.hasKey(collectionSlug):
self.models[collectionSlug] = newModel() self.models[collectionSlug] = newModel()
return self.models[collectionSlug] return self.models[collectionSlug]
proc getModelForCollection*(self: View, collectionSlug: string): QObject {.slot.} =
return self.getModelForCollectionPrivate(collectionSlug)
proc getCollectible*(self: View, collectionSlug: string, id: int): Item =
let model = self.getModelForCollectionPrivate(collectionSlug)
return model.getItemByID(id)

View File

@ -1,4 +1,5 @@
import ../../../../../../app_service/service/collectible/service as collectible_service import ../../../../../../app_service/service/collectible/service as collectible_service
import ./item
type type
AccessInterface* {.pure inheritable.} = ref object of RootObj AccessInterface* {.pure inheritable.} = ref object of RootObj
@ -19,6 +20,8 @@ method loadCollections*(self: AccessInterface, address: string) {.base.} =
method setCollections*(self: AccessInterface, collections: seq[CollectionDto]) {.base.} = method setCollections*(self: AccessInterface, collections: seq[CollectionDto]) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method getCollection*(self: AccessInterface, slug: string): Item {.base.} =
raise newException(ValueError, "No implementation available")
# View Delegate Interface # View Delegate Interface
# Delegate for the view must be declared here due to use of QtObject and multi # Delegate for the view must be declared here due to use of QtObject and multi

View File

@ -13,6 +13,9 @@ proc initItem*(name, slug, imageUrl: string, ownedAssetCount: int): Item =
result.imageUrl = imageUrl result.imageUrl = imageUrl
result.ownedAssetCount = ownedAssetCount result.ownedAssetCount = ownedAssetCount
proc initItem*(): Item =
result = initItem("", "", "", 0)
proc `$`*(self: Item): string = proc `$`*(self: Item): string =
result = fmt"""CollectibleCollection( result = fmt"""CollectibleCollection(
name: {self.name}, name: {self.name},

View File

@ -74,3 +74,9 @@ QtObject:
self.items = items self.items = items
self.endResetModel() self.endResetModel()
self.countChanged() self.countChanged()
proc getItemBySlug*(self: Model, slug: string): Item =
for item in self.items:
if(item.getSlug() == slug):
return item
return initItem()

View File

@ -51,3 +51,6 @@ method setCollections*(self: Module, collections: seq[CollectionDto]) =
c.ownedAssetCount, c.ownedAssetCount,
)) ))
) )
method getCollection*(self: Module, slug: string): Item =
return self.view.getCollection(slug)

View File

@ -37,3 +37,6 @@ QtObject:
proc setItems*(self: View, items: seq[Item]) = proc setItems*(self: View, items: seq[Item]) =
self.model.setItems(items) self.model.setItems(items)
proc getCollection*(self: View, slug: string): Item =
return self.model.getItemBySlug(slug)

View File

@ -0,0 +1,29 @@
import io_interface
import ../collectibles/module as collectibles_module
import ../collections/module as collections_module
type
Controller* = ref object of RootObj
delegate: io_interface.AccessInterface
collectiblesModule: collectibles_module.AccessInterface
collectionsModule: collections_module.AccessInterface
proc newController*(
delegate: io_interface.AccessInterface,
collectiblesModule: collectibles_module.AccessInterface,
collectionsModule: collections_module.AccessInterface
): Controller =
result = Controller()
result.delegate = delegate
result.collectiblesModule = collectiblesModule
result.collectionsModule = collectionsModule
proc delete*(self: Controller) =
discard
proc init*(self: Controller) =
discard
proc update*(self: Controller, slug: string, id: int) =
self.delegate.setData(self.collectionsModule.getCollection(slug), self.collectiblesModule.getCollectible(slug, id))

View File

@ -0,0 +1,27 @@
import ../collections/item as collection_item
import ../collectibles/item as collectible_item
type
AccessInterface* {.pure inheritable.} = ref object of RootObj
## Abstract class for any input/interaction with this module.
method delete*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method load*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method isLoaded*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")
method update*(self: AccessInterface, slug: string, id: int) {.base.} =
raise newException(ValueError, "No implementation available")
method setData*(self: AccessInterface, collection: collection_item.Item, collectible: collectible_item.Item) {.base.} =
raise newException(ValueError, "No implementation available")
# View Delegate Interface
# Delegate for the view must be declared here due to use of QtObject and multi
# inheritance, which is not well supported in Nim.
method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -0,0 +1,54 @@
import NimQml, sequtils, sugar
import ../../../../../global/global_singleton
import ./io_interface, ./view, ./controller
import ../io_interface as delegate_interface
import ../collectibles/module as collectibles_module
import ../collections/module as collections_module
import ../collections/item as collection_item
import ../collectibles/item as collectible_item
export io_interface
type
Module* = ref object of io_interface.AccessInterface
delegate: delegate_interface.AccessInterface
view: View
controller: Controller
moduleLoaded: bool
currentAccountIndex: int
proc newModule*(
delegate: delegate_interface.AccessInterface,
collectionsModule: collections_module.AccessInterface,
collectiblesModule: collectibles_module.AccessInterface,
): Module =
result = Module()
result.delegate = delegate
result.view = newView(result)
result.controller = newController(result, collectiblesModule, collectionsModule)
result.moduleLoaded = false
method delete*(self: Module) =
self.view.delete
method load*(self: Module) =
singletonInstance.engine.setRootContextProperty("walletSectionCollectibleCurrent", newQVariant(self.view))
self.controller.init()
self.view.load()
method isLoaded*(self: Module): bool =
return self.moduleLoaded
method viewDidLoad*(self: Module) =
self.moduleLoaded = true
self.delegate.currentCollectibleModuleDidLoad()
method update*(self: Module, slug: string, id: int) =
self.controller.update(slug, id)
method setData*(self: Module, collection: collection_item.Item, collectible: collectible_item.Item) =
self.view.setData(collection, collectible)

View File

@ -0,0 +1,181 @@
import NimQml, sequtils, sugar
import ./io_interface
import ../collections/model as collections_model
import ../collectibles/model as collectibles_model
import ../collections/item as collection_item
import ../collectibles/item as collectible_item
import ../collectibles/trait_model
QtObject:
type
View* = ref object of QObject
delegate: io_interface.AccessInterface
name: string
id: string
description: string
backgroundColor: string
imageUrl: string
collectionID: string
collectionImageUrl: string
permalink: string
propertiesModel: TraitModel
rankingsModel: TraitModel
statsModel: TraitModel
proc setup(self: View) =
self.QObject.setup
proc delete*(self: View) =
self.QObject.delete
proc newView*(delegate: io_interface.AccessInterface): View =
new(result, delete)
result.setup()
result.delegate = delegate
result.description = "Collectibles"
result.backgroundColor = "transparent"
result.propertiesModel = newTraitModel()
result.rankingsModel = newTraitModel()
result.statsModel = newTraitModel()
proc load*(self: View) =
self.delegate.viewDidLoad()
proc getName(self: View): QVariant {.slot.} =
return newQVariant(self.name)
proc nameChanged(self: View) {.signal.}
QtProperty[QVariant] name:
read = getName
notify = nameChanged
proc getID(self: View): QVariant {.slot.} =
return newQVariant(self.id)
proc idChanged(self: View) {.signal.}
QtProperty[QVariant] id:
read = getID
notify = idChanged
proc getDescription(self: View): QVariant {.slot.} =
return newQVariant(self.description)
proc descriptionChanged(self: View) {.signal.}
QtProperty[QVariant] description:
read = getDescription
notify = descriptionChanged
proc getBackgroundColor(self: View): QVariant {.slot.} =
return newQVariant(self.backgroundColor)
proc backgroundColorChanged(self: View) {.signal.}
QtProperty[QVariant] backgroundColor:
read = getBackgroundColor
notify = backgroundColorChanged
proc getImageUrl(self: View): QVariant {.slot.} =
return newQVariant(self.imageUrl)
proc imageUrlChanged(self: View) {.signal.}
QtProperty[QVariant] imageUrl:
read = getImageUrl
notify = imageUrlChanged
proc getCollectionID(self: View): QVariant {.slot.} =
return newQVariant(self.collectionID)
proc collectionIDChanged(self: View) {.signal.}
QtProperty[QVariant] collectionID:
read = getCollectionID
notify = collectionIDChanged
proc getCollectionImageUrl(self: View): QVariant {.slot.} =
return newQVariant(self.collectionImageUrl)
proc collectionImageUrlChanged(self: View) {.signal.}
QtProperty[QVariant] collectionImageUrl:
read = getCollectionImageUrl
notify = collectionImageUrlChanged
proc getPermalink(self: View): QVariant {.slot.} =
return newQVariant(self.permalink)
proc permalinkChanged(self: View) {.signal.}
QtProperty[QVariant] permalink:
read = getPermalink
notify = permalinkChanged
proc propertiesChanged(self: View) {.signal.}
proc getProperties*(self: View): QVariant {.slot.} =
return newQVariant(self.propertiesModel)
QtProperty[QVariant] properties:
read = getProperties
notify = propertiesChanged
proc rankingsChanged(self: View) {.signal.}
proc getRankings*(self: View): QVariant {.slot.} =
return newQVariant(self.rankingsModel)
QtProperty[QVariant] rankings:
read = getRankings
notify = rankingsChanged
proc statsChanged(self: View) {.signal.}
proc getStats*(self: View): QVariant {.slot.} =
return newQVariant(self.statsModel)
QtProperty[QVariant] rankings:
read = getStats
notify = statsChanged
proc update*(self: View, slug: string, id: int) {.slot.} =
self.delegate.update(slug, id)
proc setData*(self: View, collection: collection_item.Item, collectible: collectible_item.Item) =
if (self.name != collectible.getName()):
self.name = collectible.getName()
self.nameChanged()
let idString = $collectible.getId()
if (self.id != idString):
self.id = idString
self.idChanged()
if (self.description != collectible.getDescription()):
self.description = collectible.getDescription()
self.descriptionChanged()
if (self.backgroundColor != collectible.getBackgroundColor()):
self.backgroundColor = collectible.getBackgroundColor()
self.backgroundColorChanged()
if (self.imageUrl != collectible.getImageUrl()):
self.imageUrl = collectible.getImageUrl()
self.imageUrlChanged()
if (self.collectionImageUrl != collection.getImageUrl()):
self.collectionImageUrl = collection.getImageUrl()
self.collectionImageUrlChanged()
self.propertiesModel.setItems(collectible.getProperties())
self.propertiesChanged()
self.rankingsModel.setItems(collectible.getRankings())
self.rankingsChanged()
self.statsModel.setItems(collectible.getStats())
self.statsChanged()

View File

@ -23,3 +23,6 @@ method collectiblesModuleDidLoad*(self: AccessInterface) {.base.} =
method collectionsModuleDidLoad*(self: AccessInterface) {.base.} = method collectionsModuleDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method currentCollectibleModuleDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -7,6 +7,7 @@ import ../../../../../app_service/service/wallet_account/service as wallet_accou
import ./collectible/module as collectible_module import ./collectible/module as collectible_module
import ./collections/module as collections_module import ./collections/module as collections_module
import ./collectibles/module as collectibles_module import ./collectibles/module as collectibles_module
import ./current_collectible/module as current_collectible_module
export io_interface export io_interface
@ -19,6 +20,7 @@ type
collectiblesModule: collectibles_module.AccessInterface collectiblesModule: collectibles_module.AccessInterface
collectionsModule: collections_module.AccessInterface collectionsModule: collections_module.AccessInterface
collectibleModule: collectible_module.AccessInterface collectibleModule: collectible_module.AccessInterface
currentCollectibleModule: current_collectible_module.AccessInterface
proc newModule*( proc newModule*(
delegate: delegate_interface.AccessInterface, delegate: delegate_interface.AccessInterface,
@ -34,17 +36,20 @@ proc newModule*(
result.collectiblesModule = collectibles_module.newModule(result, collectibleService) result.collectiblesModule = collectibles_module.newModule(result, collectibleService)
result.collectionsModule = collectionsModule.newModule(result, events, collectibleService) result.collectionsModule = collectionsModule.newModule(result, events, collectibleService)
result.collectibleModule = collectibleModule.newModule(result, collectibleService) result.collectibleModule = collectibleModule.newModule(result, collectibleService)
result.currentCollectibleModule = currentCollectibleModule.newModule(result, result.collectionsModule, result.collectiblesModule)
method delete*(self: Module) = method delete*(self: Module) =
self.collectiblesModule.delete self.collectiblesModule.delete
self.collectionsModule.delete self.collectionsModule.delete
self.collectibleModule.delete self.collectibleModule.delete
self.currentCollectibleModule.delete
method load*(self: Module) = method load*(self: Module) =
self.controller.init self.controller.init
self.collectiblesModule.load self.collectiblesModule.load
self.collectionsModule.load self.collectionsModule.load
self.collectibleModule.load self.collectibleModule.load
self.currentCollectibleModule.load
method isLoaded*(self: Module): bool = method isLoaded*(self: Module): bool =
return self.moduleLoaded return self.moduleLoaded
@ -59,6 +64,9 @@ proc checkIfModuleDidLoad(self: Module) =
if(not self.collectibleModule.isLoaded()): if(not self.collectibleModule.isLoaded()):
return return
if(not self.currentCollectibleModule.isLoaded()):
return
self.moduleLoaded = true self.moduleLoaded = true
self.delegate.collectiblesModuleDidLoad() self.delegate.collectiblesModuleDidLoad()
@ -71,6 +79,9 @@ method collectiblesModuleDidLoad*(self: Module) =
method collectionsModuleDidLoad*(self: Module) = method collectionsModuleDidLoad*(self: Module) =
self.checkIfModuleDidLoad() self.checkIfModuleDidLoad()
method currentCollectibleModuleDidLoad*(self: Module) =
self.checkIfModuleDidLoad()
method switchAccount*(self: Module, accountIndex: int) = method switchAccount*(self: Module, accountIndex: int) =
let account = self.controller.getWalletAccount(accountIndex) let account = self.controller.getWalletAccount(accountIndex)
self.collectionsModule.loadCollections(account.address) self.collectionsModule.loadCollections(account.address)

View File

@ -1,20 +0,0 @@
import QtQuick 2.13
import QtQuick.Dialogs 1.3
import utils 1.0
QtObject {
id: root
property string name
property string collectibleId
property string description: qsTr("Collectibles")
property color backgroundColor: "transparent"
property url collectibleImageUrl
property url permalink
property url imageUrl
property var properties
property var rankings
property var stats
property int collectionIndex
}

View File

@ -34,8 +34,9 @@ QtObject {
property var walletTokensModule: walletSectionAllTokens property var walletTokensModule: walletSectionAllTokens
property var tokens: walletSectionAllTokens.all property var tokens: walletSectionAllTokens.all
property CollectiblesStore collectiblesStore: CollectiblesStore { }
property var collectionList: walletSectionCollectiblesCollections.model property var collectionList: walletSectionCollectiblesCollections.model
property var collectibleLists: walletSectionCollectiblesCollectibles.model
property var currentCollectible: walletSectionCollectibleCurrent
property var savedAddresses: walletSectionSavedAddresses.model property var savedAddresses: walletSectionSavedAddresses.model
@ -177,6 +178,10 @@ QtObject {
// walletModelV2Inst.collectiblesView.collections.getCollectionTraitMaxValue(collectionIndex, traitType).toString(); // walletModelV2Inst.collectiblesView.collections.getCollectionTraitMaxValue(collectionIndex, traitType).toString();
} }
function selectCollectible(slug, id) {
walletSectionCollectibleCurrent.update(slug, id)
}
function createOrUpdateSavedAddress(name, address, favourite) { function createOrUpdateSavedAddress(name, address, favourite) {
return walletSectionSavedAddresses.createOrUpdateSavedAddress(name, address, favourite) return walletSectionSavedAddresses.createOrUpdateSavedAddress(name, address, favourite)
} }

View File

@ -87,9 +87,9 @@ Item {
bottomPadding: 16 bottomPadding: 16
spacing: 24 spacing: 24
Repeater { Component {
objectName: "collectiblesRepeater" id: collectibleDelegate
model: RootStore.getCollectionCollectiblesList(root.slug)
StatusRoundedImage { StatusRoundedImage {
id: image id: image
width: 146 width: 146
@ -115,22 +115,18 @@ Item {
anchors.fill: parent anchors.fill: parent
hoverEnabled: true hoverEnabled: true
onClicked: { onClicked: {
RootStore.collectiblesStore.collectibleImageUrl = collectionImageUrl; RootStore.selectCollectible(root.slug, model.id)
RootStore.collectiblesStore.name = model.name;
RootStore.collectiblesStore.collectibleId = model.id;
RootStore.collectiblesStore.description = model.description;
RootStore.collectiblesStore.permalink = model.permalink;
RootStore.collectiblesStore.imageUrl = model.imageUrl;
RootStore.collectiblesStore.backgroundColor = model.backgroundColor;
RootStore.collectiblesStore.properties = model.properties;
RootStore.collectiblesStore.rankings = model.rankings;
RootStore.collectiblesStore.stats = model.stats;
RootStore.collectiblesStore.collectionIndex = root.collectionIndex;
root.collectibleClicked(); root.collectibleClicked();
} }
} }
} }
} }
Repeater {
objectName: "collectiblesRepeater"
model: RootStore.getCollectionCollectiblesList(root.slug)
delegate: collectibleDelegate
}
} }
} }
} }

View File

@ -15,15 +15,17 @@ import "../../controls"
Item { Item {
id: root id: root
property var currentCollectible: RootStore.currentCollectible
CollectibleDetailsHeader { CollectibleDetailsHeader {
id: collectibleHeader id: collectibleHeader
anchors.top: parent.top anchors.top: parent.top
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
asset.name: RootStore.collectiblesStore.collectibleImageUrl asset.name: currentCollectible.collectionImageUrl
asset.isImage: true asset.isImage: true
primaryText: RootStore.collectiblesStore.name primaryText: currentCollectible.name
secondaryText: RootStore.collectiblesStore.collectibleId secondaryText: currentCollectible.id
} }
ColumnLayout { ColumnLayout {
@ -45,17 +47,17 @@ Item {
width: 253 width: 253
height: 253 height: 253
radius: 2 radius: 2
color: RootStore.collectiblesStore.backgroundColor color: currentCollectible.backgroundColor
border.color: Theme.palette.directColor8 border.color: Theme.palette.directColor8
border.width: 1 border.width: 1
image.source: RootStore.collectiblesStore.imageUrl image.source: currentCollectible.imageUrl
} }
StatusBaseText { StatusBaseText {
id: collectibleText id: collectibleText
width: parent.width - collectibleimage.width - Style.current.bigPadding width: parent.width - collectibleimage.width - Style.current.bigPadding
height: collectibleimage.height height: collectibleimage.height
text: RootStore.collectiblesStore.description text: currentCollectible.description
color: Theme.palette.directColor1 color: Theme.palette.directColor1
font.pixelSize: 15 font.pixelSize: 15
lineHeight: 22 lineHeight: 22
@ -69,7 +71,7 @@ Item {
id: collectiblesDetailsTab id: collectiblesDetailsTab
Layout.fillWidth: true Layout.fillWidth: true
Layout.topMargin: Style.current.xlPadding Layout.topMargin: Style.current.xlPadding
visible: RootStore.collectiblesStore.properties.count > 0 visible: currentCollectible.properties.count > 0
StatusTabButton { StatusTabButton {
leftPadding: 0 leftPadding: 0
@ -83,7 +85,7 @@ Item {
width: parent.width width: parent.width
spacing: 10 spacing: 10
Repeater { Repeater {
model: RootStore.collectiblesStore.properties model: currentCollectible.properties
InformationTile { InformationTile {
maxWidth: parent.width maxWidth: parent.width
primaryText: model.traitType primaryText: model.traitType