diff --git a/src/app/boot/app_controller.nim b/src/app/boot/app_controller.nim index 4c2453239e..bbc67aaa28 100644 --- a/src/app/boot/app_controller.nim +++ b/src/app/boot/app_controller.nim @@ -39,7 +39,8 @@ 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 ../global/global_singleton +import app/global/global_singleton +import app/global/app_signals import ../core/[main] @@ -377,6 +378,9 @@ proc checkForStoringPasswordToKeychain(self: AppController) = else: self.keychainService.storeData(account.keyUid, self.startupModule.getPin()) +proc chekForWalletConnectPairings(self: AppController) = + self.statusFoundation.events.emit(WALLET_CONNECT_CHECK_PAIRINGS, Args()) + proc startupDidLoad*(self: AppController) = singletonInstance.engine.setRootContextProperty("localAppSettings", self.localAppSettingsVariant) singletonInstance.engine.setRootContextProperty("localAccountSettings", self.localAccountSettingsVariant) @@ -392,6 +396,7 @@ proc mainDidLoad*(self: AppController) = self.applyNecessaryActionsAfterLoggingIn() self.startupModule.moveToAppState() self.checkForStoringPasswordToKeychain() + self.chekForWalletConnectPairings() proc start*(self: AppController) = self.keycardService.init() diff --git a/src/app/global/app_signals.nim b/src/app/global/app_signals.nim index 32fbb83032..b8d1708132 100644 --- a/src/app/global/app_signals.nim +++ b/src/app/global/app_signals.nim @@ -12,7 +12,7 @@ const TOGGLE_SECTION* = "toggleSection" ## Emmiting this signal will turn on section/s with passed `sectionType` if that section type is ## turned off, or turn it off in case that section type is turned on. -type +type ActiveSectionChatArgs* = ref object of Args sectionId*: string chatId*: string @@ -22,7 +22,7 @@ const SIGNAL_MAKE_SECTION_CHAT_ACTIVE* = "makeSectionChatActive" ## Emmiting this signal will switch the app to passed `sectionId`, after that if `chatId` is set ## it will make that chat an active one and at the end if `messageId` is set it will point to ## that message. - + type StatusUrlAction* {.pure.} = enum @@ -31,7 +31,7 @@ type OpenCommunity, OpenCommunityChannel -type +type StatusUrlArgs* = ref object of Args action*: StatusUrlAction communityId*:string @@ -40,4 +40,6 @@ type userId*: string # can be public key or ens name const SIGNAL_STATUS_URL_ACTIVATED* = "statusUrlActivated" -const FAKE_LOADING_SCREEN_FINISHED* = "fakeLoadingScreenFinished" \ No newline at end of file +const FAKE_LOADING_SCREEN_FINISHED* = "fakeLoadingScreenFinished" + +const WALLET_CONNECT_CHECK_PAIRINGS* = "walletConnectCheckPairings" \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/wallet_connect/controller.nim b/src/app/modules/main/wallet_section/wallet_connect/controller.nim index dfa5271857..b17124ce4f 100644 --- a/src/app/modules/main/wallet_section/wallet_connect/controller.nim +++ b/src/app/modules/main/wallet_section/wallet_connect/controller.nim @@ -4,6 +4,7 @@ import backend/wallet as backend_wallet import backend/wallet_connect as backend_wallet_connect import app/global/global_singleton +import app/global/app_signals import app/core/eventemitter import app/core/signals/types import app/global/app_signals @@ -34,18 +35,19 @@ QtObject: ## Forward declarations proc invalidateData(self: Controller) + proc setHasActivePairings*(self: Controller, value: bool) proc onDataSigned(self: Controller, keyUid: string, path: string, r: string, s: string, v: string, pin: string, identifier: string) proc finishSessionRequest(self: Controller, signature: string) proc finishAuthRequest(self: Controller, signature: string) ## signals + proc checkPairings*(self: Controller) {.signal.} proc requestOpenWalletConnectPopup*(self: Controller, uri: string) {.signal.} proc hasActivePairingsChanged*(self: Controller) {.signal.} proc respondSessionProposal*(self: Controller, sessionProposalJson: string, supportedNamespacesJson: string, error: string) {.signal.} proc respondSessionRequest*(self: Controller, sessionRequestJson: string, signedJson: string, error: bool) {.signal.} proc respondAuthRequest*(self: Controller, signature: string, error: bool) {.signal.} - proc setup(self: Controller) = self.QObject.setup @@ -61,6 +63,10 @@ QtObject: if found: self.requestOpenWalletConnectPopup(wcUri) + self.events.on(WALLET_CONNECT_CHECK_PAIRINGS) do(e: Args): + self.setHasActivePairings(true) + self.checkPairings() + self.events.on(SIGNAL_SHARED_KEYCARD_MODULE_DATA_SIGNED) do(e: Args): let args = SharedKeycarModuleArgs(e) if args.uniqueIdentifier != UNIQUE_WC_SESSION_REQUEST_SIGNING_IDENTIFIER and @@ -121,12 +127,13 @@ QtObject: proc getHasActivePairings*(self: Controller): bool {.slot.} = return self.hasActivePairings - proc setHasActivePairings(self: Controller, value: bool) = + proc setHasActivePairings*(self: Controller, value: bool) {.slot.} = self.hasActivePairings = value self.hasActivePairingsChanged() QtProperty[bool] hasActivePairings: read = getHasActivePairings + write = setHasActivePairings notify = hasActivePairingsChanged proc sendTransactionAndRespond(self: Controller, signature: string) = diff --git a/ui/app/AppLayouts/Wallet/views/walletconnect/WalletConnectModal.qml b/ui/app/AppLayouts/Wallet/views/walletconnect/WalletConnectModal.qml index 0051a46588..1758234621 100644 --- a/ui/app/AppLayouts/Wallet/views/walletconnect/WalletConnectModal.qml +++ b/ui/app/AppLayouts/Wallet/views/walletconnect/WalletConnectModal.qml @@ -274,6 +274,8 @@ Popup { sdk.pair(d.pairModalUriWhenReady) d.pairModalUriWhenReady = "" } + + d.checkForPairings() } function onSdkInit(success, info) { @@ -420,6 +422,7 @@ Popup { QtObject { id: d + property bool checkPairings: false property string selectedAddress: "" property var observedData: null property var authMessage: null @@ -436,6 +439,24 @@ Popup { readonly property string waitingUserResponseToAuthRequest: "waiting_user_response_to_auth_request" readonly property string pairedState: "paired" + function checkForPairings() { + if (!d.checkPairings || !root.sdk.sdkReady) { + return + } + + d.checkPairings = false; + root.sdk.getPairings((pairings) => { + for (let i = 0; i < pairings.length; i++) { + if (pairings[i].active) { + // if there is at least a single active pairing we leave wallet connect sdk loaded + return; + } + } + // if there are no active pairings, we unload loaded sdk + root.controller.hasActivePairings = false; + }) + } + function setStatusText(message, textColor) { statusText.text = message if (textColor === undefined) { @@ -506,5 +527,10 @@ Popup { root.sdk.authApprove(d.observedData, d.selectedAddress, signature) } + + function onCheckPairings() { + d.checkPairings = true + d.checkForPairings() + } } } diff --git a/ui/app/AppLayouts/Wallet/views/walletconnect/WalletConnectSDK.qml b/ui/app/AppLayouts/Wallet/views/walletconnect/WalletConnectSDK.qml index 06fcc9fb6d..355be5e35e 100644 --- a/ui/app/AppLayouts/Wallet/views/walletconnect/WalletConnectSDK.qml +++ b/ui/app/AppLayouts/Wallet/views/walletconnect/WalletConnectSDK.qml @@ -44,6 +44,10 @@ Item { wcCalls.pair(pairLink) } + function getPairings(callback) { + wcCalls.getPairings(callback) + } + function getActiveSessions(callback) { wcCalls.getActiveSessions(callback) }