Skip to content

Commit

Permalink
feat(walletconnect): initial code organization
Browse files Browse the repository at this point in the history
Closes #14395
  • Loading branch information
saledjenic authored and stefandunca committed Apr 30, 2024
1 parent d0658fe commit dfc7bec
Show file tree
Hide file tree
Showing 51 changed files with 992 additions and 306 deletions.
87 changes: 46 additions & 41 deletions src/app/boot/app_controller.nim
Original file line number Diff line number Diff line change
@@ -1,49 +1,50 @@
import NimQml, sequtils, sugar, chronicles, uuids

import ../../app_service/service/general/service as general_service
import ../../app_service/service/keychain/service as keychain_service
import ../../app_service/service/keycard/service as keycard_service
import ../../app_service/service/accounts/service as accounts_service
import ../../app_service/service/contacts/service as contacts_service
import ../../app_service/service/language/service as language_service
import ../../app_service/service/chat/service as chat_service
import ../../app_service/service/community/service as community_service
import ../../app_service/service/message/service as message_service
import ../../app_service/service/token/service as token_service
import ../../app_service/service/collectible/service as collectible_service
import ../../app_service/service/currency/service as currency_service
import ../../app_service/service/transaction/service as transaction_service
import ../../app_service/service/wallet_account/service as wallet_account_service
import ../../app_service/service/bookmarks/service as bookmark_service
import ../../app_service/service/dapp_permissions/service as dapp_permissions_service
import ../../app_service/service/privacy/service as privacy_service
import ../../app_service/service/provider/service as provider_service
import ../../app_service/service/node/service as node_service
import ../../app_service/service/profile/service as profile_service
import ../../app_service/service/settings/service as settings_service
import ../../app_service/service/stickers/service as stickers_service
import ../../app_service/service/about/service as about_service
import ../../app_service/service/node_configuration/service as node_configuration_service
import ../../app_service/service/network/service as network_service
import ../../app_service/service/activity_center/service as activity_center_service
import ../../app_service/service/saved_address/service as saved_address_service
import ../../app_service/service/devices/service as devices_service
import ../../app_service/service/mailservers/service as mailservers_service
import ../../app_service/service/gif/service as gif_service
import ../../app_service/service/ens/service as ens_service
import ../../app_service/service/community_tokens/service as tokens_service
import ../../app_service/service/network_connection/service as network_connection_service
import ../../app_service/service/shared_urls/service as shared_urls_service

import ../modules/shared_modules/keycard_popup/module as keycard_shared_module
import ../modules/startup/module as startup_module
import ../modules/main/module as main_module
import ../core/notifications/notifications_manager
import ../../constants as main_constants
import app_service/service/general/service as general_service
import app_service/service/keychain/service as keychain_service
import app_service/service/keycard/service as keycard_service
import app_service/service/accounts/service as accounts_service
import app_service/service/contacts/service as contacts_service
import app_service/service/language/service as language_service
import app_service/service/chat/service as chat_service
import app_service/service/community/service as community_service
import app_service/service/message/service as message_service
import app_service/service/token/service as token_service
import app_service/service/collectible/service as collectible_service
import app_service/service/currency/service as currency_service
import app_service/service/transaction/service as transaction_service
import app_service/service/wallet_account/service as wallet_account_service
import app_service/service/wallet_connect/service as wallet_connect_service
import app_service/service/bookmarks/service as bookmark_service
import app_service/service/dapp_permissions/service as dapp_permissions_service
import app_service/service/privacy/service as privacy_service
import app_service/service/provider/service as provider_service
import app_service/service/node/service as node_service
import app_service/service/profile/service as profile_service
import app_service/service/settings/service as settings_service
import app_service/service/stickers/service as stickers_service
import app_service/service/about/service as about_service
import app_service/service/node_configuration/service as node_configuration_service
import app_service/service/network/service as network_service
import app_service/service/activity_center/service as activity_center_service
import app_service/service/saved_address/service as saved_address_service
import app_service/service/devices/service as devices_service
import app_service/service/mailservers/service as mailservers_service
import app_service/service/gif/service as gif_service
import app_service/service/ens/service as ens_service
import app_service/service/community_tokens/service as tokens_service
import app_service/service/network_connection/service as network_connection_service
import app_service/service/shared_urls/service as shared_urls_service

import app/modules/shared_modules/keycard_popup/module as keycard_shared_module
import app/modules/startup/module as startup_module
import app/modules/main/module as main_module
import app/core/notifications/notifications_manager
import app/global/global_singleton
import app/global/app_signals
import app/core/[main]

import ../core/[main]
import constants as main_constants

