diff --git a/src/app/boot/app_controller.nim b/src/app/boot/app_controller.nim index 95a757b2ff..7b6871361f 100644 --- a/src/app/boot/app_controller.nim +++ b/src/app/boot/app_controller.nim @@ -8,6 +8,8 @@ import ../../app_service/service/chat/service as chat_service import ../../app_service/service/community/service as community_service import ../../app_service/service/token/service as token_service import ../../app_service/service/transaction/service as transaction_service +import ../../app_service/service/collectible/service as collectible_service + import ../core/local_account_settings import ../modules/startup/module as startup_module @@ -61,11 +63,11 @@ type communityService: community_service.Service tokenService: token_service.Service transactionService: transaction_service.Service + collectibleService: collectible_service.Service # Core localAccountSettings: LocalAccountSettings localAccountSettingsVariant: QVariant - startupModule: startup_module.AccessInterface mainModule: main_module.AccessInterface ################################################# @@ -116,6 +118,7 @@ proc newAppController*(appService: AppService): AppController = result.communityService = community_service.newService(result.chatService) result.tokenService = token_service.newService() result.transactionService = transaction_service.newService() + result.collectibleService = collectible_service.newService() # Core result.localAccountSettingsVariant = newQVariant( @@ -132,7 +135,8 @@ proc newAppController*(appService: AppService): AppController = result.chatService, result.communityService, result.tokenService, - result.transactionService + result.transactionService, + result.collectibleService ) ################################################# diff --git a/src/app/modules/main/controller.nim b/src/app/modules/main/controller.nim index 830538d719..ce42032ab4 100644 --- a/src/app/modules/main/controller.nim +++ b/src/app/modules/main/controller.nim @@ -1,5 +1,3 @@ -import NimQml, Tables - import controller_interface import io_interface import ../../core/global_singleton diff --git a/src/app/modules/main/module.nim b/src/app/modules/main/module.nim index 3f54a252b1..1dbd70cae2 100644 --- a/src/app/modules/main/module.nim +++ b/src/app/modules/main/module.nim @@ -12,6 +12,7 @@ import ../../../app_service/service/chat/service as chat_service import ../../../app_service/service/community/service as community_service import ../../../app_service/service/token/service as token_service import ../../../app_service/service/transaction/service as transaction_service +import ../../../app_service/service/collectible/service as collectible_service import eventemitter @@ -45,7 +46,8 @@ proc newModule*[T]( chatService: chat_service.Service, communityService: community_service.Service, tokenService: token_service.Service, - transactionService: transaction_service.Service + transactionService: transaction_service.Service, + collectibleService: collectible_service.Service ): Module[T] = result = Module[T]() result.delegate = delegate @@ -65,7 +67,7 @@ proc newModule*[T]( ) result.walletSectionModule = wallet_section_module.newModule[Module[T]]( - result, tokenService, transactionService + result, tokenService, transactionService, collectible_service ) diff --git a/src/app/modules/main/wallet_section/collectibles/controller.nim b/src/app/modules/main/wallet_section/collectibles/controller.nim new file mode 100644 index 0000000000..e26f7333d3 --- /dev/null +++ b/src/app/modules/main/wallet_section/collectibles/controller.nim @@ -0,0 +1,23 @@ +import ./controller_interface +import ../../../../../app_service/service/collectible/service as collectible_service + +export controller_interface + +type + Controller*[T: controller_interface.DelegateInterface] = ref object of controller_interface.AccessInterface + delegate: T + collectibleService: collectible_service.ServiceInterface + +proc newController*[T]( + delegate: T, + collectibleService: collectible_service.ServiceInterface +): Controller[T] = + result = Controller[T]() + result.delegate = delegate + result.collectibleService = collectibleService + +method delete*[T](self: Controller[T]) = + discard + +method init*[T](self: Controller[T]) = + discard \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/collectibles/controller_interface.nim b/src/app/modules/main/wallet_section/collectibles/controller_interface.nim new file mode 100644 index 0000000000..c88ce57e45 --- /dev/null +++ b/src/app/modules/main/wallet_section/collectibles/controller_interface.nim @@ -0,0 +1,17 @@ +import ../../../../../app_service/service/token/service_interface as token_service + +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 init*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") + +type + ## Abstract class (concept) which must be implemented by object/s used in this + ## module. + DelegateInterface* = concept c + \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/collectibles/item.nim b/src/app/modules/main/wallet_section/collectibles/item.nim new file mode 100644 index 0000000000..4ba78c05ec --- /dev/null +++ b/src/app/modules/main/wallet_section/collectibles/item.nim @@ -0,0 +1,16 @@ +import strformat + +type + Item* = object + name: string + +proc initItem*(name: string): Item = + result.name = name + +proc `$`*(self: Item): string = + result = fmt"""AllTokensItem( + name: {self.name}, + ]""" + +proc getName*(self: Item): string = + return self.name \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/collectibles/model.nim b/src/app/modules/main/wallet_section/collectibles/model.nim new file mode 100644 index 0000000000..3ddfd86fdd --- /dev/null +++ b/src/app/modules/main/wallet_section/collectibles/model.nim @@ -0,0 +1,64 @@ +import NimQml, Tables, strutils, strformat + +import ./item + +type + ModelRole {.pure.} = enum + Name = UserRole + 1, + +QtObject: + type + Model* = ref object of QAbstractListModel + items: seq[Item] + + proc delete(self: Model) = + self.items = @[] + self.QAbstractListModel.delete + + proc setup(self: Model) = + self.QAbstractListModel.setup + + proc newModel*(): Model = + new(result, delete) + result.setup + + proc `$`*(self: Model): string = + for i in 0 ..< self.items.len: + result &= fmt"""[{i}]:({$self.items[i]})""" + + proc countChanged(self: Model) {.signal.} + + proc getCount(self: Model): int {.slot.} = + self.items.len + + QtProperty[int] count: + read = getCount + notify = countChanged + + method rowCount(self: Model, index: QModelIndex = nil): int = + return self.items.len + + method roleNames(self: Model): Table[int, string] = + { + ModelRole.Name.int:"name" + }.toTable + + method data(self: Model, index: QModelIndex, role: int): QVariant = + if (not index.isValid): + return + + if (index.row < 0 or index.row >= self.items.len): + return + + let item = self.items[index.row] + let enumRole = role.ModelRole + + case enumRole: + of ModelRole.Name: + result = newQVariant(item.getName()) + + proc setItems*(self: Model, items: seq[Item]) = + self.beginResetModel() + self.items = items + self.endResetModel() + self.countChanged() \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/collectibles/module.nim b/src/app/modules/main/wallet_section/collectibles/module.nim index fae63721bb..c3515faede 100644 --- a/src/app/modules/main/wallet_section/collectibles/module.nim +++ b/src/app/modules/main/wallet_section/collectibles/module.nim @@ -1,21 +1,28 @@ -import ./io_interface, ./view +import ./io_interface, ./view, ./controller +import ../../../../../app_service/service/collectible/service as collectible_service export io_interface type - Module* [T: DelegateInterface] = ref object of AccessInterface + Module* [T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface delegate: T view: View + controller: controller.AccessInterface moduleLoaded: bool -proc newModule*[T](delegate: T): Module[T] = +proc newModule*[T]( + delegate: T, + collectibleService: collectible_service.ServiceInterface +): Module[T] = result = Module[T]() result.delegate = delegate - result.view = newView() + result.view = newView(result) + result.controller = controller.newController[Module[T]](result, collectibleService) result.moduleLoaded = false method delete*[T](self: Module[T]) = self.view.delete + self.controller.delete method load*[T](self: Module[T]) = self.moduleLoaded = true diff --git a/src/app/modules/main/wallet_section/collectibles/view.nim b/src/app/modules/main/wallet_section/collectibles/view.nim index c75634662b..519f0900cf 100644 --- a/src/app/modules/main/wallet_section/collectibles/view.nim +++ b/src/app/modules/main/wallet_section/collectibles/view.nim @@ -1,15 +1,32 @@ import NimQml +import ./model +import ./io_interface + QtObject: type View* = ref object of QObject - - proc setup(self: View) = - self.QObject.setup + delegate: io_interface.AccessInterface + model: Model + modelVariant: QVariant proc delete*(self: View) = + self.model.delete + self.modelVariant.delete self.QObject.delete - proc newView*(): View = + proc newView*(delegate: io_interface.AccessInterface): View = new(result, delete) - result.setup() + result.QObject.setup + result.delegate = delegate + result.model = newModel() + result.modelVariant = newQVariant(result.model) + + proc modelChanged*(self: View) {.signal.} + + proc getModel(self: View): QVariant {.slot.} = + return self.modelVariant + + QtProperty[QVariant] model: + read = getModel + notify = modelChanged \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/module.nim b/src/app/modules/main/wallet_section/module.nim index 1d855feadd..f3ef008ebb 100644 --- a/src/app/modules/main/wallet_section/module.nim +++ b/src/app/modules/main/wallet_section/module.nim @@ -11,6 +11,7 @@ import ./transactions/module as transactions_module import ../../../../app_service/service/token/service as token_service import ../../../../app_service/service/transaction/service as transaction_service +import ../../../../app_service/service/collectible/service as collectible_service import io_interface export io_interface @@ -32,6 +33,7 @@ proc newModule*[T]( delegate: T, tokenService: token_service.Service, transactionService: transaction_service.Service, + collectibleService: collectible_service.Service ): Module[T] = result = Module[T]() result.delegate = delegate @@ -41,7 +43,7 @@ proc newModule*[T]( result.accountTokensModule = account_tokens_module.newModule(result) result.accountsModule = accounts_module.newModule(result) result.allTokensModule = all_tokens_module.newModule(result, tokenService) - result.collectiblesModule = collectibles_module.newModule(result) + result.collectiblesModule = collectibles_module.newModule(result, collectibleService) result.mainAccountModule = main_account_module.newModule(result) result.transactionsModule = transactions_module.newModule(result, transactionService) diff --git a/src/app_service/service/collectible/dto.nim b/src/app_service/service/collectible/dto.nim new file mode 100644 index 0000000000..3d4df956ea --- /dev/null +++ b/src/app_service/service/collectible/dto.nim @@ -0,0 +1,6 @@ +import json + +include ../../common/json_utils + +type Dto* = ref object + id*, name*, image*, collectibleType*, description*, externalUrl*: string \ No newline at end of file diff --git a/src/app_service/service/collectible/service.nim b/src/app_service/service/collectible/service.nim new file mode 100644 index 0000000000..e0577f6348 --- /dev/null +++ b/src/app_service/service/collectible/service.nim @@ -0,0 +1,20 @@ +import chronicles + +import ./service_interface, ./dto + +export service_interface + +logScope: + topics = "collectible-service" + +type + Service* = ref object of ServiceInterface + +method delete*(self: Service) = + discard + +proc newService*(): Service = + result = Service() + +method init*(self: Service) = + discard \ No newline at end of file diff --git a/src/app_service/service/collectible/service_interface.nim b/src/app_service/service/collectible/service_interface.nim new file mode 100644 index 0000000000..b2b8ae9637 --- /dev/null +++ b/src/app_service/service/collectible/service_interface.nim @@ -0,0 +1,13 @@ +import dto + +export dto + +type + ServiceInterface* {.pure inheritable.} = ref object of RootObj + ## Abstract class for this service access. + +method delete*(self: ServiceInterface) {.base.} = + raise newException(ValueError, "No implementation available") + +method init*(self: ServiceInterface) {.base.} = + raise newException(ValueError, "No implementation available") \ No newline at end of file