fix(ImportCommunityPopup): no UI information when requesting info failed

- track the import progress manually as
`root.store.getCommunityDetails(key)` can optionally return `null`
immediately if the community is not known and launch an async task
- as an additional measure, since the above async call sometimes never
finishes, add a `Timer` that unsets the internal `loading` state

Fixes #12358
This commit is contained in:
Lukáš Tinkl 2023-10-12 16:35:59 +02:00 committed by Lukáš Tinkl
parent bc85bc8cd3
commit 9581e6deb6
1 changed files with 65 additions and 20 deletions

View File

@ -20,19 +20,26 @@ StatusDialog {
title: qsTr("Import Community") title: qsTr("Import Community")
signal joinCommunity(string communityId, var communityDetails) signal joinCommunity(string communityId, var communityDetails)
QtObject { QtObject {
id: d id: d
property string importErrorMessage property string importErrorMessage
readonly property bool communityFound: (d.communityDetails !== null && !!d.communityDetails.name) property bool loading
readonly property var communityDetails: { property bool communityFound: (d.communityDetails !== null && !!d.communityDetails.name)
if (isInputValid) { property var communityDetails: {
let key = isPublicKey ? Utils.getCompressedPk(publicKey) : if (!isInputValid) {
root.store.getCommunityPublicKeyFromPrivateKey(inputKey); loading = false
return root.store.getCommunityDetails(key); return null
} else {
return null;
} }
loading = true
const key = isPublicKey ? Utils.getCompressedPk(publicKey) :
root.store.getCommunityPublicKeyFromPrivateKey(inputKey, true /*importing*/);
const details = root.store.getCommunityDetails(key)
if (!!details) // the above can return `null` in which case we continue loading
loading = false
return details
} }
readonly property string inputErrorMessage: isInputValid ? "" : qsTr("Invalid key") readonly property string inputErrorMessage: isInputValid ? "" : qsTr("Invalid key")
@ -56,14 +63,56 @@ StatusDialog {
readonly property bool isInputValid: isPrivateKey || isPublicKey readonly property bool isInputValid: isPrivateKey || isPublicKey
} }
Timer {
interval: 20000 // 20s
running: d.loading
onTriggered: {
d.loading = false
d.importErrorMessage = qsTr("Timeout reached while getting community info")
}
}
Connections {
target: root.store
function onImportingCommunityStateChanged(communityId, state, errorMsg) {
switch (state)
{
case Constants.communityImported:
const community = root.store.getCommunityDetailsAsJson(communityId)
d.loading = false
d.communityFound = true
d.communityDetails = community
d.importErrorMessage = ""
break
case Constants.communityImportingInProgress:
d.loading = true
break
case Constants.communityImportingError:
d.loading = false
d.communityFound = false
d.communityDetails = null
d.importErrorMessage = errorMsg
break
default:
const msg = qsTr("Error state '%1' while importing community: %2").arg(state).arg(communityId)
console.error(msg)
d.loading = false
d.communityFound = false
d.communityDetails = null
d.importErrorMessage = msg
return
}
}
}
footer: StatusDialogFooter { footer: StatusDialogFooter {
rightButtons: ObjectModel { rightButtons: ObjectModel {
StatusButton { StatusButton {
id: importButton enabled: d.communityFound && ((d.isPublicKey) || (d.isPrivateKey && agreeToKeepOnline.checked))
enabled: (d.isInputValid && (d.isPrivateKey && d.communityFound ? agreeToKeepOnline.checked : true)) loading: d.loading
loading: (enabled && !d.communityFound) text: d.isPrivateKey && d.communityFound ? qsTr("Make this device the control node for %1").arg(d.communityDetails.name)
text: !d.publicKey ? qsTr("Make this device the control node for %1").arg((!loading && !!d.communityDetails) ? d.communityDetails.name : "") : qsTr("Import")
: qsTr("Import")
onClicked: { onClicked: {
if (d.isPrivateKey) { if (d.isPrivateKey) {
root.store.importCommunity(d.privateKey); root.store.importCommunity(d.privateKey);
@ -76,7 +125,6 @@ StatusDialog {
} }
} }
StatusScrollView { StatusScrollView {
id: scrollContent id: scrollContent
anchors.fill: parent anchors.fill: parent
@ -93,7 +141,7 @@ StatusDialog {
Layout.fillWidth: true 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.") 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.")
wrapMode: Text.WordWrap wrapMode: Text.WordWrap
font.pixelSize: 13 font.pixelSize: Style.current.additionalTextSize
color: Theme.palette.baseColor1 color: Theme.palette.baseColor1
} }
@ -101,7 +149,6 @@ StatusDialog {
id: inputLabel id: inputLabel
text: qsTr("Community key") text: qsTr("Community key")
color: Theme.palette.directColor1 color: Theme.palette.directColor1
font.pixelSize: 15
} }
StatusTextArea { StatusTextArea {
@ -128,8 +175,8 @@ StatusDialog {
StatusBaseText { StatusBaseText {
id: detectionLabel id: detectionLabel
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight
font.pixelSize: 13 font.pixelSize: Style.current.additionalTextSize
visible: keyInput.text.trim() !== "" visible: !!d.inputKey
text: { text: {
if (d.errorMessage !== "") { if (d.errorMessage !== "") {
return d.errorMessage return d.errorMessage
@ -160,13 +207,11 @@ StatusDialog {
StatusBaseText { StatusBaseText {
Layout.topMargin: Style.current.halfPadding Layout.topMargin: Style.current.halfPadding
visible: (d.communityFound && d.isPrivateKey) visible: (d.communityFound && d.isPrivateKey)
font.pixelSize: Style.current.primaryTextFontSize
text: qsTr("I acknowledge that...") text: qsTr("I acknowledge that...")
} }
StatusCheckBox { StatusCheckBox {
id: agreeToKeepOnline id: agreeToKeepOnline
Layout.fillWidth: true Layout.fillWidth: true
font.pixelSize: Style.current.primaryTextFontSize
text: qsTr("I must keep this device online and running Status for the Community to function") text: qsTr("I must keep this device online and running Status for the Community to function")
} }
} }