2024-05-06 17:55:11 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Controls 2.15
|
|
|
|
import QtQuick.Layouts 1.15
|
|
|
|
|
2024-06-29 20:24:05 +00:00
|
|
|
import StatusQ 0.1
|
|
|
|
import SortFilterProxyModel 0.2
|
|
|
|
|
2024-05-06 17:55:11 +00:00
|
|
|
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
|
|
|
|
2024-06-19 13:13:32 +00:00
|
|
|
DappsComboBox {
|
2024-05-06 17:55:11 +00:00
|
|
|
id: root
|
|
|
|
|
2024-05-06 20:22:43 +00:00
|
|
|
required property WalletConnectService wcService
|
|
|
|
|
|
|
|
signal pairWCReady()
|
2024-05-06 17:55:11 +00:00
|
|
|
|
2024-06-19 13:13:32 +00:00
|
|
|
model: root.wcService.dappsModel
|
2024-05-06 17:55:11 +00:00
|
|
|
|
2024-06-19 13:13:32 +00:00
|
|
|
onPairDapp: {
|
|
|
|
pairWCLoader.active = true
|
|
|
|
}
|
2024-05-06 17:55:11 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-06 20:22:43 +00:00
|
|
|
Loader {
|
|
|
|
id: connectDappLoader
|
|
|
|
|
|
|
|
active: false
|
|
|
|
|
|
|
|
property var dappChains: []
|
|
|
|
property var sessionProposal: null
|
|
|
|
property var availableNamespaces: null
|
|
|
|
property var sessionTopic: null
|
2024-06-29 20:24:05 +00:00
|
|
|
readonly property var proposalMedatada: !!sessionProposal
|
|
|
|
? sessionProposal.params.proposer.metadata
|
|
|
|
: { name: "", url: "", icons: [] }
|
2024-05-06 20:22:43 +00:00
|
|
|
|
|
|
|
sourceComponent: ConnectDAppModal {
|
|
|
|
visible: true
|
|
|
|
|
|
|
|
onClosed: connectDappLoader.active = false
|
2024-06-04 20:45:03 +00:00
|
|
|
accounts: root.wcService.validAccounts
|
2024-06-29 20:24:05 +00:00
|
|
|
flatNetworks: SortFilterProxyModel {
|
|
|
|
sourceModel: root.wcService.flatNetworks
|
|
|
|
filters: [
|
|
|
|
FastExpressionFilter {
|
|
|
|
inverted: true
|
|
|
|
expression: connectDappLoader.dappChains.indexOf(chainId) === -1
|
|
|
|
expectedRoles: ["chainId"]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
selectedAccountAddress: root.wcService.selectedAccountAddress
|
|
|
|
|
|
|
|
dAppUrl: proposalMedatada.url
|
|
|
|
dAppName: proposalMedatada.name
|
|
|
|
dAppIconUrl: !!proposalMedatada.icons && proposalMedatada.icons.length > 0 ? proposalMedatada.icons[0] : ""
|
2024-05-06 20:22:43 +00:00
|
|
|
|
|
|
|
onConnect: {
|
2024-06-15 21:33:12 +00:00
|
|
|
root.wcService.approvePairSession(sessionProposal, selectedChains, selectedAccount)
|
2024-05-06 20:22:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2024-06-12 13:48:44 +00:00
|
|
|
payloadData: request.data
|
2024-06-07 16:54:19 +00:00
|
|
|
method: request.method
|
2024-05-31 09:58:47 +00:00
|
|
|
maxFeesText: request.maxFeesText
|
2024-06-23 08:27:29 +00:00
|
|
|
maxFeesEthText: request.maxFeesEthText
|
|
|
|
enoughFunds: request.enoughFunds
|
2024-05-31 09:58:47 +00:00
|
|
|
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-18 19:45:56 +00:00
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: root.wcService.requestHandler
|
|
|
|
|
2024-06-23 08:27:29 +00:00
|
|
|
function onMaxFeesUpdated(maxFees, maxFeesWei, haveEnoughFunds, symbol) {
|
2024-06-18 19:45:56 +00:00
|
|
|
maxFeesText = `${maxFees.toFixed(2)} ${symbol}`
|
2024-06-23 08:27:29 +00:00
|
|
|
var ethStr = "?"
|
|
|
|
if (globalUtils) {
|
|
|
|
ethStr = globalUtils.wei2Eth(maxFeesWei, 9)
|
|
|
|
}
|
|
|
|
maxFeesEthText = `${ethStr} ETH`
|
|
|
|
enoughFunds = haveEnoughFunds
|
2024-06-18 19:45:56 +00:00
|
|
|
}
|
|
|
|
function onEstimatedTimeUpdated(minMinutes, maxMinutes) {
|
|
|
|
estimatedTimeText = qsTr("%1-%2mins").arg(minMinutes).arg(maxMinutes)
|
|
|
|
}
|
|
|
|
}
|
2024-05-31 09:58:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-04 20:45:03 +00:00
|
|
|
Connections {
|
|
|
|
target: root.wcService ? root.wcService.requestHandler : null
|
|
|
|
|
2024-06-12 13:48:44 +00:00
|
|
|
function onSessionRequestResult(request, isSuccess) {
|
2024-06-07 16:54:19 +00:00
|
|
|
if (isSuccess) {
|
|
|
|
sessionRequestLoader.active = false
|
|
|
|
} else {
|
|
|
|
// TODO #14762 handle the error case
|
|
|
|
}
|
2024-06-04 20:45:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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.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-06 20:22:43 +00:00
|
|
|
}
|
2024-05-06 17:55:11 +00:00
|
|
|
}
|