logScope:
topics = "app-controller"
Expand Down Expand Up @@ -80,6 +81,7 @@ type
currencyService: currency_service.Service
transactionService: transaction_service.Service
walletAccountService: wallet_account_service.Service
walletConnectService: wallet_connect_service.Service
bookmarkService: bookmark_service.Service
dappPermissionsService: dapp_permissions_service.Service
providerService: provider_service.Service
Expand Down Expand Up @@ -190,6 +192,7 @@ proc newAppController*(statusFoundation: StatusFoundation): AppController =
statusFoundation.events, statusFoundation.threadpool, result.settingsService, result.accountsService,
result.tokenService, result.networkService, result.currencyService
)
result.walletConnectService = wallet_connect_service.newService(statusFoundation.events, statusFoundation.threadpool)
result.messageService = message_service.newService(
statusFoundation.events,
statusFoundation.threadpool,
Expand Down Expand Up @@ -324,6 +327,7 @@ proc delete*(self: AppController) =
self.tokenService.delete
self.transactionService.delete
self.walletAccountService.delete
self.walletConnectService.delete
self.aboutService.delete
self.networkService.delete
self.activityCenterService.delete
Expand Down Expand Up @@ -451,6 +455,7 @@ proc load(self: AppController) =
self.collectibleService.init()
self.currencyService.init()
self.walletAccountService.init()
self.walletConnectService.init()

# Apply runtime log level settings
if not main_constants.runtimeLogLevelSet():
Expand Down
2 changes: 1 addition & 1 deletion src/app/modules/main/wallet_section/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import ./send/module as send_module

import ./activity/controller as activityc
import ./activity/details_controller as activity_detailsc
import ./wallet_connect/controller as wcc
import ./poc_wallet_connect/controller as wcc

import app/modules/shared_modules/collectible_details/controller as collectible_detailsc

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
################################################################################
# WalletConnect POC - to remove this file
################################################################################

import NimQml, strutils, json, chronicles

import backend/wallet as backend_wallet
import backend/wallet_connect as backend_wallet_connect
import backend/poc_wallet_connect as backend_wallet_connect

import app/global/global_singleton
import app/global/app_signals
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
################################################################################
# WalletConnect POC - to remove this file
################################################################################

import json, strutils
import uri

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
################################################################################
# WalletConnect POC - to remove this file
################################################################################

import json

include app_service/common/json_utils
Expand Down
2 changes: 1 addition & 1 deletion src/app/modules/main/wallet_section/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ./activity/details_controller as activity_detailsc
import app/modules/shared_modules/collectible_details/controller as collectible_detailsc
import ./io_interface
import ../../shared_models/currency_amount
import ./wallet_connect/controller as wcc
import ./poc_wallet_connect/controller as wcc

type
ActivityControllerArray* = array[2, activityc.Controller]
Expand Down
32 changes: 32 additions & 0 deletions src/app/modules/shared_modules/wallet_connect/controller.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import chronicles
import io_interface

import app/core/eventemitter
import app_service/service/wallet_account/service as wallet_account_service
import app_service/service/wallet_connect/service as wallet_connect_service

logScope:
topics = "wallet-connect-controller"

type
Controller* = ref object of RootObj
delegate: io_interface.AccessInterface
events: EventEmitter
walletAccountService: wallet_account_service.Service
walletConnectService: wallet_connect_service.Service

proc newController*(delegate: io_interface.AccessInterface,
events: EventEmitter,
walletAccountService: wallet_account_service.Service,
walletConnectService: wallet_connect_service.Service): Controller =
result = Controller()
result.delegate = delegate
result.events = events
result.walletAccountService = walletAccountService
result.walletConnectService = walletConnectService

proc delete*(self: Controller) =
self.disconnectAll()

proc init*(self: Controller) =
discard
14 changes: 14 additions & 0 deletions src/app/modules/shared_modules/wallet_connect/io_interface.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import NimQml

type
AccessInterface* {.pure inheritable.} = ref object of RootObj

method delete*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

method getModuleAsVariant*(self: AccessInterface): QVariant {.base.} =
raise newException(ValueError, "No implementation available")


type
DelegateInterface* = concept c
49 changes: 49 additions & 0 deletions src/app/modules/shared_modules/wallet_connect/module.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import NimQml, chronicles

import io_interface
import view, controller
import app/core/eventemitter

import app_service/service/wallet_account/service as wallet_account_service
import app_service/service/wallet_connect/service as wallet_connect_service
import app_service/service/keychain/service as keychain_service

export io_interface

logScope:
topics = "wallet-connect-module"

type
Module*[T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface
delegate: T
view: View
viewVariant: QVariant
controller: Controller

proc newModule*[T](delegate: T,
uniqueIdentifier: string,
events: EventEmitter,
walletAccountService: wallet_account_service.Service,
walletConnectService: wallet_connect_service.Service):
Module[T] =
result = Module[T]()
result.delegate = delegate
result.view = view.newView(result)
result.viewVariant = newQVariant(result.view)
result.controller = controller.newController(result, walletAccountService, walletConnectService)

{.push warning[Deprecated]: off.}

method delete*[T](self: Module[T]) =
self.view.delete
self.viewVariant.delete
self.controller.delete

proc init[T](self: Module[T], fullConnect = true) =
self.controller.init()

method getModuleAsVariant*[T](self: Module[T]): QVariant =
return self.viewVariant


{.pop.}
15 changes: 15 additions & 0 deletions src/app/modules/shared_modules/wallet_connect/view.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import NimQml
import io_interface

QtObject:
type
View* = ref object of QObject
delegate: io_interface.AccessInterface

proc delete*(self: View) =
self.QObject.delete

proc newView*(delegate: io_interface.AccessInterface): View =
new(result, delete)
result.QObject.setup
result.delegate = delegate
3 changes: 3 additions & 0 deletions src/app_service/service/wallet_connect/async_tasks.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#################################################
# Async
#################################################
34 changes: 34 additions & 0 deletions src/app_service/service/wallet_connect/service.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import NimQml, chronicles

# import backend/wallet_connect as status_go_wallet_connect

import app/global/global_singleton

import app/core/eventemitter
import app/core/signals/types
import app/core/tasks/[threadpool]

logScope:
topics = "wallet-connect-service"

# include async_tasks

QtObject:
type Service* = ref object of QObject
events: EventEmitter
threadpool: ThreadPool

proc delete*(self: Service) =
self.QObject.delete

proc newService*(
events: EventEmitter,
threadpool: ThreadPool,
): Service =
new(result, delete)
result.QObject.setup
result.events = events
result.threadpool = threadpool

proc init*(self: Service) =
discard

0 comments on commit dfc7bec

Please sign in to comment.