2020-12-18 20:55:33 +00:00
import QtQuick 2.12
import QtQuick . Controls 2.3
2022-11-28 14:57:56 +00:00
import QtQuick . Layouts 1.14
2020-12-18 20:55:33 +00:00
import QtGraphicalEffects 1.13
import QtQuick . Dialogs 1.3
2022-11-28 14:57:56 +00:00
import QtQml . Models 2.14
2021-09-28 15:04:06 +00:00
import utils 1.0
2021-10-27 21:27:49 +00:00
import shared . controls 1.0
2021-10-19 08:51:11 +00:00
import StatusQ . Core 0.1
import StatusQ . Core . Theme 0.1
2022-11-28 14:57:56 +00:00
import StatusQ . Popups . Dialog 0.1
import StatusQ . Controls 0.1
2021-10-19 08:51:11 +00:00
2022-11-28 14:57:56 +00:00
StatusDialog {
2021-10-22 20:49:47 +00:00
id: root
2021-11-30 14:49:36 +00:00
property var store
2022-11-28 14:57:56 +00:00
width: 640
title: qsTr ( "Import Community" )
2021-10-22 20:49:47 +00:00
2023-07-21 17:21:11 +00:00
signal joinCommunity ( string communityId , var communityDetails )
2022-11-28 14:57:56 +00:00
QtObject {
id: d
property string importErrorMessage
2023-07-21 17:21:11 +00:00
readonly property bool communityFound: ( d . isPublicKey && ! ! d . communityDetails )
readonly property var communityDetails: {
return root . store . getCommunityDetails ( Utils . getCompressedPk ( publicKey ) ) ;
}
2022-11-28 14:57:56 +00:00
readonly property string inputErrorMessage: isInputValid ? "" : qsTr ( "Invalid key" )
readonly property string errorMessage: importErrorMessage || inputErrorMessage
2023-05-15 10:31:23 +00:00
readonly property string inputKey: keyInput . text . trim ( )
2023-07-21 17:21:11 +00:00
readonly property bool isPrivateKey: ( Utils . isPrivateKey ( inputKey ) )
readonly property bool isPublicKey: ( publicKey !== "" )
2023-05-15 10:31:23 +00:00
readonly property string publicKey: {
2023-07-21 17:21:11 +00:00
if ( ! Utils . isStatusDeepLink ( inputKey ) ) {
const key = Utils . dropCommunityLinkPrefix ( inputKey )
if ( ! Utils . isCommunityPublicKey ( key ) )
return ""
if ( ! Utils . isCompressedPubKey ( key ) )
return key
return Utils . changeCommunityKeyCompression ( key )
} else {
return Utils . getCommunityDataFromSharedLink ( inputKey ) . communityId ;
}
2023-05-15 10:31:23 +00:00
}
2022-11-28 14:57:56 +00:00
readonly property bool isInputValid: isPrivateKey || isPublicKey
2021-03-10 14:25:06 +00:00
}
2022-11-28 14:57:56 +00:00
footer: StatusDialogFooter {
rightButtons: ObjectModel {
StatusButton {
2023-05-04 15:37:44 +00:00
id: importButton
enabled: d . isInputValid
2023-07-21 17:21:11 +00:00
loading: ( d . isPublicKey && ! d . communityFound )
text: d . isPrivateKey ? qsTr ( "Make this an Owner Node" )
: qsTr ( "Import" )
2023-05-04 15:37:44 +00:00
onClicked: {
if ( d . isPrivateKey ) {
2023-05-15 10:31:23 +00:00
const communityKey = d . inputKey
2023-05-04 15:37:44 +00:00
if ( ! communityKey . startsWith ( "0x" ) ) {
communityKey = "0x" + communityKey ;
}
root . store . importCommunity ( communityKey ) ;
root . close ( ) ;
2023-07-21 17:21:11 +00:00
} else if ( d . communityFound ) {
root . joinCommunity ( d . publicKey , d . communityDetails ) ;
2023-05-04 15:37:44 +00:00
}
}
2022-11-28 14:57:56 +00:00
}
}
2020-12-18 20:55:33 +00:00
}
2022-11-28 14:57:56 +00:00
ColumnLayout {
anchors.fill: parent
spacing: Style . current . padding
2020-12-18 20:55:33 +00:00
2022-03-23 10:56:25 +00:00
StatusBaseText {
id: infoText1
2022-11-28 14:57:56 +00:00
Layout.fillWidth: true
text: qsTr ( "Enter the public key of the community you wish to access, or enter the private key of a community you own. Remember to always keep any private key safe and never share a private key with anyone else." )
2022-03-23 10:56:25 +00:00
wrapMode: Text . WordWrap
font.pixelSize: 13
color: Theme . palette . baseColor1
}
2022-11-28 14:57:56 +00:00
StatusBaseText {
id: inputLabel
text: qsTr ( "Community key" )
color: Theme . palette . directColor1
font.pixelSize: 15
}
StatusTextArea {
2021-03-10 14:25:06 +00:00
id: keyInput
2022-11-28 14:57:56 +00:00
Layout.fillWidth: true
2023-05-05 14:01:34 +00:00
implicitHeight: 110
placeholderText: "0x0..."
wrapMode: TextEdit . WrapAtWordBoundaryOrAnywhere
2022-11-28 14:57:56 +00:00
onTextChanged: d . importErrorMessage = ""
2023-07-21 17:21:11 +00:00
}
RowLayout {
2022-11-28 14:57:56 +00:00
Layout.fillWidth: true
2023-07-21 17:21:11 +00:00
Layout.fillHeight: true
StatusChatInfoButton {
visible: ( d . communityFound && d . isPublicKey )
title: ! ! d . communityDetails . name ? d.communityDetails.name : ""
subTitle: ! ! d . communityDetails . nbMembers ? qsTr ( "%n member(s)" , "" , d . communityDetails . nbMembers ) : ""
asset.emoji: "1f918"
asset.emojiSize: "24x24"
asset.name: ! ! d . communityDetails . image ? d.communityDetails.image : ""
asset.isImage: ( asset . name !== "" )
asset.color: ! ! d . communityDetails . color ? d.communityDetails.color : ""
}
Item { Layout.fillWidth: true }
StatusBaseText {
id: detectionLabel
Layout.alignment: Qt . AlignRight
font.pixelSize: 13
visible: keyInput . text . trim ( ) !== ""
text: {
if ( d . errorMessage !== "" ) {
return d . errorMessage
}
if ( d . isPrivateKey ) {
return qsTr ( "Private key detected" )
}
if ( d . isPublicKey ) {
return qsTr ( "Public key detected" )
}
2022-11-28 14:57:56 +00:00
}
2023-07-21 17:21:11 +00:00
color: d . errorMessage === "" ? Theme.palette.successColor1 : Theme . palette . dangerColor1
2022-02-02 17:54:28 +00:00
}
2021-02-12 18:19:31 +00:00
}
2020-12-18 20:55:33 +00:00
}
}