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

184 lines
6.3 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.panels 1.0
import StatusQ.Controls 0.1
import StatusQ.Popups 0.1
import StatusQ.Core 0.1
import StatusQ.Core.Theme 0.1
import "../controls"
import "../stores"
2020-10-19 19:00:43 +00:00
StatusModal {
id: browserConnectionModal
2020-10-19 19:00:43 +00:00
property var currentTab
property var request: ({"hostname": "", "address": "", "title": "", "permission": ""})
2020-10-19 19:00:43 +00:00
property string currentAddress: ""
property bool interactedWith: false
property var web3Response: function(){}
width: 360
height: 480
showHeader: false
2020-10-19 19:00:43 +00:00
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
topPadding: 0
bottomPadding: 0
2020-10-19 19:00:43 +00:00
function postMessage(isAllowed){
console.log(isAllowed)
interactedWith = true
RootStore.currentTabConnected = isAllowed
if(isAllowed){
Web3ProviderStore.addPermission(request.hostname, request.address, request.permission)
}
2022-03-29 10:21:12 +00:00
Web3ProviderStore.web3ProviderInst.postMessage("", Constants.api_request, JSON.stringify(request))
2020-10-19 19:00:43 +00:00
}
onClosed: {
if(!interactedWith){
RootStore.currentTabConnected = false
postMessage(false);
}
2020-10-19 19:00:43 +00:00
}
contentItem: Item {
width: parent.width
height: parent.height
2020-10-19 19:00:43 +00:00
ColumnLayout {
spacing: Style.current.bigPadding
anchors.centerIn: parent
2020-10-19 19:00:43 +00:00
RowLayout {
property int imgSize: 40
2020-10-19 19:00:43 +00:00
id: logoHeader
spacing: Style.current.halfPadding
Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
2020-10-19 19:00:43 +00:00
FaviconImage {
id: siteImg
}
2020-10-19 19:00:43 +00:00
SVGImage {
id: dots1
source: Style.svg("dots-icon")
2020-10-19 19:00:43 +00:00
}
RoundedIcon {
source: Style.svg("check")
iconColor: Style.current.primary
color: Style.current.secondaryBackground
2020-10-19 19:00:43 +00:00
}
SVGImage {
id: dots2
source: Style.svg("dots-icon")
}
RoundedIcon {
source: Style.svg("walletIcon")
iconHeight: 18
iconWidth: 18
iconColor: accountSelector.selectedAccount.iconColor || Style.current.primary
color: Style.current.background
border.width: 1
border.color: Style.current.border
2020-10-19 19:00:43 +00:00
}
}
StatusBaseText {
id: titleText
text: qsTr("'%1' would like to connect to").arg(request.title)
wrapMode: Text.WordWrap
font.weight: Font.Bold
font.pixelSize: 17
horizontalAlignment: Text.AlignHCenter
elide: Text.ElideRight
Layout.maximumWidth: browserConnectionModal.width - Style.current.padding
Layout.fillWidth: true
Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
color: Theme.palette.directColor1
}
2020-10-19 19:00:43 +00:00
StatusAccountSelector {
id: accountSelector
label: ""
implicitWidth: 300
Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
showAccountDetails: false
accounts: WalletStore.accounts
selectedAccount: WalletStore.dappBrowserAccount
currency: WalletStore.defaultCurrency
onSelectedAccountChanged: {
if (!browserConnectionModal.currentAddress) {
// We just set the account for the first time. Nothing to do here
browserConnectionModal.currentAddress = selectedAccount.address
return
}
if (browserConnectionModal.currentAddress === selectedAccount.address) {
return
}
browserConnectionModal.currentAddress = selectedAccount.address
Web3ProviderStore.web3ProviderInst.dappsAddress = selectedAccount.address;
if (selectedAccount.address) {
Web3ProviderStore.web3ProviderInst.dappsAddress = selectedAccount.address;
WalletStore.switchAccountByAddress(selectedAccount.address)
}
2020-10-19 19:00:43 +00:00
}
}
StatusBaseText {
id: infoText
text: {
switch(request.permission){
case Constants.permission_web3: return qsTr("Allowing authorizes this DApp to retrieve your wallet address and enable Web3");
case Constants.permission_contactCode: return qsTr("Granting access authorizes this DApp to retrieve your chat key");
default: return qsTr("Unknown permission: " + request.permission);
}
2020-10-19 19:00:43 +00:00
}
wrapMode: Text.WordWrap
font.pixelSize: 15
horizontalAlignment: Text.AlignHCenter
color: Theme.palette.baseColor1
Layout.maximumWidth: browserConnectionModal.width - Style.current.padding
Layout.fillWidth: true
Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
2020-10-19 19:00:43 +00:00
}
Row {
spacing: Style.current.padding
Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
StatusButton {
type: StatusBaseButton.Type.Danger
width: 151
text: qsTr("Deny")
onClicked: {
postMessage(false);
browserConnectionModal.close();
}
}
StatusButton {
normalColor: Utils.setColorAlpha(Style.current.success, 0.1)
textColor: Style.current.success
width: 151
text: qsTr("Allow")
onClicked: {
postMessage(true);
browserConnectionModal.close();
}
2020-10-19 19:00:43 +00:00
}
}
}
}
}