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
|
2024-07-17 10:46:43 +00:00
|
|
|
import StatusQ.Core.Utils 0.1 as SQUtils
|
2024-06-29 20:24:05 +00:00
|
|
|
import SortFilterProxyModel 0.2
|
|
|
|
|
2024-07-09 17:49:00 +00:00
|
|
|
import AppLayouts.Wallet 1.0
|
2024-05-06 17:55:11 +00:00
|
|
|
import AppLayouts.Wallet.controls 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
|
|
|
|
2024-07-09 17:49:00 +00:00
|
|
|
import shared.popups.walletconnect 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-07-11 21:00:15 +00:00
|
|
|
// Values mapped to Constants.LoginType
|
|
|
|
required property int loginType
|
2024-10-03 18:15:24 +00:00
|
|
|
property var accountsModel
|
|
|
|
property var networksModel
|
|
|
|
property SessionRequestsModel sessionRequestsModel
|
2024-07-11 21:00:15 +00:00
|
|
|
property string selectedAccountAddress
|
2024-05-06 20:22:43 +00:00
|
|
|
|
2024-10-03 18:15:24 +00:00
|
|
|
property var formatBigNumber: (number, symbol, noSymbolOption) => console.error("formatBigNumber not set")
|
|
|
|
|
2024-05-06 20:22:43 +00:00
|
|
|
signal pairWCReady()
|
2024-05-06 17:55:11 +00:00
|
|
|
|
2024-10-03 18:15:24 +00:00
|
|
|
signal disconnectRequested(string connectionId)
|
|
|
|
signal pairingRequested(string uri)
|
|
|
|
signal pairingValidationRequested(string uri)
|
|
|
|
signal connectionAccepted(var pairingId, var chainIds, string selectedAccount)
|
|
|
|
signal connectionDeclined(var pairingId)
|
|
|
|
signal signRequestAccepted(string connectionId, string requestId)
|
|
|
|
signal signRequestRejected(string connectionId, string requestId)
|
|
|
|
|
|
|
|
/// Response to pairingValidationRequested
|
|
|
|
function pairingValidated(validationState) {
|
|
|
|
if (pairWCLoader.item) {
|
|
|
|
pairWCLoader.item.pairingValidated(validationState)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Confirmation received on connectionAccepted
|
|
|
|
function connectionSuccessful(pairingId, newConnectionId) {
|
|
|
|
connectDappLoader.connectionSuccessful(pairingId, newConnectionId)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Confirmation received on connectionAccepted
|
|
|
|
function connectionFailed(pairingId) {
|
|
|
|
connectDappLoader.connectionFailed(pairingId)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Request to connect to a dApp
|
|
|
|
function connectDApp(dappChains, dappUrl, dappName, dappIcon, pairingId) {
|
|
|
|
connectDappLoader.connect(dappChains, dappUrl, dappName, dappIcon, pairingId)
|
|
|
|
}
|
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
|
|
|
|
2024-06-24 21:26:53 +00:00
|
|
|
onDisconnectDapp: (dappUrl) => {
|
2024-07-15 09:23:35 +00:00
|
|
|
disconnectdAppDialogLoader.dAppUrl = dappUrl
|
|
|
|
disconnectdAppDialogLoader.active = true
|
|
|
|
}
|
|
|
|
|
|
|
|
Loader {
|
|
|
|
id: disconnectdAppDialogLoader
|
|
|
|
|
|
|
|
property string dAppUrl
|
|
|
|
|
|
|
|
active: false
|
|
|
|
|
|
|
|
onLoaded: {
|
2024-10-03 18:15:24 +00:00
|
|
|
const dApp = SQUtils.ModelUtils.getByKey(root.model, "url", dAppUrl);
|
2024-07-15 09:23:35 +00:00
|
|
|
if (dApp) {
|
|
|
|
item.dappName = dApp.name;
|
|
|
|
item.dappIcon = dApp.iconUrl;
|
|
|
|
item.dappUrl = disconnectdAppDialogLoader.dAppUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
item.open();
|
|
|
|
}
|
|
|
|
|
|
|
|
sourceComponent: DAppConfirmDisconnectPopup {
|
|
|
|
|
|
|
|
visible: true
|
|
|
|
|
|
|
|
onClosed: {
|
|
|
|
disconnectdAppDialogLoader.active = false
|
|
|
|
}
|
|
|
|
|
|
|
|
onAccepted: {
|
2024-10-03 18:15:24 +00:00
|
|
|
SQUtils.ModelUtils.forEach(model, (dApp) => {
|
|
|
|
if (dApp.url === dAppUrl) {
|
|
|
|
root.disconnectRequested(dApp.topic)
|
|
|
|
}
|
|
|
|
})
|
2024-07-15 09:23:35 +00:00
|
|
|
}
|
|
|
|
}
|
2024-06-24 21:26:53 +00:00
|
|
|
}
|
|
|
|
|
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-10-03 18:15:24 +00:00
|
|
|
onPair: (uri) => root.pairingRequested(uri)
|
|
|
|
onPairUriChanged: (uri) => root.pairingValidationRequested(uri)
|
2024-05-06 17:55:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-06 20:22:43 +00:00
|
|
|
Loader {
|
|
|
|
id: connectDappLoader
|
|
|
|
|
|
|
|
active: false
|
|
|
|
|
2024-10-03 18:15:24 +00:00
|
|
|
// Array of chaind ids
|
|
|
|
property var dappChains
|
|
|
|
property url dappUrl
|
|
|
|
property string dappName
|
|
|
|
property url dappIcon
|
|
|
|
property var key
|
|
|
|
property var topic
|
|
|
|
|
|
|
|
property var connectionQueue: []
|
|
|
|
onActiveChanged: {
|
|
|
|
if (!active && connectionQueue.length > 0) {
|
|
|
|
connect(connectionQueue[0].dappChains,
|
|
|
|
connectionQueue[0].dappUrl,
|
|
|
|
connectionQueue[0].dappName,
|
|
|
|
connectionQueue[0].dappIcon,
|
|
|
|
connectionQueue[0].key)
|
|
|
|
connectionQueue.shift()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function connect(dappChains, dappUrl, dappName, dappIcon, key) {
|
|
|
|
if (connectDappLoader.active) {
|
|
|
|
connectionQueue.push({ dappChains, dappUrl, dappName, dappIcon, key })
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
connectDappLoader.dappChains = dappChains
|
|
|
|
connectDappLoader.dappUrl = dappUrl
|
|
|
|
connectDappLoader.dappName = dappName
|
|
|
|
connectDappLoader.dappIcon = dappIcon
|
|
|
|
connectDappLoader.key = key
|
|
|
|
|
|
|
|
if (pairWCLoader.item) {
|
|
|
|
// Allow user to get the uri valid confirmation
|
|
|
|
pairWCLoader.item.pairingValidated(Pairing.errors.dappReadyForApproval)
|
|
|
|
connectDappTimer.start()
|
|
|
|
} else {
|
|
|
|
connectDappLoader.active = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function connectionSuccessful(key, newTopic) {
|
|
|
|
if (connectDappLoader.key === key && connectDappLoader.item) {
|
|
|
|
connectDappLoader.topic = newTopic
|
|
|
|
connectDappLoader.item.pairSuccessful()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function connectionFailed(id) {
|
|
|
|
if (connectDappLoader.key === key && connectDappLoader.item) {
|
|
|
|
connectDappLoader.item.pairFailed()
|
|
|
|
}
|
|
|
|
}
|
2024-05-06 20:22:43 +00:00
|
|
|
|
|
|
|
sourceComponent: ConnectDAppModal {
|
|
|
|
visible: true
|
2024-10-03 18:15:24 +00:00
|
|
|
|
2024-05-06 20:22:43 +00:00
|
|
|
onClosed: connectDappLoader.active = false
|
2024-10-03 18:15:24 +00:00
|
|
|
accounts: root.accountsModel
|
2024-06-29 20:24:05 +00:00
|
|
|
flatNetworks: SortFilterProxyModel {
|
2024-10-03 18:15:24 +00:00
|
|
|
sourceModel: root.networksModel
|
2024-06-29 20:24:05 +00:00
|
|
|
filters: [
|
|
|
|
FastExpressionFilter {
|
|
|
|
inverted: true
|
|
|
|
expression: connectDappLoader.dappChains.indexOf(chainId) === -1
|
|
|
|
expectedRoles: ["chainId"]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2024-07-11 21:00:15 +00:00
|
|
|
selectedAccountAddress: root.selectedAccountAddress
|
2024-06-29 20:24:05 +00:00
|
|
|
|
2024-10-03 18:15:24 +00:00
|
|
|
dAppUrl: connectDappLoader.dappUrl
|
|
|
|
dAppName: connectDappLoader.dappName
|
|
|
|
dAppIconUrl: connectDappLoader.dappIcon
|
2024-05-06 20:22:43 +00:00
|
|
|
|
|
|
|
onConnect: {
|
2024-10-03 18:15:24 +00:00
|
|
|
if (!selectedAccount || !selectedAccount.address) {
|
|
|
|
console.error("Missing account selection")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (!selectedChains || selectedChains.length === 0) {
|
|
|
|
console.error("Missing chain selection")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
root.connectionAccepted(connectDappLoader.key, selectedChains, selectedAccount.address)
|
2024-05-06 20:22:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onDecline: {
|
2024-10-03 18:15:24 +00:00
|
|
|
root.connectionDeclined(connectDappLoader.key)
|
|
|
|
close()
|
2024-05-06 20:22:43 +00:00
|
|
|
}
|
|
|
|
|
2024-10-03 18:15:24 +00:00
|
|
|
onDisconnect: {
|
|
|
|
root.disconnectRequested(connectDappLoader.topic)
|
|
|
|
close()
|
2024-05-06 20:22:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-03 18:15:24 +00:00
|
|
|
Instantiator {
|
|
|
|
model: root.sessionRequestsModel
|
|
|
|
delegate: DAppSignRequestModal {
|
2024-07-09 17:49:00 +00:00
|
|
|
id: dappRequestModal
|
2024-07-11 21:00:15 +00:00
|
|
|
objectName: "dappsRequestModal"
|
2024-05-31 09:58:47 +00:00
|
|
|
|
2024-10-03 18:15:24 +00:00
|
|
|
required property var model
|
|
|
|
required property int index
|
|
|
|
|
|
|
|
readonly property var request: model.requestItem
|
2024-09-17 07:42:01 +00:00
|
|
|
readonly property var account: accountEntry.available ? accountEntry.item : {
|
|
|
|
name: "",
|
|
|
|
address: "",
|
|
|
|
emoji: "",
|
2024-09-25 17:15:13 +00:00
|
|
|
colorId: 0,
|
|
|
|
migratedToKeycard: false
|
2024-09-17 07:42:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
readonly property var network: networkEntry.available ? networkEntry.item : {
|
|
|
|
chainName: "",
|
|
|
|
iconUrl: ""
|
|
|
|
}
|
2024-10-03 18:15:24 +00:00
|
|
|
property bool requestHandled: false
|
|
|
|
|
|
|
|
function rejectRequest() {
|
|
|
|
// Allow rejecting only once
|
|
|
|
if (requestHandled) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
requestHandled = true
|
|
|
|
let userRejected = true
|
|
|
|
root.signRequestRejected(request.topic, request.id)
|
|
|
|
}
|
|
|
|
|
|
|
|
parent: root
|
2024-09-17 07:42:01 +00:00
|
|
|
|
2024-09-25 17:15:13 +00:00
|
|
|
loginType: account.migratedToKeycard ? Constants.LoginType.Keycard : root.loginType
|
2024-10-03 18:15:24 +00:00
|
|
|
formatBigNumber: root.formatBigNumber
|
|
|
|
|
|
|
|
visible: !!request.dappUrl
|
2024-07-17 10:46:43 +00:00
|
|
|
|
2024-05-31 09:58:47 +00:00
|
|
|
dappUrl: request.dappUrl
|
|
|
|
dappIcon: request.dappIcon
|
2024-07-11 21:00:15 +00:00
|
|
|
dappName: request.dappName
|
2024-05-31 09:58:47 +00:00
|
|
|
|
2024-09-17 07:42:01 +00:00
|
|
|
accountColor: Utils.getColorForId(account.colorId)
|
|
|
|
accountName: account.name
|
|
|
|
accountAddress: account.address
|
|
|
|
accountEmoji: account.emoji
|
2024-07-11 21:00:15 +00:00
|
|
|
|
2024-09-17 07:42:01 +00:00
|
|
|
networkName: network.chainName
|
|
|
|
networkIconPath: Style.svg(network.iconUrl)
|
2024-07-11 21:00:15 +00:00
|
|
|
|
2024-10-03 18:15:24 +00:00
|
|
|
fiatFees: request.fiatMaxFees ? request.fiatMaxFees.toFixed() : ""
|
|
|
|
cryptoFees: request.ethMaxFees ? request.ethMaxFees.toFixed() : ""
|
|
|
|
estimatedTime: WalletUtils.getLabelForEstimatedTxTime(request.estimatedTimeCategory)
|
|
|
|
feesLoading: hasFees && (!fiatFees || !cryptoFees)
|
2024-07-11 21:00:15 +00:00
|
|
|
hasFees: signingTransaction
|
2024-10-03 18:15:24 +00:00
|
|
|
enoughFundsForTransaction: request.haveEnoughFunds
|
|
|
|
enoughFundsForFees: request.haveEnoughFees
|
2024-07-11 21:00:15 +00:00
|
|
|
|
2024-07-17 16:36:32 +00:00
|
|
|
signingTransaction: !!request.method && (request.method === SessionRequest.methods.signTransaction.name
|
|
|
|
|| request.method === SessionRequest.methods.sendTransaction.name)
|
|
|
|
requestPayload: request.preparedData
|
2024-10-03 18:15:24 +00:00
|
|
|
|
2024-07-15 17:30:27 +00:00
|
|
|
onClosed: {
|
2024-10-03 18:15:24 +00:00
|
|
|
Qt.callLater(rejectRequest)
|
2024-07-15 17:30:27 +00:00
|
|
|
}
|
2024-05-31 09:58:47 +00:00
|
|
|
|
2024-07-11 21:00:15 +00:00
|
|
|
onAccepted: {
|
2024-07-15 17:30:27 +00:00
|
|
|
requestHandled = true
|
2024-10-03 18:15:24 +00:00
|
|
|
root.signRequestAccepted(request.topic, request.id)
|
2024-05-31 09:58:47 +00:00
|
|
|
}
|
|
|
|
|
2024-07-11 21:00:15 +00:00
|
|
|
onRejected: {
|
2024-07-15 17:30:27 +00:00
|
|
|
rejectRequest()
|
|
|
|
}
|
|
|
|
|
2024-09-17 07:42:01 +00:00
|
|
|
ModelEntry {
|
|
|
|
id: accountEntry
|
2024-10-03 18:15:24 +00:00
|
|
|
sourceModel: root.accountsModel
|
2024-09-17 07:42:01 +00:00
|
|
|
key: "address"
|
|
|
|
value: request.accountAddress
|
|
|
|
}
|
|
|
|
|
|
|
|
ModelEntry {
|
|
|
|
id: networkEntry
|
2024-10-03 18:15:24 +00:00
|
|
|
sourceModel: root.networksModel
|
2024-09-17 07:42:01 +00:00
|
|
|
key: "chainId"
|
|
|
|
value: request.chainId
|
|
|
|
}
|
2024-05-31 09:58:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-24 15:37:08 +00:00
|
|
|
// Used between transitioning from PairWCModal to ConnectDAppModal
|
|
|
|
Timer {
|
|
|
|
id: connectDappTimer
|
|
|
|
|
|
|
|
interval: 500
|
|
|
|
running: false
|
|
|
|
repeat: false
|
|
|
|
|
|
|
|
onTriggered: {
|
|
|
|
pairWCLoader.item.close()
|
|
|
|
connectDappLoader.active = true
|
|
|
|
}
|
|
|
|
}
|
2024-05-06 17:55:11 +00:00
|
|
|
}
|