2024-05-06 20:22:43 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Controls 2.15
|
|
|
|
import QtQuick.Layouts 1.15
|
2024-07-29 08:41:47 +00:00
|
|
|
import QtQml.Models 2.15
|
2024-05-06 20:22:43 +00:00
|
|
|
import SortFilterProxyModel 0.2
|
|
|
|
|
|
|
|
import StatusQ 0.1
|
|
|
|
import StatusQ.Core 0.1
|
2024-06-15 21:33:12 +00:00
|
|
|
import StatusQ.Core.Utils 0.1
|
2024-05-06 20:22:43 +00:00
|
|
|
import StatusQ.Popups.Dialog 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
import StatusQ.Components 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
|
2024-06-07 12:27:56 +00:00
|
|
|
import shared.controls 1.0
|
2024-05-06 20:22:43 +00:00
|
|
|
// TODO extract the components to StatusQ
|
|
|
|
import shared.popups.send.controls 1.0
|
2024-07-04 13:32:04 +00:00
|
|
|
import shared.popups.walletconnect.controls 1.0
|
2024-05-06 20:22:43 +00:00
|
|
|
|
|
|
|
import AppLayouts.Wallet.controls 1.0
|
|
|
|
|
|
|
|
import utils 1.0
|
2024-06-29 20:24:05 +00:00
|
|
|
import shared.popups.walletconnect.private 1.0
|
2024-05-06 20:22:43 +00:00
|
|
|
|
|
|
|
StatusDialog {
|
|
|
|
id: root
|
|
|
|
|
2024-06-29 20:24:05 +00:00
|
|
|
/*
|
|
|
|
Accounts model
|
|
|
|
|
|
|
|
Expected model structure:
|
|
|
|
name [string] - account name e.g. "Piggy Bank"
|
|
|
|
address [string] - wallet account address e.g. "0x1234567890"
|
|
|
|
emoji [string] - emoji for account e.g. "🐷"
|
|
|
|
colorId [string] - color id for account e.g. "1"
|
|
|
|
currencyBalance [var] - fiat currency balance
|
|
|
|
amount [number] - amount of currency e.g. 1234
|
|
|
|
symbol [string] - currency symbol e.g. "USD"
|
|
|
|
optDisplayDecimals [number] - optional number of decimals to display
|
|
|
|
stripTrailingZeroes [bool] - strip trailing zeroes
|
|
|
|
walletType [string] - wallet type e.g. Constants.watchWalletType. See `Constants` for possible values
|
|
|
|
migratedToKeycard [bool] - whether account is migrated to keycard
|
|
|
|
accountBalance [var] - account balance for a specific network
|
|
|
|
formattedBalance [string] - formatted balance e.g. "1234.56B"
|
|
|
|
balance [string] - balance e.g. "123456000000"
|
|
|
|
iconUrl [string] - icon url e.g. "network/Network=Hermez"
|
|
|
|
chainColor [string] - chain color e.g. "#FF0000"
|
|
|
|
*/
|
2024-05-06 20:22:43 +00:00
|
|
|
required property var accounts
|
2024-06-29 20:24:05 +00:00
|
|
|
/*
|
|
|
|
Networks model
|
|
|
|
Expected model structure:
|
|
|
|
chainName [string] - chain long name. e.g. "Ethereum" or "Optimism"
|
|
|
|
chainId [int] - chain unique identifier
|
|
|
|
iconUrl [string] - SVG icon name. e.g. "network/Network=Ethereum"
|
|
|
|
layer [int] - chain layer. e.g. 1 or 2
|
|
|
|
isTest [bool] - true if the chain is a testnet
|
|
|
|
*/
|
2024-05-06 20:22:43 +00:00
|
|
|
required property var flatNetworks
|
|
|
|
|
2024-06-29 20:24:05 +00:00
|
|
|
property alias dAppUrl: dappCard.dAppUrl
|
|
|
|
property alias dAppName: dappCard.name
|
|
|
|
property alias dAppIconUrl: dappCard.iconUrl
|
|
|
|
property alias connectionStatus: d.connectionStatus
|
2024-10-23 12:56:32 +00:00
|
|
|
property bool connectButtonEnabled: true
|
2024-06-29 20:24:05 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Selected account address holds the initial account address selection for the account selector.
|
|
|
|
It is used to preselect the account in the account selector.
|
|
|
|
*/
|
|
|
|
property string selectedAccountAddress: contextCard.selectedAccount.address ?? ""
|
|
|
|
|
2024-07-19 19:21:36 +00:00
|
|
|
property bool multipleChainSelection: true
|
|
|
|
|
2024-06-29 20:24:05 +00:00
|
|
|
readonly property alias selectedAccount: contextCard.selectedAccount
|
2024-06-15 21:33:12 +00:00
|
|
|
readonly property alias selectedChains: d.selectedChains
|
2024-05-06 20:22:43 +00:00
|
|
|
|
|
|
|
readonly property int notConnectedStatus: 0
|
|
|
|
readonly property int connectionSuccessfulStatus: 1
|
|
|
|
readonly property int connectionFailedStatus: 2
|
|
|
|
|
2024-10-03 18:15:24 +00:00
|
|
|
function pairSuccessful() {
|
2024-10-23 12:56:32 +00:00
|
|
|
d.connectionInProgress = false
|
2024-05-06 20:22:43 +00:00
|
|
|
d.connectionStatus = root.connectionSuccessfulStatus
|
|
|
|
}
|
2024-10-03 18:15:24 +00:00
|
|
|
function pairFailed() {
|
2024-10-23 12:56:32 +00:00
|
|
|
d.connectionInProgress = false
|
2024-05-06 20:22:43 +00:00
|
|
|
d.connectionStatus = root.connectionFailedStatus
|
|
|
|
}
|
|
|
|
|
|
|
|
signal connect()
|
|
|
|
signal decline()
|
|
|
|
signal disconnect()
|
|
|
|
|
2024-06-29 20:24:05 +00:00
|
|
|
width: 480
|
2024-05-06 20:22:43 +00:00
|
|
|
|
2024-06-29 20:24:05 +00:00
|
|
|
title: d.connectionSuccessful ? qsTr("dApp connected") :
|
|
|
|
qsTr("Connection request")
|
2024-05-06 20:22:43 +00:00
|
|
|
|
2024-07-29 08:41:47 +00:00
|
|
|
padding: 0
|
|
|
|
|
|
|
|
StatusScrollView {
|
|
|
|
id: scrollView
|
|
|
|
anchors.fill: parent
|
|
|
|
contentWidth: availableWidth
|
|
|
|
topPadding: 0
|
|
|
|
bottomPadding: 0
|
|
|
|
|
|
|
|
ColumnLayout {
|
|
|
|
spacing: 20
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.leftMargin: 4
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: 4
|
|
|
|
|
|
|
|
DAppCard {
|
|
|
|
id: dappCard
|
2024-07-30 10:46:02 +00:00
|
|
|
Layout.maximumWidth: scrollView.availableWidth - Layout.leftMargin * 2
|
2024-07-29 08:41:47 +00:00
|
|
|
Layout.leftMargin: 12
|
|
|
|
Layout.rightMargin: Layout.leftMargin
|
|
|
|
Layout.topMargin: 14
|
|
|
|
Layout.bottomMargin: Layout.topMargin
|
2024-07-30 10:46:02 +00:00
|
|
|
connectionSuccessful: d.connectionSuccessful
|
|
|
|
connectionAttempted: d.connectionAttempted
|
2024-07-29 08:41:47 +00:00
|
|
|
}
|
2024-05-06 20:22:43 +00:00
|
|
|
|
2024-07-29 08:41:47 +00:00
|
|
|
ContextCard {
|
|
|
|
id: contextCard
|
2024-07-30 10:46:02 +00:00
|
|
|
Layout.maximumWidth: scrollView.availableWidth
|
2024-07-29 08:41:47 +00:00
|
|
|
Layout.fillWidth: true
|
|
|
|
|
|
|
|
multipleChainSelection: root.multipleChainSelection
|
|
|
|
selectedAccountAddress: root.selectedAccountAddress
|
|
|
|
connectionAttempted: d.connectionAttempted
|
|
|
|
accountsModel: d.accountsProxy
|
|
|
|
chainsModel: root.flatNetworks
|
|
|
|
chainSelection: d.selectedChains
|
|
|
|
|
|
|
|
onChainSelectionChanged: {
|
|
|
|
if (d.selectedChains !== chainSelection) {
|
|
|
|
d.selectedChains = chainSelection
|
|
|
|
}
|
2024-06-29 20:24:05 +00:00
|
|
|
}
|
|
|
|
}
|
2024-05-06 20:22:43 +00:00
|
|
|
|
2024-07-29 08:41:47 +00:00
|
|
|
PermissionsCard {
|
2024-07-30 10:46:02 +00:00
|
|
|
Layout.maximumWidth: scrollView.availableWidth
|
2024-07-29 08:41:47 +00:00
|
|
|
Layout.fillWidth: true
|
2024-05-06 20:22:43 +00:00
|
|
|
|
2024-07-29 08:41:47 +00:00
|
|
|
Layout.leftMargin: 16
|
|
|
|
Layout.rightMargin: Layout.leftMargin
|
|
|
|
Layout.topMargin: 12
|
|
|
|
Layout.bottomMargin: Layout.topMargin
|
|
|
|
dappName: dappCard.name
|
|
|
|
}
|
2024-05-06 20:22:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
footer: StatusDialogFooter {
|
|
|
|
id: footer
|
|
|
|
rightButtons: ObjectModel {
|
2024-09-03 12:57:07 +00:00
|
|
|
StatusFlatButton {
|
2024-06-29 20:24:05 +00:00
|
|
|
objectName: "rejectButton"
|
2024-05-06 20:22:43 +00:00
|
|
|
height: 44
|
2024-06-29 20:24:05 +00:00
|
|
|
text: qsTr("Reject")
|
2024-05-06 20:22:43 +00:00
|
|
|
|
2024-06-29 20:24:05 +00:00
|
|
|
visible: !d.connectionAttempted
|
2024-05-06 20:22:43 +00:00
|
|
|
|
|
|
|
onClicked: root.decline()
|
|
|
|
}
|
2024-06-29 20:24:05 +00:00
|
|
|
StatusFlatButton {
|
|
|
|
objectName: "disconnectButton"
|
2024-05-06 20:22:43 +00:00
|
|
|
height: 44
|
|
|
|
text: qsTr("Disconnect")
|
|
|
|
|
2024-06-29 20:24:05 +00:00
|
|
|
visible: d.connectionSuccessful
|
2024-05-06 20:22:43 +00:00
|
|
|
|
|
|
|
type: StatusBaseButton.Type.Danger
|
|
|
|
|
|
|
|
onClicked: root.disconnect()
|
|
|
|
}
|
|
|
|
StatusButton {
|
2024-06-29 20:24:05 +00:00
|
|
|
objectName: "primaryActionButton"
|
2024-05-06 20:22:43 +00:00
|
|
|
height: 44
|
2024-07-29 08:41:47 +00:00
|
|
|
text: d.connectionAttempted ? qsTr("Close") : qsTr("Connect")
|
2024-06-29 20:24:05 +00:00
|
|
|
enabled: {
|
2024-10-23 12:56:32 +00:00
|
|
|
if (d.connectionInProgress)
|
|
|
|
return false
|
2024-06-29 20:24:05 +00:00
|
|
|
if (!d.connectionAttempted)
|
|
|
|
return root.selectedChains.length > 0
|
2024-10-23 12:56:32 +00:00
|
|
|
return root.connectButtonEnabled
|
2024-06-29 20:24:05 +00:00
|
|
|
}
|
2024-05-06 20:22:43 +00:00
|
|
|
|
|
|
|
onClicked: {
|
2024-10-23 12:56:32 +00:00
|
|
|
if (!d.connectionAttempted) {
|
|
|
|
d.connectionInProgress = true
|
2024-05-06 20:22:43 +00:00
|
|
|
root.connect()
|
2024-10-23 12:56:32 +00:00
|
|
|
}
|
|
|
|
else {
|
2024-05-06 20:22:43 +00:00
|
|
|
root.close()
|
2024-10-23 12:56:32 +00:00
|
|
|
}
|
2024-05-06 20:22:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
|
|
|
|
property SortFilterProxyModel accountsProxy: SortFilterProxyModel {
|
|
|
|
sourceModel: root.accounts
|
|
|
|
|
|
|
|
sorters: RoleSorter { roleName: "position"; sortOrder: Qt.AscendingOrder }
|
|
|
|
}
|
|
|
|
|
2024-06-15 21:33:12 +00:00
|
|
|
property var selectedChains: allChainIdsAggregator.value
|
2024-05-06 20:22:43 +00:00
|
|
|
|
2024-06-15 21:33:12 +00:00
|
|
|
readonly property FunctionAggregator allChainIdsAggregator: FunctionAggregator {
|
2024-06-29 20:24:05 +00:00
|
|
|
model: root.flatNetworks
|
2024-06-15 21:33:12 +00:00
|
|
|
initialValue: []
|
|
|
|
roleName: "chainId"
|
|
|
|
|
|
|
|
aggregateFunction: (aggr, value) => [...aggr, value]
|
2024-07-15 17:30:27 +00:00
|
|
|
}
|
2024-06-15 21:33:12 +00:00
|
|
|
|
2024-06-29 20:24:05 +00:00
|
|
|
property int connectionStatus: root.notConnectedStatus
|
|
|
|
readonly property bool connectionSuccessful: d.connectionStatus === root.connectionSuccessfulStatus
|
|
|
|
readonly property bool connectionFailed: d.connectionStatus === root.connectionFailedStatus
|
|
|
|
readonly property bool connectionAttempted: d.connectionStatus !== root.notConnectedStatus
|
2024-10-23 12:56:32 +00:00
|
|
|
property bool connectionInProgress: false
|
2024-05-06 20:22:43 +00:00
|
|
|
}
|
|
|
|
}
|