status-desktop/ui/app/AppLayouts/Browser/popups/BrowserWalletMenu.qml

227 lines
7.0 KiB
QML
Raw Normal View History

import QtQuick 2.15
2020-10-15 17:05:34 +00:00
import QtQuick.Controls 2.13
import QtQuick.Layouts 1.13
2020-10-15 17:05:34 +00:00
import QtGraphicalEffects 1.13
import StatusQ.Controls 0.1
import StatusQ.Core 0.1
import shared.controls 1.0
import shared.views 1.0
import utils 1.0
import "../stores"
2020-10-15 17:05:34 +00:00
2022-12-01 16:58:37 +00:00
// TODO: replace with StatusMenu
Dialog {
2020-10-15 17:05:34 +00:00
id: popup
required property var assetsStore
required property var currencyStore
required property var tokensStore
signal sendTriggered(var selectedAccount)
signal disconnect()
signal reload()
2020-10-15 17:05:34 +00:00
modal: false
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
parent: Overlay.overlay
width: 360
height: 480
background: Rectangle {
id: bgPopup
color: Style.current.background
radius: Style.current.radius
layer.enabled: true
layer.effect: DropShadow {
2020-10-15 17:05:34 +00:00
width: bgPopup.width
height: bgPopup.height
x: bgPopup.x
y: bgPopup.y + 10
visible: bgPopup.visible
source: bgPopup
horizontalOffset: 0
verticalOffset: 5
radius: 10
samples: 15
color: Style.current.dropShadow
2020-10-15 17:05:34 +00:00
}
}
padding: Style.current.padding
Item {
id: walletHeader
width: parent.width
height: networkText.height
Rectangle {
id: networkColorCircle
width: 8
height: 8
radius: width / 2
color: {
2022-06-07 13:57:09 +00:00
switch (Web3ProviderStore.chainName) {
case Constants.networkMainnet: return Style.current.green;
case Constants.networkRopsten: return Style.current.turquoise;
default: return Style.current.red
}
}
2020-10-15 17:05:34 +00:00
anchors.verticalCenter: parent.verticalCenter
}
StatusBaseText {
2020-10-15 17:05:34 +00:00
id: networkText
text: {
2022-06-07 13:57:09 +00:00
switch (Web3ProviderStore.chainName) {
case Constants.networkMainnet: return qsTr("Mainnet");
case Constants.networkRopsten: return qsTr("Ropsten");
default: return qsTr("Unknown")
}
}
2020-10-15 17:05:34 +00:00
font.pixelSize: 15
anchors.verticalCenter: parent.verticalCenter
anchors.left: networkColorCircle.right
anchors.leftMargin: Style.current.halfPadding
}
StatusBaseText {
2020-10-15 17:05:34 +00:00
id: disconectBtn
text: qsTr("Disconnect")
2020-10-15 17:05:34 +00:00
font.pixelSize: 15
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right
color: Style.current.danger
visible: RootStore.currentTabConnected
2020-10-15 17:05:34 +00:00
MouseArea {
cursorShape: Qt.PointingHandCursor
anchors.fill: parent
onClicked: disconnect()
2020-10-15 17:05:34 +00:00
}
}
}
2020-10-15 18:12:35 +00:00
Connections {
target: WalletStore.dappBrowserAccount
function onConnectedAccountDeleted() {
popup.reload()
// This is done because when an account is deleted and the account is updated to default one,
// only the properties are updated and we need to listen to those events and update the selected account
accountSelectorRow.currentAddress = ""
accountSelector.selectedAccount = Qt.binding(function () {return WalletStore.dappBrowserAccount})
}
}
2020-10-15 18:12:35 +00:00
Item {
property string currentAddress: ""
id: accountSelectorRow
width: parent.width
height: accountSelector.height
2020-10-15 18:12:35 +00:00
anchors.top: walletHeader.bottom
anchors.topMargin: Style.current.bigPadding
StatusAccountSelector {
id: accountSelector
2020-10-15 18:12:35 +00:00
label: ""
anchors.left: parent.left
anchors.right: copyBtn.left
anchors.rightMargin: Style.current.padding
accounts: WalletStore.accounts
selectedAccount: WalletStore.dappBrowserAccount
currency: WalletStore.defaultCurrency
2020-10-15 18:12:35 +00:00
onSelectedAccountChanged: {
if (!accountSelectorRow.currentAddress) {
// We just set the account for the first time. Nothing to do here
accountSelectorRow.currentAddress = selectedAccount.address
return
}
if (accountSelectorRow.currentAddress === selectedAccount.address) {
return
}
accountSelectorRow.currentAddress = selectedAccount.address
Web3ProviderStore.web3ProviderInst.dappsAddress = selectedAccount.address;
WalletStore.switchAccountByAddress(selectedAccount.address)
reload()
2020-10-15 18:12:35 +00:00
}
}
CopyToClipBoardButton {
id: copyBtn
width: 20
height: 20
anchors.right: sendBtn.left
anchors.rightMargin: Style.current.padding
anchors.top: parent.top
anchors.topMargin: Style.current.padding
color: Style.current.transparent
textToCopy: accountSelector.selectedAccount.address
2023-02-20 12:55:39 +00:00
onCopyClicked: RootStore.copyToClipboard(textToCopy)
2020-10-15 18:12:35 +00:00
}
StatusFlatRoundButton {
2020-10-15 18:12:35 +00:00
id: sendBtn
width: 40
height: 40
2020-10-15 18:12:35 +00:00
anchors.right: parent.right
anchors.top: parent.top
anchors.topMargin: Style.current.halfPadding
icon.name: "send"
onClicked: sendTriggered(accountSelector.selectedAccount)
2020-10-15 18:12:35 +00:00
}
}
Item {
id: walletInfoContent
width: parent.width
anchors.top: accountSelectorRow.bottom
anchors.topMargin: Style.current.bigPadding
anchors.bottom: parent.bottom
StatusTabBar {
id: walletTabBar
width: parent.width
anchors.top: parent.top
StatusTabButton {
id: assetBtn
width: implicitWidth
text: qsTr("Assets")
}
StatusTabButton {
id: historyBtn
width: implicitWidth
text: qsTr("History")
}
}
StackLayout {
id: stackLayout
width: parent.width
anchors.top: walletTabBar.bottom
anchors.topMargin: Style.current.bigPadding
anchors.bottom: parent.bottom
currentIndex: walletTabBar.currentIndex
// Disable because the refactored version of AssetView requires specific
// integration but the old version was not working properly neither.
//AssetsView {
// id: assetsTab
// controller: popup.assetsStore.assetsController
// currencyStore: popup.currencyStore
// tokensStore: popup.tokensStore
//}
HistoryView {
id: historyTab
overview: WalletStore.dappBrowserAccount
}
}
}
onClosed: {
popup.destroy();
}
2020-10-15 17:05:34 +00:00
}