2024-05-06 17:55:11 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Controls 2.15
|
|
|
|
import QtQuick.Layouts 1.15
|
|
|
|
|
|
|
|
import AppLayouts.Wallet.controls 1.0
|
|
|
|
|
|
|
|
import shared.popups.walletconnect 1.0
|
2024-05-06 20:22:43 +00:00
|
|
|
import AppLayouts.Wallet.services.dapps 1.0
|
2024-05-31 09:58:47 +00:00
|
|
|
import AppLayouts.Wallet.services.dapps.types 1.0
|
2024-05-06 20:22:43 +00:00
|
|
|
|
|
|
|
import shared.stores 1.0
|
2024-05-31 09:34:59 +00:00
|
|
|
import utils 1.0
|
2024-05-06 17:55:11 +00:00
|
|
|
|
|
|
|
ConnectedDappsButton {
|
|
|
|
id: root
|
|
|
|
|
2024-05-06 20:22:43 +00:00
|
|
|
required property WalletConnectService wcService
|
|
|
|
|
2024-05-21 10:42:50 +00:00
|
|
|
signal dappsListReady()
|
2024-05-06 20:22:43 +00:00
|
|
|
signal pairWCReady()
|
2024-05-31 09:34:59 +00:00
|
|
|
signal displayToastMessage(string message, bool error)
|
2024-05-06 17:55:11 +00:00
|
|
|
|
|
|
|
onClicked: {
|
|
|
|
dappsListLoader.active = true
|
|
|
|
}
|
|
|
|
|
|
|
|
highlighted: dappsListLoader.active
|
|
|
|
|
|
|
|
Loader {
|
2024-05-06 20:22:43 +00:00
|
|
|
id: pairWCLoader
|
2024-05-06 17:55:11 +00:00
|
|
|
|
|
|
|
active: false
|
|
|
|
|
|
|
|
onLoaded: {
|
|
|
|
item.open()
|
2024-05-06 20:22:43 +00:00
|
|
|
root.pairWCReady()
|
2024-05-06 17:55:11 +00:00
|
|
|
}
|
|
|
|
|
2024-05-06 20:22:43 +00:00
|
|
|
sourceComponent: PairWCModal {
|
2024-05-06 17:55:11 +00:00
|
|
|
visible: true
|
|
|
|
|
2024-05-06 20:22:43 +00:00
|
|
|
onClosed: pairWCLoader.active = false
|
2024-05-06 17:55:11 +00:00
|
|
|
|
|
|
|
onPair: (uri) => {
|
2024-05-06 20:22:43 +00:00
|
|
|
root.wcService.pair(uri)
|
|
|
|
this.isPairing = true
|
2024-05-06 17:55:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Loader {
|
|
|
|
id: dappsListLoader
|
|
|
|
|
|
|
|
active: false
|
|
|
|
|
|
|
|
onLoaded: {
|
|
|
|
item.open()
|
2024-05-21 10:42:50 +00:00
|
|
|
root.dappsListReady()
|
2024-05-06 17:55:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sourceComponent: DAppsListPopup {
|
|
|
|
visible: true
|
|
|
|
|
2024-06-04 20:45:03 +00:00
|
|
|
model: root.wcService.dappsModel
|
2024-05-21 10:42:50 +00:00
|
|
|
|
2024-05-06 20:22:43 +00:00
|
|
|
onPairWCDapp: {
|
|
|
|
pairWCLoader.active = true
|
2024-05-06 17:55:11 +00:00
|
|
|
this.close()
|
|
|
|
}
|
2024-06-04 20:45:03 +00:00
|
|
|
|
2024-05-06 17:55:11 +00:00
|
|
|
onOpened: {
|
2024-05-21 10:42:50 +00:00
|
|
|
this.x = root.width - this.contentWidth - 2 * this.padding
|
2024-05-06 17:55:11 +00:00
|
|
|
this.y = root.height + 4
|
|
|
|
}
|
|
|
|
onClosed: dappsListLoader.active = false
|
|
|
|
}
|
|
|
|
}
|
2024-05-06 20:22:43 +00:00
|
|
|
|
|
|
|
Loader {
|
|
|
|
id: connectDappLoader
|
|
|
|
|
|
|
|
active: false
|
|
|
|
|
|
|
|
onLoaded: item.openWithFilter(dappChains, sessionProposal.params.proposer)
|
|
|
|
|
|
|
|
property var dappChains: []
|
|
|
|
property var sessionProposal: null
|
|
|
|
property var availableNamespaces: null
|
|
|
|
property var sessionTopic: null
|
|
|
|
|
|
|
|
sourceComponent: ConnectDAppModal {
|
|
|
|
visible: true
|
|
|
|
|
|
|
|
onClosed: connectDappLoader.active = false
|
2024-06-04 20:45:03 +00:00
|
|
|
accounts: root.wcService.validAccounts
|
|
|
|
flatNetworks: root.wcService.flatNetworks
|
2024-05-06 20:22:43 +00:00
|
|
|
|
|
|
|
onConnect: {
|
|
|
|
root.wcService.approvePairSession(sessionProposal, dappChains, selectedAccount)
|
|
|
|
}
|
|
|
|
|
|
|
|
onDecline: {
|
|
|
|
connectDappLoader.active = false
|
|
|
|
root.wcService.rejectPairSession(sessionProposal.id)
|
|
|
|
}
|
|
|
|
|
|
|
|
onDisconnect: {
|
|
|
|
connectDappLoader.active = false
|
|
|
|
root.wcService.disconnectDapp(sessionTopic)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-31 09:58:47 +00:00
|
|
|
Loader {
|
|
|
|
id: sessionRequestLoader
|
|
|
|
|
|
|
|
active: false
|
|
|
|
|
|
|
|
onLoaded: item.open()
|
|
|
|
|
|
|
|
property SessionRequestResolved request: null
|
|
|
|
|
|
|
|
sourceComponent: DAppRequestModal {
|
|
|
|
account: request.account
|
|
|
|
network: request.network
|
|
|
|
|
|
|
|
dappName: request.dappName
|
|
|
|
dappUrl: request.dappUrl
|
|
|
|
dappIcon: request.dappIcon
|
|
|
|
|
|
|
|
signContent: request.data.message
|
|
|
|
maxFeesText: request.maxFeesText
|
|
|
|
estimatedTimeText: request.estimatedTimeText
|
|
|
|
|
|
|
|
visible: true
|
|
|
|
|
|
|
|
onClosed: sessionRequestLoader.active = false
|
|
|
|
|
|
|
|
onSign: {
|
2024-06-04 20:45:03 +00:00
|
|
|
if (!request) {
|
|
|
|
console.error("Error signing: request is null")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
root.wcService.requestHandler.authenticate(request)
|
2024-05-31 09:58:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onReject: {
|
|
|
|
let userRejected = true
|
2024-06-04 20:45:03 +00:00
|
|
|
root.wcService.requestHandler.rejectSessionRequest(request, userRejected)
|
2024-05-31 09:58:47 +00:00
|
|
|
close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-04 20:45:03 +00:00
|
|
|
Connections {
|
|
|
|
target: root.wcService ? root.wcService.requestHandler : null
|
|
|
|
|
|
|
|
function onSessionRequestResult(payload, isSuccess) {
|
|
|
|
// TODO #14927 handle this properly
|
|
|
|
sessionRequestLoader.active = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-06 20:22:43 +00:00
|
|
|
Connections {
|
|
|
|
target: root.wcService
|
|
|
|
|
|
|
|
function onConnectDApp(dappChains, sessionProposal, availableNamespaces) {
|
|
|
|
connectDappLoader.dappChains = dappChains
|
|
|
|
connectDappLoader.sessionProposal = sessionProposal
|
|
|
|
connectDappLoader.availableNamespaces = availableNamespaces
|
|
|
|
connectDappLoader.sessionTopic = null
|
|
|
|
|
|
|
|
if (pairWCLoader.item) {
|
|
|
|
pairWCLoader.item.close()
|
|
|
|
}
|
|
|
|
|
|
|
|
connectDappLoader.active = true
|
|
|
|
}
|
|
|
|
|
|
|
|
function onApproveSessionResult(session, err) {
|
|
|
|
connectDappLoader.dappChains = []
|
|
|
|
connectDappLoader.sessionProposal = null
|
|
|
|
connectDappLoader.availableNamespaces = null
|
|
|
|
connectDappLoader.sessionTopic = session.topic
|
|
|
|
|
|
|
|
let modal = connectDappLoader.item
|
|
|
|
if (!!modal) {
|
|
|
|
if (err) {
|
|
|
|
modal.pairFailed(session, err)
|
|
|
|
} else {
|
|
|
|
modal.pairSuccessful(session)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-05-31 09:34:59 +00:00
|
|
|
|
2024-05-31 09:58:47 +00:00
|
|
|
function onSessionRequest(request) {
|
|
|
|
sessionRequestLoader.request = request
|
|
|
|
sessionRequestLoader.active = true
|
|
|
|
}
|
|
|
|
|
2024-05-31 09:34:59 +00:00
|
|
|
function onDisplayToastMessage(message, err) {
|
|
|
|
root.displayToastMessage(message, err)
|
|
|
|
}
|
2024-05-06 20:22:43 +00:00
|
|
|
}
|
2024-05-06 17:55:11 +00:00
|
|
|
}
|