mirror of
https://github.com/status-im/status-desktop.git
synced 2025-01-09 13:56:10 +00:00
feat(walletconnect): check for potential WalletConnect pairings after the user logs in
Closes: #12993
This commit is contained in:
parent
969998dd3f
commit
e24e3d734c
@ -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()
|
||||
|
@ -41,3 +41,5 @@ type
|
||||
|
||||
const SIGNAL_STATUS_URL_ACTIVATED* = "statusUrlActivated"
|
||||
const FAKE_LOADING_SCREEN_FINISHED* = "fakeLoadingScreenFinished"
|
||||
|
||||
const WALLET_CONNECT_CHECK_PAIRINGS* = "walletConnectCheckPairings"
|
@ -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) =
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -44,6 +44,10 @@ Item {
|
||||
wcCalls.pair(pairLink)
|
||||
}
|
||||
|
||||
function getPairings(callback) {
|
||||
wcCalls.getPairings(callback)
|
||||
}
|
||||
|
||||
function getActiveSessions(callback) {
|
||||
wcCalls.getActiveSessions(callback)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user