feat:(@desktop/profile): dedicated collectibles model for profile showcase

Closes #11637
This commit is contained in:
Dario Gabriel Lipicar 2023-08-11 11:56:32 -03:00 committed by dlipicar
parent e82270c718
commit 238ffeb01e
6 changed files with 33 additions and 4 deletions

View File

@ -43,6 +43,9 @@ method viewDidLoad*(self: AccessInterface) {.base.} =
method getModuleAsVariant*(self: AccessInterface): QVariant {.base.} =
raise newException(ValueError, "No implementation available")
method getCollectiblesModel*(self: AccessInterface): QVariant {.base.} =
raise newException(ValueError, "No implementation available")
method toggleIncludeWatchOnlyAccount*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -1,10 +1,12 @@
import NimQml, sequtils, sugar, chronicles, tables
import ./io_interface, ./view, ./controller
import ./io_interface, ./view
import ./controller as accountsc
import ../io_interface as delegate_interface
import app/modules/shared/wallet_utils
import app/modules/shared/keypairs
import app/modules/shared_models/[keypair_model, currency_amount]
import app/modules/shared_modules/collectibles/controller as collectiblesc
import app/global/global_singleton
import app/core/eventemitter
import app_service/service/keycard/service as keycard_service
@ -12,6 +14,8 @@ import app_service/service/wallet_account/service as wallet_account_service
import app_service/service/network/service as network_service
import app_service/service/settings/service
import backend/collectibles as backend_collectibles
export io_interface
type
@ -20,9 +24,10 @@ type
events: EventEmitter
view: View
viewVariant: QVariant
controller: Controller
controller: accountsc.Controller
moduleLoaded: bool
walletAccountService: wallet_account_service.Service
collectiblesController: collectiblesc.Controller
proc newModule*(
delegate: delegate_interface.AccessInterface,
@ -36,7 +41,8 @@ proc newModule*(
result.walletAccountService = walletAccountService
result.view = newView(result)
result.viewVariant = newQVariant(result.view)
result.controller = controller.newController(result, walletAccountService)
result.controller = accountsc.newController(result, walletAccountService)
result.collectiblesController = collectiblesc.newController(int32(backend_collectibles.CollectiblesRequestID.ProfileShowcase), events)
result.moduleLoaded = false
## Forward declarations
@ -46,10 +52,14 @@ method delete*(self: Module) =
self.view.delete
self.viewVariant.delete
self.controller.delete
self.collectiblesController.delete
method getModuleAsVariant*(self: Module): QVariant =
return self.viewVariant
method getCollectiblesModel*(self: Module): QVariant =
return self.collectiblesController.getModel()
method convertWalletAccountDtoToKeyPairAccountItem(self: Module, account: WalletAccountDto): KeyPairAccountItem =
result = newKeyPairAccountItem(
name = account.name,
@ -110,6 +120,11 @@ method refreshWalletAccounts*(self: Module) =
self.view.setKeyPairModelItems(self.createKeypairItems(walletAccounts))
self.view.setItems(items)
let ownedWalletAccounts = walletAccounts.filter(a => a.walletType != WalletTypeWatch)
let ownedWalletAccountAddresses = ownedWalletAccounts.map(a => a.address)
let enabledNetworks = self.controller.getEnabledChainIds()
self.collectiblesController.globalFilterChanged(ownedWalletAccountAddresses, enabledNetworks)
method load*(self: Module) =
self.events.on(SIGNAL_KEYPAIR_SYNCED) do(e: Args):
self.refreshWalletAccounts()

View File

@ -34,6 +34,9 @@ method networksModuleDidLoad*(self: AccessInterface) {.base.} =
method getNetworksModule*(self: AccessInterface): QVariant {.base.} =
raise newException(ValueError, "No implementation available")
method getCollectiblesModel*(self: AccessInterface): QVariant {.base.} =
raise newException(ValueError, "No implementation available")
method getKeypairImportModule*(self: AccessInterface): QVariant {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -76,6 +76,9 @@ method isLoaded*(self: Module): bool =
method getModuleAsVariant*(self: Module): QVariant =
return self.viewVariant
method getCollectiblesModel*(self: Module): QVariant =
return self.accountsModule.getCollectiblesModel()
proc checkIfModuleDidLoad(self: Module) =
if(not self.accountsModule.isLoaded()):
return

View File

@ -26,6 +26,11 @@ QtObject:
QtProperty[QVariant] networksModule:
read = getNetworksModule
proc getCollectiblesModel(self: View): QVariant {.slot.} =
return self.delegate.getCollectiblesModel()
QtProperty[QVariant] collectiblesModel:
read = getCollectiblesModel
proc runKeypairImportPopup*(self: View, keyUid: string, importOption: int) {.slot.} =
self.delegate.runKeypairImportPopup(keyUid, ImportOption(importOption))

View File

@ -8,6 +8,7 @@ QtObject {
property var walletModule
property var accountsModule: root.walletModule.accountsModule
property var networksModule: root.walletModule.networksModule
property var collectibles: root.walletModule.collectiblesModel
property var accountSensitiveSettings: Global.appIsReady? localAccountSensitiveSettings : null
@ -23,7 +24,6 @@ QtObject {
// TODO(alaibe): there should be no access to wallet section, create collectible in profile
property var overview: walletSectionOverview
property var assets: walletSectionAssets.assets
property var collectibles: Global.appIsReady ? walletSection.collectiblesController.model : null // To-do: Fetch profile collectibles separately
property var accounts: Global.appIsReady? accountsModule.accounts : null
property var originModel: accountsModule.keyPairModel
property bool includeWatchOnlyAccount: accountsModule.includeWatchOnlyAccount