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

206 lines
6.2 KiB
QML
Raw Normal View History

2020-10-19 19:00:43 +00:00
import QtQuick 2.13
import QtQuick.Controls 2.13
import QtQuick.Layouts 1.13
import utils 1.0
import shared.controls 1.0
import shared.panels 1.0
import StatusQ.Controls 0.1
import "../controls"
import "../stores"
2020-10-19 19:00:43 +00:00
// TODO: replace StatusModal
2020-10-19 19:00:43 +00:00
Popup {
property var currentTab
property var request: ({"hostname": "", "title": "", "permission": ""})
property string currentAddress: ""
property bool interactedWith: false
2020-10-19 19:00:43 +00:00
id: root
modal: true
Overlay.modal: Rectangle {
color: "#60000000"
}
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
2021-11-19 00:13:23 +00:00
width: 470
height: 400
2020-10-19 19:00:43 +00:00
background: Rectangle {
color: Style.current.background
radius: 8
}
2021-11-19 00:13:23 +00:00
padding: Style.current.padding
2020-10-19 19:00:43 +00:00
function postMessage(isAllowed){
interactedWith = true
2020-10-19 19:00:43 +00:00
request.isAllowed = isAllowed;
currentTabConnected = isAllowed
provider.web3Response(Web3ProviderStore.web3ProviderInst.postMessage(JSON.stringify(request)));
2020-10-19 19:00:43 +00:00
}
onClosed: {
if(!interactedWith){
currentTabConnected = false
postMessage(false);
}
2020-10-19 19:00:43 +00:00
root.destroy();
}
ColumnLayout {
spacing: Style.current.bigPadding
anchors.left: root.left
anchors.leftMargin: Style.current.padding
anchors.right: root.right
anchors.rightMargin: Style.current.padding
anchors.top: root.top
2021-11-19 00:13:23 +00:00
anchors.topMargin: Style.current.padding
2020-10-19 19:00:43 +00:00
RowLayout {
property int imgSize: 40
id: logoHeader
spacing: Style.current.halfPadding
width: 176
height: imgSize
Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
FaviconImage {
2020-10-19 19:00:43 +00:00
id: siteImg
width: logoHeader.imgSize
height: logoHeader.imgSize
}
SVGImage {
id: dots1
source: Style.svg("dots-icon")
2020-10-19 19:00:43 +00:00
width: 20
height: 4
}
RoundedIcon {
source: Style.svg("check")
2020-10-19 19:00:43 +00:00
iconColor: Style.current.primary
color: Style.current.secondaryBackground
width: 24
height: 24
}
SVGImage {
id: dots2
source: Style.svg("dots-icon")
2020-10-19 19:00:43 +00:00
width: 20
height: 4
}
RoundedIcon {
source: Style.svg("walletIcon")
2020-10-19 19:00:43 +00:00
iconHeight: 18
iconWidth: 18
iconColor: accountSelector.selectedAccount.iconColor || Style.current.primary
2020-10-19 19:00:43 +00:00
color: Style.current.background
width: logoHeader.imgSize
height: logoHeader.imgSize
border.width: 1
border.color: Style.current.border
}
}
StyledText {
id: titleText
2021-02-18 16:36:05 +00:00
//% "'%1' would like to connect to"
text: qsTrId("--1--would-like-to-connect-to").arg(request.title)
2020-10-19 19:00:43 +00:00
Layout.fillWidth: true
Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
wrapMode: Text.WordWrap
font.weight: Font.Bold
font.pixelSize: 17
horizontalAlignment: Text.AlignHCenter
}
StatusAccountSelector {
2020-10-19 19:00:43 +00:00
id: accountSelector
label: ""
2021-11-19 00:13:23 +00:00
width: 300
implicitWidth: width
2020-10-19 19:00:43 +00:00
Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
showAccountDetails: false
accounts: WalletStore.accounts
selectedAccount: WalletStore.dappBrowserAccount
currency: WalletStore.defaultCurrency
2020-10-19 19:00:43 +00:00
onSelectedAccountChanged: {
if (!root.currentAddress) {
// We just set the account for the first time. Nothing to do here
root.currentAddress = selectedAccount.address
return
}
if (root.currentAddress === selectedAccount.address) {
return
}
root.currentAddress = selectedAccount.address
Web3ProviderStore.web3ProviderInst.dappsAddress = selectedAccount.address;
Web3ProviderStore.revokeAllPermissions()
if (selectedAccount.address) {
Web3ProviderStore.web3ProviderInst.dappsAddress = selectedAccount.address;
WalletStore.setDappBrowserAddress()
2020-10-19 19:00:43 +00:00
}
}
}
StyledText {
id: infoText
text: {
switch(request.permission){
2021-02-18 16:36:05 +00:00
//% "Allowing authorizes this DApp to retrieve your wallet address and enable Web3"
case Constants.permission_web3: return qsTrId("allowing-authorizes-this-dapp");
//% "Granting access authorizes this DApp to retrieve your chat key"
case Constants.permission_contactCode: return qsTrId("your-contact-code");
default: return qsTr("Unknown permission: " + request.permission);
2020-10-19 19:00:43 +00:00
}
}
Layout.fillWidth: true
wrapMode: Text.WordWrap
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
font.pixelSize: 15
horizontalAlignment: Text.AlignHCenter
color: Style.current.secondaryText
}
Row {
width: childrenRect.width
spacing: Style.current.padding
Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
StatusButton {
type: StatusBaseButton.Type.Danger
2020-10-19 19:00:43 +00:00
width: 155
2021-02-18 16:36:05 +00:00
//% "Deny"
text: qsTrId("deny")
2020-10-19 19:00:43 +00:00
onClicked: {
postMessage(false);
root.close();
}
}
StyledButton {
btnColor: Utils.setColorAlpha(Style.current.success, 0.1)
textColor: Style.current.success
width: 155
2021-02-18 16:36:05 +00:00
//% "Allow"
label: qsTrId("allow")
2020-10-19 19:00:43 +00:00
onClicked: {
postMessage(true);
root.close();
}
}
}
}
}
/*##^##
Designer {
D{i:0;formeditorColor:"#ffffff"}
}
##^##*/