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:
parent
bc85bc8cd3
commit
9581e6deb6
|
@ -20,19 +20,26 @@ StatusDialog {
|
|||
title: qsTr("Import Community")
|
||||
|
||||
signal joinCommunity(string communityId, var communityDetails)
|
||||
|
||||
QtObject {
|
||||
id: d
|
||||
property string importErrorMessage
|
||||
|
||||
readonly property bool communityFound: (d.communityDetails !== null && !!d.communityDetails.name)
|
||||
readonly property var communityDetails: {
|
||||
if (isInputValid) {
|
||||
let key = isPublicKey ? Utils.getCompressedPk(publicKey) :
|
||||
root.store.getCommunityPublicKeyFromPrivateKey(inputKey);
|
||||
return root.store.getCommunityDetails(key);
|
||||
} else {
|
||||
return null;
|
||||
property bool loading
|
||||
property bool communityFound: (d.communityDetails !== null && !!d.communityDetails.name)
|
||||
property var communityDetails: {
|
||||
if (!isInputValid) {
|
||||
loading = false
|
||||
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")
|
||||
|
@ -56,14 +63,56 @@ StatusDialog {
|
|||
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 {
|
||||
rightButtons: ObjectModel {
|
||||
StatusButton {
|
||||
id: importButton
|
||||
enabled: (d.isInputValid && (d.isPrivateKey && d.communityFound ? agreeToKeepOnline.checked : true))
|
||||
loading: (enabled && !d.communityFound)
|
||||
text: !d.publicKey ? qsTr("Make this device the control node for %1").arg((!loading && !!d.communityDetails) ? d.communityDetails.name : "")
|
||||
: qsTr("Import")
|
||||
enabled: d.communityFound && ((d.isPublicKey) || (d.isPrivateKey && agreeToKeepOnline.checked))
|
||||
loading: d.loading
|
||||
text: d.isPrivateKey && d.communityFound ? qsTr("Make this device the control node for %1").arg(d.communityDetails.name)
|
||||
: qsTr("Import")
|
||||
onClicked: {
|
||||
if (d.isPrivateKey) {
|
||||
root.store.importCommunity(d.privateKey);
|
||||
|
@ -76,7 +125,6 @@ StatusDialog {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
StatusScrollView {
|
||||
id: scrollContent
|
||||
anchors.fill: parent
|
||||
|
@ -93,7 +141,7 @@ StatusDialog {
|
|||
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.")
|
||||
wrapMode: Text.WordWrap
|
||||
font.pixelSize: 13
|
||||
font.pixelSize: Style.current.additionalTextSize
|
||||
color: Theme.palette.baseColor1
|
||||
}
|
||||
|
||||
|
@ -101,7 +149,6 @@ StatusDialog {
|
|||
id: inputLabel
|
||||
text: qsTr("Community key")
|
||||
color: Theme.palette.directColor1
|
||||
font.pixelSize: 15
|
||||
}
|
||||
|
||||
StatusTextArea {
|
||||
|
@ -128,8 +175,8 @@ StatusDialog {
|
|||
StatusBaseText {
|
||||
id: detectionLabel
|
||||
Layout.alignment: Qt.AlignRight
|
||||
font.pixelSize: 13
|
||||
visible: keyInput.text.trim() !== ""
|
||||
font.pixelSize: Style.current.additionalTextSize
|
||||
visible: !!d.inputKey
|
||||
text: {
|
||||
if (d.errorMessage !== "") {
|
||||
return d.errorMessage
|
||||
|
@ -160,13 +207,11 @@ StatusDialog {
|
|||
StatusBaseText {
|
||||
Layout.topMargin: Style.current.halfPadding
|
||||
visible: (d.communityFound && d.isPrivateKey)
|
||||
font.pixelSize: Style.current.primaryTextFontSize
|
||||
text: qsTr("I acknowledge that...")
|
||||
}
|
||||
StatusCheckBox {
|
||||
id: agreeToKeepOnline
|
||||
Layout.fillWidth: true
|
||||
font.pixelSize: Style.current.primaryTextFontSize
|
||||
text: qsTr("I must keep this device online and running Status for the Community to function")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue