diff --git a/src/app/boot/app_controller.nim b/src/app/boot/app_controller.nim index a3f4e25106..2b0bad37c9 100644 --- a/src/app/boot/app_controller.nim +++ b/src/app/boot/app_controller.nim @@ -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 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 ../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/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" @@ -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 @@ -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, @@ -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 @@ -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(): diff --git a/src/app/modules/main/wallet_section/module.nim b/src/app/modules/main/wallet_section/module.nim index d415c25c91..68fa09addd 100644 --- a/src/app/modules/main/wallet_section/module.nim +++ b/src/app/modules/main/wallet_section/module.nim @@ -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 diff --git a/src/app/modules/main/wallet_section/wallet_connect/controller.nim b/src/app/modules/main/wallet_section/poc_wallet_connect/controller.nim similarity index 97% rename from src/app/modules/main/wallet_section/wallet_connect/controller.nim rename to src/app/modules/main/wallet_section/poc_wallet_connect/controller.nim index 36c667bcf6..8c3abf5cbb 100644 --- a/src/app/modules/main/wallet_section/wallet_connect/controller.nim +++ b/src/app/modules/main/wallet_section/poc_wallet_connect/controller.nim @@ -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 diff --git a/src/app/modules/main/wallet_section/wallet_connect/helpers.nim b/src/app/modules/main/wallet_section/poc_wallet_connect/helpers.nim similarity index 86% rename from src/app/modules/main/wallet_section/wallet_connect/helpers.nim rename to src/app/modules/main/wallet_section/poc_wallet_connect/helpers.nim index 889dd3ce36..6dc1339c58 100644 --- a/src/app/modules/main/wallet_section/wallet_connect/helpers.nim +++ b/src/app/modules/main/wallet_section/poc_wallet_connect/helpers.nim @@ -1,3 +1,7 @@ +################################################################################ +# WalletConnect POC - to remove this file +################################################################################ + import json, strutils import uri diff --git a/src/app/modules/main/wallet_section/wallet_connect/tx_response_dto.nim b/src/app/modules/main/wallet_section/poc_wallet_connect/tx_response_dto.nim similarity index 76% rename from src/app/modules/main/wallet_section/wallet_connect/tx_response_dto.nim rename to src/app/modules/main/wallet_section/poc_wallet_connect/tx_response_dto.nim index 915c831b33..10196dc260 100644 --- a/src/app/modules/main/wallet_section/wallet_connect/tx_response_dto.nim +++ b/src/app/modules/main/wallet_section/poc_wallet_connect/tx_response_dto.nim @@ -1,3 +1,7 @@ +################################################################################ +# WalletConnect POC - to remove this file +################################################################################ + import json include app_service/common/json_utils diff --git a/src/app/modules/main/wallet_section/view.nim b/src/app/modules/main/wallet_section/view.nim index 58f52f4e09..65b36865af 100644 --- a/src/app/modules/main/wallet_section/view.nim +++ b/src/app/modules/main/wallet_section/view.nim @@ -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] diff --git a/src/app/modules/shared_modules/wallet_connect/controller.nim b/src/app/modules/shared_modules/wallet_connect/controller.nim new file mode 100644 index 0000000000..68285316aa --- /dev/null +++ b/src/app/modules/shared_modules/wallet_connect/controller.nim @@ -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 \ No newline at end of file diff --git a/src/app/modules/shared_modules/wallet_connect/io_interface.nim b/src/app/modules/shared_modules/wallet_connect/io_interface.nim new file mode 100644 index 0000000000..9d6679ac3c --- /dev/null +++ b/src/app/modules/shared_modules/wallet_connect/io_interface.nim @@ -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 diff --git a/src/app/modules/shared_modules/wallet_connect/module.nim b/src/app/modules/shared_modules/wallet_connect/module.nim new file mode 100644 index 0000000000..c8c51e7532 --- /dev/null +++ b/src/app/modules/shared_modules/wallet_connect/module.nim @@ -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.} diff --git a/src/app/modules/shared_modules/wallet_connect/view.nim b/src/app/modules/shared_modules/wallet_connect/view.nim new file mode 100644 index 0000000000..1b1e8044e3 --- /dev/null +++ b/src/app/modules/shared_modules/wallet_connect/view.nim @@ -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 \ No newline at end of file diff --git a/src/app_service/service/wallet_connect/async_tasks.nim b/src/app_service/service/wallet_connect/async_tasks.nim new file mode 100644 index 0000000000..661a54e173 --- /dev/null +++ b/src/app_service/service/wallet_connect/async_tasks.nim @@ -0,0 +1,3 @@ +################################################# +# Async +################################################# diff --git a/src/app_service/service/wallet_connect/service.nim b/src/app_service/service/wallet_connect/service.nim new file mode 100644 index 0000000000..f539eedcf3 --- /dev/null +++ b/src/app_service/service/wallet_connect/service.nim @@ -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 \ No newline at end of file diff --git a/src/backend/poc_wallet_connect.nim b/src/backend/poc_wallet_connect.nim new file mode 100644 index 0000000000..d3d61d1413 --- /dev/null +++ b/src/backend/poc_wallet_connect.nim @@ -0,0 +1,97 @@ +################################################################################ +# WalletConnect POC - to remove this file +################################################################################ + +import options, logging +import json +import core, response_type + +from gen import rpc +import backend + +# Declared in services/wallet/walletconnect/walletconnect.go +const eventWCProposeUserPair*: string = "WalletConnectProposeUserPair" + +# Declared in services/wallet/walletconnect/walletconnect.go +const ErrorChainsNotSupported*: string = "chains not supported" + +rpc(wCSignMessage, "wallet"): + message: string + address: string + password: string + +rpc(wCBuildRawTransaction, "wallet"): + signature: string + + +rpc(wCSendTransactionWithSignature, "wallet"): + signature: string + +rpc(wCPairSessionProposal, "wallet"): + sessionProposalJson: string + +rpc(wCSaveOrUpdateSession, "wallet"): + sessionJson: string + +rpc(wCChangeSessionState, "wallet"): + topic: string + active: bool + +rpc(wCSessionRequest, "wallet"): + sessionRequestJson: string + +rpc(wCAuthRequest, "wallet"): + address: string + message: string + + +proc isErrorResponse(rpcResponse: RpcResponse[JsonNode]): bool = + return not rpcResponse.error.isNil + +proc prepareResponse(res: var JsonNode, rpcResponse: RpcResponse[JsonNode]): string = + if isErrorResponse(rpcResponse): + return rpcResponse.error.message + if rpcResponse.result.isNil: + return "no result" + res = rpcResponse.result + +# TODO #12434: async answer +proc pair*(res: var JsonNode, sessionProposalJson: string): string = + try: + let response = wCPairSessionProposal(sessionProposalJson) + return prepareResponse(res, response) + except Exception as e: + warn e.msg + return e.msg + +proc saveOrUpdateSession*(sessionJson: string): bool = + try: + let response = wCSaveOrUpdateSession(sessionJson) + return not isErrorResponse(response) + except Exception as e: + warn e.msg + return false + +proc deleteSession*(topic: string): bool = + try: + let response = wCChangeSessionState(topic, false) + return not isErrorResponse(response) + except Exception as e: + warn e.msg + return false + +proc sessionRequest*(res: var JsonNode, sessionRequestJson: string): string = + try: + let response = wCSessionRequest(sessionRequestJson) + return prepareResponse(res, response) + except Exception as e: + warn e.msg + return e.msg + +proc authRequest*(res: var JsonNode, address: string, authMessage: string): string = + try: + let response = wCAuthRequest(address, authMessage) + return prepareResponse(res, response) + except Exception as e: + warn e.msg + return e.msg \ No newline at end of file diff --git a/src/backend/wallet_connect.nim b/src/backend/wallet_connect.nim index aad94dc63c..56966c4776 100644 --- a/src/backend/wallet_connect.nim +++ b/src/backend/wallet_connect.nim @@ -1,93 +1,2 @@ -import options, logging import json import core, response_type - -from gen import rpc -import backend - -# Declared in services/wallet/walletconnect/walletconnect.go -const eventWCProposeUserPair*: string = "WalletConnectProposeUserPair" - -# Declared in services/wallet/walletconnect/walletconnect.go -const ErrorChainsNotSupported*: string = "chains not supported" - -rpc(wCSignMessage, "wallet"): - message: string - address: string - password: string - -rpc(wCBuildRawTransaction, "wallet"): - signature: string - - -rpc(wCSendTransactionWithSignature, "wallet"): - signature: string - -rpc(wCPairSessionProposal, "wallet"): - sessionProposalJson: string - -rpc(wCSaveOrUpdateSession, "wallet"): - sessionJson: string - -rpc(wCChangeSessionState, "wallet"): - topic: string - active: bool - -rpc(wCSessionRequest, "wallet"): - sessionRequestJson: string - -rpc(wCAuthRequest, "wallet"): - address: string - message: string - - -proc isErrorResponse(rpcResponse: RpcResponse[JsonNode]): bool = - return not rpcResponse.error.isNil - -proc prepareResponse(res: var JsonNode, rpcResponse: RpcResponse[JsonNode]): string = - if isErrorResponse(rpcResponse): - return rpcResponse.error.message - if rpcResponse.result.isNil: - return "no result" - res = rpcResponse.result - -# TODO #12434: async answer -proc pair*(res: var JsonNode, sessionProposalJson: string): string = - try: - let response = wCPairSessionProposal(sessionProposalJson) - return prepareResponse(res, response) - except Exception as e: - warn e.msg - return e.msg - -proc saveOrUpdateSession*(sessionJson: string): bool = - try: - let response = wCSaveOrUpdateSession(sessionJson) - return not isErrorResponse(response) - except Exception as e: - warn e.msg - return false - -proc deleteSession*(topic: string): bool = - try: - let response = wCChangeSessionState(topic, false) - return not isErrorResponse(response) - except Exception as e: - warn e.msg - return false - -proc sessionRequest*(res: var JsonNode, sessionRequestJson: string): string = - try: - let response = wCSessionRequest(sessionRequestJson) - return prepareResponse(res, response) - except Exception as e: - warn e.msg - return e.msg - -proc authRequest*(res: var JsonNode, address: string, authMessage: string): string = - try: - let response = wCAuthRequest(address, authMessage) - return prepareResponse(res, response) - except Exception as e: - warn e.msg - return e.msg \ No newline at end of file diff --git a/storybook/stubs/AppLayouts/Wallet/views/walletconnect/src/index.html b/storybook/stubs/AppLayouts/Wallet/views/walletconnect/src/index.html index 247e63e2a3..dba7580200 100644 --- a/storybook/stubs/AppLayouts/Wallet/views/walletconnect/src/index.html +++ b/storybook/stubs/AppLayouts/Wallet/views/walletconnect/src/index.html @@ -4,7 +4,7 @@
- +