Fix/remove send collectibles model 16328 (#16332)

* fix(wallet): Remove collectibles nested model

* fix(wallet): Remove collectible controller from send module
This commit is contained in:
Cuteivist 2024-09-16 13:21:25 +02:00 committed by GitHub
parent 8bbe17b613
commit 7cd2ed888c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 3 additions and 432 deletions

View File

@ -3,7 +3,6 @@ import app/modules/shared_models/currency_amount
import app_service/service/transaction/dto
import app_service/service/network/network_item
import app/modules/shared_models/collectibles_model as collectibles
import app/modules/shared_models/collectibles_nested_model as nested_collectibles
from app_service/service/keycard/service import KeycardEvent
type
@ -67,9 +66,6 @@ method authenticateUser*(self: AccessInterface) {.base.} =
method onUserAuthenticated*(self: AccessInterface, pin: string, password: string, keyUid: string) {.base.} =
raise newException(ValueError, "No implementation available")
method notifySelectedSenderAccountChanged*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method setSelectedReceiveAccountIndex*(self: AccessInterface, index: int) {.base.} =
raise newException(ValueError, "No implementation available")
@ -79,9 +75,6 @@ method filterChanged*(self: AccessInterface, addresses: seq[string], chainIds: s
method getCollectiblesModel*(self: AccessInterface): collectibles.Model {.base.} =
raise newException(ValueError, "No implementation available")
method getNestedCollectiblesModel*(self: AccessInterface): nested_collectibles.Model {.base.} =
raise newException(ValueError, "No implementation available")
method splitAndFormatAddressPrefix*(self: AccessInterface, text : string, updateInStore: bool): string {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -16,11 +16,6 @@ import app_service/service/transaction/dto_conversion
import app/modules/shared_models/currency_amount
import app_service/service/network/network_item as network_service_item
import app/modules/shared_modules/collectibles/controller as collectiblesc
import app/modules/shared_models/collectibles_model as collectibles
import app/modules/shared_models/collectibles_nested_model as nested_collectibles
import backend/collectibles as backend_collectibles
export io_interface
logScope:
@ -50,9 +45,6 @@ type
view: View
viewVariant: QVariant
controller: controller.Controller
# Get the list of owned collectibles by the currently selected account
collectiblesController: collectiblesc.Controller
nestedCollectiblesModel: nested_collectibles.Model
moduleLoaded: bool
tmpSendTransactionDetails: TmpSendTransactionDetails
tmpPin: string
@ -75,13 +67,6 @@ proc newModule*(
result.events = events
result.controller = controller.newController(result, events, walletAccountService, networkService, currencyService,
transactionService, keycardService)
result.collectiblesController = collectiblesc.newController(
requestId = int32(backend_collectibles.CollectiblesRequestID.WalletSend),
loadType = collectiblesc.LoadType.AutoLoadSingleUpdate,
networkService = networkService,
events = events
)
result.nestedCollectiblesModel = nested_collectibles.newModel(result.collectiblesController.getModel())
result.view = newView(result)
result.viewVariant = newQVariant(result.view)
@ -91,8 +76,6 @@ method delete*(self: Module) =
self.viewVariant.delete
self.view.delete
self.controller.delete
self.nestedCollectiblesModel.delete
self.collectiblesController.delete
proc convertSendToNetworkToNetworkItem(self: Module, network: SendToNetwork): NetworkRouteItem =
result = initNetworkRouteItem(
@ -334,22 +317,6 @@ method filterChanged*(self: Module, addresses: seq[string], chainIds: seq[int])
self.view.setSenderAccount(addresses[0])
self.view.setReceiverAccount(addresses[0])
proc updateCollectiblesFilter*(self: Module) =
let senderAddress = self.view.getSelectedSenderAccountAddress()
let addresses = @[senderAddress]
let chainIds = self.controller.getChainIds()
self.collectiblesController.setFilterAddressesAndChains(addresses, chainIds)
self.nestedCollectiblesModel.setAddress(senderAddress)
method notifySelectedSenderAccountChanged*(self: Module) =
self.updateCollectiblesFilter()
method getCollectiblesModel*(self: Module): collectibles.Model =
return self.collectiblesController.getModel()
method getNestedCollectiblesModel*(self: Module): nested_collectibles.Model =
return self.nestedCollectiblesModel
proc getNetworkColor(self: Module, shortName: string): string =
let networks = self.controller.getCurrentNetworks()
for network in networks:

View File

@ -2,8 +2,6 @@ import NimQml, Tables, json, sequtils, strutils, stint, options, chronicles
import uuids
import ./io_interface, ./network_route_model, ./network_route_item, ./suggested_route_item, ./transaction_routes
import app/modules/shared_models/collectibles_model as collectibles
import app/modules/shared_models/collectibles_nested_model as nested_collectibles
import app_service/service/network/service as network_service
import app_service/service/transaction/dto as transaction_dto
@ -15,9 +13,6 @@ QtObject:
type
View* = ref object of QObject
delegate: io_interface.AccessInterface
# list of collectibles owned by the selected sender account
collectiblesModel: collectibles.Model
nestedCollectiblesModel: nested_collectibles.Model
# for send modal
fromNetworksRouteModel: NetworkRouteModel
toNetworksRouteModel: NetworkRouteModel
@ -52,8 +47,6 @@ QtObject:
result.fromNetworksRouteModel = newNetworkRouteModel()
result.toNetworksRouteModel = newNetworkRouteModel()
result.transactionRoutes = newTransactionRoutes()
result.collectiblesModel = delegate.getCollectiblesModel()
result.nestedCollectiblesModel = delegate.getNestedCollectiblesModel()
proc load*(self: View) =
self.delegate.viewDidLoad()
@ -69,20 +62,6 @@ QtObject:
read = getSelectedSenderAccountAddress
notify = selectedSenderAccountAddressChanged
proc collectiblesModelChanged*(self: View) {.signal.}
proc getCollectiblesModel(self: View): QVariant {.slot.} =
return newQVariant(self.collectiblesModel)
QtProperty[QVariant] collectiblesModel:
read = getCollectiblesModel
notify = collectiblesModelChanged
proc nestedCollectiblesModelChanged*(self: View) {.signal.}
proc getNestedCollectiblesModel(self: View): QVariant {.slot.} =
return newQVariant(self.nestedCollectiblesModel)
QtProperty[QVariant] nestedCollectiblesModel:
read = getNestedCollectiblesModel
notify = nestedCollectiblesModelChanged
proc selectedReceiveAccountAddressChanged*(self: View) {.signal.}
proc getSelectedReceiveAccountAddress*(self: View): string {.slot.} =
return self.selectedReceiveAccountAddress
@ -247,7 +226,6 @@ QtObject:
self.toNetworksRouteModel.resetPathData()
for path in paths:
let fromChainId = path.getfromNetwork()
let networkItem = self.delegate.getNetworkItem(fromChainId)
self.fromNetworksRouteModel.updateFromNetworks(path, not chainsWithNoGas.hasKey(fromChainId))
self.toNetworksRouteModel.updateToNetworks(path)
@ -331,7 +309,6 @@ QtObject:
proc setSenderAccount*(self: View, address: string) {.slot.} =
self.setSelectedSenderAccountAddress(address)
self.delegate.notifySelectedSenderAccountChanged()
proc setReceiverAccount*(self: View, address: string) {.slot.} =
self.setSelectedReceiveAccountAddress(address)

View File

@ -1,86 +0,0 @@
import stew/shims/strformat
import app_service/common/types
import stint
type
ItemType* {.pure.} = enum
CommunityCollectible = 0,
NonCommunityCollectible = 1,
Collection = 2,
Community = 3
type
Item* = object
id: string # CollectibleID if single collectible, GroupID (CollectionID/CommunityID) otherwise
chainId: int
name: string
iconUrl: string
groupId: string
groupName: string
tokenType: TokenType
itemType: ItemType
count: UInt256
proc initItem*(
id: string,
chainId: int,
name: string,
iconUrl: string,
groupId: string,
groupName: string,
tokenType: TokenType,
itemType: ItemType,
count: UInt256,
): Item =
result.id = id
result.chainId = chainId
result.name = name
result.iconUrl = iconUrl
result.groupId = groupId
result.groupName = groupName
result.tokenType = tokenType
result.itemType = itemType
result.count = count
proc `$`*(self: Item): string =
result = fmt"""CollectiblesNestedEntry(
id: {self.id},
chainId: {self.chainId},
name: {self.name},
iconUrl: {self.iconUrl},
groupId: {self.groupId},
groupName: {self.groupName},
tokenType: {self.tokenType},
itemType: {self.itemType},
count: {self.count},
]"""
proc getId*(self: Item): string =
return self.id
proc getChainId*(self: Item): int =
return self.chainId
proc getName*(self: Item): string =
return self.name
proc getIconUrl*(self: Item): string =
return self.iconUrl
proc getGroupId*(self: Item): string =
return self.groupId
proc getGroupName*(self: Item): string =
return self.groupName
proc getTokenType*(self: Item): int =
return self.tokenType.int
proc getItemType*(self: Item): int =
return self.itemType.int
proc getCount*(self: Item): UInt256 =
return self.count
proc getCountAsString*(self: Item): string =
return $self.count

View File

@ -1,201 +0,0 @@
import NimQml, Tables, strutils, stew/shims/strformat, sequtils
import stint
import ./collectible_ownership_model
import ./collectibles_model as flat_model
import ./collectibles_entry as flat_item
import ./collectibles_nested_item as nested_item
import ./collectibles_nested_utils
type
CollectiblesNestedRole {.pure.} = enum
Uid = UserRole + 1,
ChainId
Name
IconUrl
GroupId
GroupName
TokenType
ItemType
Count
type
CollectiblesPerGroupId = Table[string, seq[flat_item.CollectiblesEntry]]
QtObject:
type
Model* = ref object of QAbstractListModel
flatModel: flat_model.Model
items: seq[nested_item.Item]
currentGroupId: string
address: string
proc delete(self: Model) =
self.items = @[]
self.QAbstractListModel.delete
proc setup(self: Model) =
self.QAbstractListModel.setup
proc newModel*(flatModel: flat_model.Model): Model =
new(result, delete)
result.flatModel = flatModel
result.items = @[]
result.currentGroupId = ""
result.setup
signalConnect(result.flatModel, "countChanged()", result, "refreshItems()")
signalConnect(result.flatModel, "itemsDataUpdated()", result, "refreshItems()")
# Forward declaration
proc refreshItems*(self: Model)
proc `$`*(self: Model): string =
result = fmt"""CollectiblesNestedModel(
flatModel: {self.flatModel},
currentGroupId: {self.currentGroupId},
]"""
proc countChanged(self: Model) {.signal.}
proc getCount*(self: Model): int {.slot.} =
self.items.len
QtProperty[int] count:
read = getCount
notify = countChanged
proc getCurrentCollectionUid*(self: Model): string {.slot.} =
result = self.currentGroupId
proc currentCollectionUidChanged(self: Model) {.signal.}
proc setCurrentCollectionUid(self: Model, currentGroupId: string) {.slot.} =
self.currentGroupId = currentGroupId
self.currentCollectionUidChanged()
self.refreshItems()
QtProperty[string] currentGroupId:
read = getCurrentCollectionUid
write = setCurrentCollectionUid
notify = currentCollectionUidChanged
method rowCount(self: Model, index: QModelIndex = nil): int =
return self.items.len
method roleNames(self: Model): Table[int, string] =
{
CollectiblesNestedRole.Uid.int:"uid",
CollectiblesNestedRole.ChainId.int:"chainId",
CollectiblesNestedRole.Name.int:"name",
CollectiblesNestedRole.IconUrl.int:"iconUrl",
CollectiblesNestedRole.GroupId.int:"groupId",
CollectiblesNestedRole.GroupName.int:"groupName",
CollectiblesNestedRole.TokenType.int:"tokenType",
CollectiblesNestedRole.ItemType.int:"itemType",
CollectiblesNestedRole.Count.int:"count",
}.toTable
method data(self: Model, index: QModelIndex, role: int): QVariant =
if (not index.isValid):
return
if (index.row < 0 or index.row >= self.getCount()):
return
let item = self.items[index.row]
let enumRole = role.CollectiblesNestedRole
case enumRole:
of CollectiblesNestedRole.Uid:
result = newQVariant(item.getId())
of CollectiblesNestedRole.ChainId:
result = newQVariant(item.getChainId())
of CollectiblesNestedRole.Name:
result = newQVariant(item.getName())
of CollectiblesNestedRole.IconUrl:
result = newQVariant(item.getIconUrl())
of CollectiblesNestedRole.GroupId:
result = newQVariant(item.getGroupId())
of CollectiblesNestedRole.GroupName:
result = newQVariant(item.getGroupName())
of CollectiblesNestedRole.TokenType:
result = newQVariant(item.getTokenType())
of CollectiblesNestedRole.ItemType:
result = newQVariant(item.getItemType())
of CollectiblesNestedRole.Count:
result = newQVariant(item.getCountAsString())
# Groups collectibles by CommunityID if available, or CollectionID otherwise.
# Returns pair (collectiblesPerCommunity, collectiblesPerCollection)
proc getCollectiblesPerGroupId(items: seq[flat_item.CollectiblesEntry]): (CollectiblesPerGroupId, CollectiblesPerGroupId) =
var collectiblesPerCommunity = initTable[string, seq[flat_item.CollectiblesEntry]]()
var collectiblesPerCollection = initTable[string, seq[flat_item.CollectiblesEntry]]()
for item in items:
let collectionId = item.getCollectionIDAsString()
let communityId = item.getCommunityId()
if communityId == "":
if not collectiblesPerCollection.hasKey(collectionId):
collectiblesPerCollection[collectionId] = @[]
collectiblesPerCollection[collectionId].add(item)
else:
if not collectiblesPerCommunity.hasKey(communityId):
collectiblesPerCommunity[communityId] = @[]
collectiblesPerCommunity[communityId].add(item)
return (collectiblesPerCommunity, collectiblesPerCollection)
proc refreshItems*(self: Model) {.slot.} =
let (collectiblesPerCommunity, collectiblesPerCollection) = getCollectiblesPerGroupId(self.flatModel.getItems())
self.beginResetModel()
self.items = @[]
var addCollections = true
# Add communities
for communityId, communityCollectibles in collectiblesPerCommunity.pairs:
if self.currentGroupId == "":
# No collection selected
if communityCollectibles.len > 0:
let communityItem = collectibleToCommunityNestedItem(communityCollectibles[0], stint.u256(communityCollectibles.len))
self.items.add(communityItem)
else:
if self.currentGroupId == communityId:
for collectible in communityCollectibles:
let collectibleItem = collectibleToCommunityCollectibleNestedItem(collectible, collectible.getOwnershipModel().getBalance(self.address))
self.items.add(collectibleItem)
# Inside community folder we dont add collection items
addCollections = false
break
if addCollections:
# Add collections and collection items
for collectionId, collectionCollectibles in collectiblesPerCollection.pairs:
if self.currentGroupId == "":
# No collection selected
# If the collection contains more than 1 collectible, we add a single collection item
# Otherwise, we add the collectible
if collectionCollectibles.len > 1:
let collectionItem = collectibleToCollectionNestedItem(collectionCollectibles[0], stint.u256(collectionCollectibles.len))
self.items.add(collectionItem)
else:
for collectible in collectionCollectibles:
let collectibleItem = collectibleToNonCommunityCollectibleNestedItem(collectible, collectible.getOwnershipModel().getBalance(self.address))
self.items.add(collectibleItem)
else:
if self.currentGroupId == collectionId:
for collectible in collectionCollectibles:
let collectibleItem = collectibleToNonCommunityCollectibleNestedItem(collectible, collectible.getOwnershipModel().getBalance(self.address))
self.items.add(collectibleItem)
# No need to keep looking
break
self.endResetModel()
self.countChanged()
proc resetModel*(self: Model) =
self.beginResetModel()
self.items = @[]
self.endResetModel()
self.countChanged()
proc setAddress*(self: Model, address: string) {.slot.} =
self.address = address
self.refreshItems()

View File

@ -1,57 +0,0 @@
import stint
import ./collectibles_entry as flat_item
import ./collectibles_nested_item as nested_item
import app_service/common/types
proc collectibleToCommunityCollectibleNestedItem*(flatItem: flat_item.CollectiblesEntry, count: UInt256): nested_item.Item =
return nested_item.initItem(
flatItem.getIDAsString(),
flatItem.getChainID(),
flatItem.getName(),
flatItem.getImageURL(),
flatItem.getCommunityId(),
flatItem.getCommunityName(),
TokenType(flatItem.getTokenType()),
ItemType.CommunityCollectible,
count
)
proc collectibleToCommunityNestedItem*(flatItem: flat_item.CollectiblesEntry, count: UInt256): nested_item.Item =
return nested_item.initItem(
flatItem.getCommunityId(),
flatItem.getChainID(),
flatItem.getCommunityName(),
flatItem.getCommunityImage(),
flatItem.getCommunityId(),
flatItem.getCommunityName(),
TokenType(flatItem.getTokenType()),
ItemType.Community,
count
)
proc collectibleToNonCommunityCollectibleNestedItem*(flatItem: flat_item.CollectiblesEntry, count: UInt256): nested_item.Item =
return nested_item.initItem(
flatItem.getIDAsString(),
flatItem.getChainID(),
flatItem.getName(),
flatItem.getImageURL(),
flatItem.getCollectionIDAsString(),
flatItem.getCollectionName(),
TokenType(flatItem.getTokenType()),
ItemType.NonCommunityCollectible,
count
)
proc collectibleToCollectionNestedItem*(flatItem: flat_item.CollectiblesEntry, count: UInt256): nested_item.Item =
return nested_item.initItem(
flatItem.getCollectionIDAsString(),
flatItem.getChainID(),
flatItem.getCollectionName(),
flatItem.getCollectionImageURL(),
flatItem.getCollectionIDAsString(),
flatItem.getCollectionName(),
TokenType(flatItem.getTokenType()),
ItemType.Collection,
count
)

View File

@ -12,7 +12,6 @@ type
CollectiblesRequestID* = enum
WalletAccount
ProfileShowcase
WalletSend
AllCollectibles
# Declared in services/wallet/collectibles/service.go

View File

@ -43,8 +43,6 @@ QtObject {
property var fromNetworksRouteModel: NetworksModel.sendFromNetworks
property var toNetworksRouteModel: NetworksModel.sendToNetworks
property string selectedSenderAccountAddress
readonly property QtObject collectiblesModel: ManageCollectiblesModel {}
readonly property QtObject nestedCollectiblesModel: ListModel {}
readonly property QtObject walletSectionSendInst: QtObject {
signal transactionSent(var chainId, var txHash, var uuid, var error)

View File

@ -426,8 +426,8 @@ StatusDialog {
onCollectibleSelected: {
const entry = SQUtils.ModelUtils.getByKey(
popup.store.collectiblesModel,
"uid", key)
popup.collectiblesStore.allCollectiblesModel,
"symbol", key)
d.selectedHoldingType = entry.tokenType
d.selectedHolding = entry
selectedItem = entry
@ -435,7 +435,7 @@ StatusDialog {
onCollectionSelected: {
const entry = SQUtils.ModelUtils.getByKey(
popup.store.collectiblesModel,
popup.collectiblesStore.allCollectiblesModel,
"collectionUid", key)
d.selectedHoldingType = entry.tokenType
d.selectedHolding = entry

View File

@ -28,8 +28,6 @@ QtObject {
readonly property var toNetworksRouteModel: walletSectionSendInst.toNetworksRouteModel
readonly property string selectedReceiverAccountAddress: walletSectionSendInst.selectedReceiveAccountAddress
readonly property string selectedSenderAccountAddress: walletSectionSendInst.selectedSenderAccountAddress
property var collectiblesModel: walletSectionSendInst.collectiblesModel
property var nestedCollectiblesModel: walletSectionSendInst.nestedCollectiblesModel
property bool areTestNetworksEnabled: networksModule.areTestNetworksEnabled
property var tmpActivityController0: walletSection.tmpActivityController0
readonly property var _tmpActivityController1: walletSection.tmpActivityController1
@ -96,14 +94,6 @@ QtObject {
return {}
}
function getCollectible(uid) {
const idx = ModelUtils.indexOf(collectiblesModel, "uid", uid)
if (idx < 0) {
return {}
}
return ModelUtils.get(collectiblesModel, idx)
}
function setSenderAccount(address) {
walletSectionSendInst.setSenderAccount(address)
}
@ -166,7 +156,6 @@ QtObject {
function resetStoredProperties() {
walletSectionSendInst.resetStoredProperties()
nestedCollectiblesModel.currentCollectionUid = ""
}
function splitAndFormatAddressPrefix(text, updateInStore) {

View File

@ -1409,14 +1409,6 @@ QtObject {
UrlUnfurlingModeDisableAll = 3
}
// these are in sync with src/app/modules/shared_models/collectibles_nested_item.nim ItemType
enum CollectiblesNestedItemType {
CommunityCollectible = 0,
NonCommunityCollectible = 1,
Collection = 2,
Community = 3
}
enum RequestToJoinState {
None = 0,
InProgress = 1,