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 ../modules/main/module as main_module
|
||||||
import ../core/notifications/notifications_manager
|
import ../core/notifications/notifications_manager
|
||||||
import ../../constants as main_constants
|
import ../../constants as main_constants
|
||||||
import ../global/global_singleton
|
import app/global/global_singleton
|
||||||
|
import app/global/app_signals
|
||||||
|
|
||||||
import ../core/[main]
|
import ../core/[main]
|
||||||
|
|
||||||
@ -377,6 +378,9 @@ proc checkForStoringPasswordToKeychain(self: AppController) =
|
|||||||
else:
|
else:
|
||||||
self.keychainService.storeData(account.keyUid, self.startupModule.getPin())
|
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) =
|
proc startupDidLoad*(self: AppController) =
|
||||||
singletonInstance.engine.setRootContextProperty("localAppSettings", self.localAppSettingsVariant)
|
singletonInstance.engine.setRootContextProperty("localAppSettings", self.localAppSettingsVariant)
|
||||||
singletonInstance.engine.setRootContextProperty("localAccountSettings", self.localAccountSettingsVariant)
|
singletonInstance.engine.setRootContextProperty("localAccountSettings", self.localAccountSettingsVariant)
|
||||||
@ -392,6 +396,7 @@ proc mainDidLoad*(self: AppController) =
|
|||||||
self.applyNecessaryActionsAfterLoggingIn()
|
self.applyNecessaryActionsAfterLoggingIn()
|
||||||
self.startupModule.moveToAppState()
|
self.startupModule.moveToAppState()
|
||||||
self.checkForStoringPasswordToKeychain()
|
self.checkForStoringPasswordToKeychain()
|
||||||
|
self.chekForWalletConnectPairings()
|
||||||
|
|
||||||
proc start*(self: AppController) =
|
proc start*(self: AppController) =
|
||||||
self.keycardService.init()
|
self.keycardService.init()
|
||||||
|
@ -12,7 +12,7 @@ const TOGGLE_SECTION* = "toggleSection"
|
|||||||
## Emmiting this signal will turn on section/s with passed `sectionType` if that section type is
|
## 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.
|
## turned off, or turn it off in case that section type is turned on.
|
||||||
|
|
||||||
type
|
type
|
||||||
ActiveSectionChatArgs* = ref object of Args
|
ActiveSectionChatArgs* = ref object of Args
|
||||||
sectionId*: string
|
sectionId*: string
|
||||||
chatId*: 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
|
## 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
|
## it will make that chat an active one and at the end if `messageId` is set it will point to
|
||||||
## that message.
|
## that message.
|
||||||
|
|
||||||
|
|
||||||
type
|
type
|
||||||
StatusUrlAction* {.pure.} = enum
|
StatusUrlAction* {.pure.} = enum
|
||||||
@ -31,7 +31,7 @@ type
|
|||||||
OpenCommunity,
|
OpenCommunity,
|
||||||
OpenCommunityChannel
|
OpenCommunityChannel
|
||||||
|
|
||||||
type
|
type
|
||||||
StatusUrlArgs* = ref object of Args
|
StatusUrlArgs* = ref object of Args
|
||||||
action*: StatusUrlAction
|
action*: StatusUrlAction
|
||||||
communityId*:string
|
communityId*:string
|
||||||
@ -40,4 +40,6 @@ type
|
|||||||
userId*: string # can be public key or ens name
|
userId*: string # can be public key or ens name
|
||||||
|
|
||||||
const SIGNAL_STATUS_URL_ACTIVATED* = "statusUrlActivated"
|
const SIGNAL_STATUS_URL_ACTIVATED* = "statusUrlActivated"
|
||||||
const FAKE_LOADING_SCREEN_FINISHED* = "fakeLoadingScreenFinished"
|
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 backend/wallet_connect as backend_wallet_connect
|
||||||
|
|
||||||
import app/global/global_singleton
|
import app/global/global_singleton
|
||||||
|
import app/global/app_signals
|
||||||
import app/core/eventemitter
|
import app/core/eventemitter
|
||||||
import app/core/signals/types
|
import app/core/signals/types
|
||||||
import app/global/app_signals
|
import app/global/app_signals
|
||||||
@ -34,18 +35,19 @@ QtObject:
|
|||||||
|
|
||||||
## Forward declarations
|
## Forward declarations
|
||||||
proc invalidateData(self: Controller)
|
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 onDataSigned(self: Controller, keyUid: string, path: string, r: string, s: string, v: string, pin: string, identifier: string)
|
||||||
proc finishSessionRequest(self: Controller, signature: string)
|
proc finishSessionRequest(self: Controller, signature: string)
|
||||||
proc finishAuthRequest(self: Controller, signature: string)
|
proc finishAuthRequest(self: Controller, signature: string)
|
||||||
|
|
||||||
## signals
|
## signals
|
||||||
|
proc checkPairings*(self: Controller) {.signal.}
|
||||||
proc requestOpenWalletConnectPopup*(self: Controller, uri: string) {.signal.}
|
proc requestOpenWalletConnectPopup*(self: Controller, uri: string) {.signal.}
|
||||||
proc hasActivePairingsChanged*(self: Controller) {.signal.}
|
proc hasActivePairingsChanged*(self: Controller) {.signal.}
|
||||||
proc respondSessionProposal*(self: Controller, sessionProposalJson: string, supportedNamespacesJson: string, error: string) {.signal.}
|
proc respondSessionProposal*(self: Controller, sessionProposalJson: string, supportedNamespacesJson: string, error: string) {.signal.}
|
||||||
proc respondSessionRequest*(self: Controller, sessionRequestJson: string, signedJson: string, error: bool) {.signal.}
|
proc respondSessionRequest*(self: Controller, sessionRequestJson: string, signedJson: string, error: bool) {.signal.}
|
||||||
proc respondAuthRequest*(self: Controller, signature: string, error: bool) {.signal.}
|
proc respondAuthRequest*(self: Controller, signature: string, error: bool) {.signal.}
|
||||||
|
|
||||||
|
|
||||||
proc setup(self: Controller) =
|
proc setup(self: Controller) =
|
||||||
self.QObject.setup
|
self.QObject.setup
|
||||||
|
|
||||||
@ -61,6 +63,10 @@ QtObject:
|
|||||||
if found:
|
if found:
|
||||||
self.requestOpenWalletConnectPopup(wcUri)
|
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):
|
self.events.on(SIGNAL_SHARED_KEYCARD_MODULE_DATA_SIGNED) do(e: Args):
|
||||||
let args = SharedKeycarModuleArgs(e)
|
let args = SharedKeycarModuleArgs(e)
|
||||||
if args.uniqueIdentifier != UNIQUE_WC_SESSION_REQUEST_SIGNING_IDENTIFIER and
|
if args.uniqueIdentifier != UNIQUE_WC_SESSION_REQUEST_SIGNING_IDENTIFIER and
|
||||||
@ -121,12 +127,13 @@ QtObject:
|
|||||||
proc getHasActivePairings*(self: Controller): bool {.slot.} =
|
proc getHasActivePairings*(self: Controller): bool {.slot.} =
|
||||||
return self.hasActivePairings
|
return self.hasActivePairings
|
||||||
|
|
||||||
proc setHasActivePairings(self: Controller, value: bool) =
|
proc setHasActivePairings*(self: Controller, value: bool) {.slot.} =
|
||||||
self.hasActivePairings = value
|
self.hasActivePairings = value
|
||||||
self.hasActivePairingsChanged()
|
self.hasActivePairingsChanged()
|
||||||
|
|
||||||
QtProperty[bool] hasActivePairings:
|
QtProperty[bool] hasActivePairings:
|
||||||
read = getHasActivePairings
|
read = getHasActivePairings
|
||||||
|
write = setHasActivePairings
|
||||||
notify = hasActivePairingsChanged
|
notify = hasActivePairingsChanged
|
||||||
|
|
||||||
proc sendTransactionAndRespond(self: Controller, signature: string) =
|
proc sendTransactionAndRespond(self: Controller, signature: string) =
|
||||||
|
@ -274,6 +274,8 @@ Popup {
|
|||||||
sdk.pair(d.pairModalUriWhenReady)
|
sdk.pair(d.pairModalUriWhenReady)
|
||||||
d.pairModalUriWhenReady = ""
|
d.pairModalUriWhenReady = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
d.checkForPairings()
|
||||||
}
|
}
|
||||||
|
|
||||||
function onSdkInit(success, info) {
|
function onSdkInit(success, info) {
|
||||||
@ -420,6 +422,7 @@ Popup {
|
|||||||
QtObject {
|
QtObject {
|
||||||
id: d
|
id: d
|
||||||
|
|
||||||
|
property bool checkPairings: false
|
||||||
property string selectedAddress: ""
|
property string selectedAddress: ""
|
||||||
property var observedData: null
|
property var observedData: null
|
||||||
property var authMessage: null
|
property var authMessage: null
|
||||||
@ -436,6 +439,24 @@ Popup {
|
|||||||
readonly property string waitingUserResponseToAuthRequest: "waiting_user_response_to_auth_request"
|
readonly property string waitingUserResponseToAuthRequest: "waiting_user_response_to_auth_request"
|
||||||
readonly property string pairedState: "paired"
|
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) {
|
function setStatusText(message, textColor) {
|
||||||
statusText.text = message
|
statusText.text = message
|
||||||
if (textColor === undefined) {
|
if (textColor === undefined) {
|
||||||
@ -506,5 +527,10 @@ Popup {
|
|||||||
|
|
||||||
root.sdk.authApprove(d.observedData, d.selectedAddress, signature)
|
root.sdk.authApprove(d.observedData, d.selectedAddress, signature)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onCheckPairings() {
|
||||||
|
d.checkPairings = true
|
||||||
|
d.checkForPairings()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,10 @@ Item {
|
|||||||
wcCalls.pair(pairLink)
|
wcCalls.pair(pairLink)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getPairings(callback) {
|
||||||
|
wcCalls.getPairings(callback)
|
||||||
|
}
|
||||||
|
|
||||||
function getActiveSessions(callback) {
|
function getActiveSessions(callback) {
|
||||||
wcCalls.getActiveSessions(callback)
|
wcCalls.getActiveSessions(callback)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user