From bb6e87deec4dc96c0c5a937dece876fd0de89fb3 Mon Sep 17 00:00:00 2001 From: Igor Sirotin Date: Thu, 4 May 2023 18:37:44 +0300 Subject: [PATCH] fix(ImportCommunityPopup): Support community link (#10557) --- .../Chat/views/MembersSelectorView.qml | 5 +-- .../shared/popups/ImportCommunityPopup.qml | 39 ++++++++++--------- ui/imports/utils/Utils.qml | 12 ++++++ 3 files changed, 33 insertions(+), 23 deletions(-) diff --git a/ui/app/AppLayouts/Chat/views/MembersSelectorView.qml b/ui/app/AppLayouts/Chat/views/MembersSelectorView.qml index c491d333e6..7fa8d9aaa9 100644 --- a/ui/app/AppLayouts/Chat/views/MembersSelectorView.qml +++ b/ui/app/AppLayouts/Chat/views/MembersSelectorView.qml @@ -63,10 +63,7 @@ MembersSelectorBase { function lookupContact(value) { - value = value.trim() - - if (value.startsWith(Constants.userLinkPrefix)) - value = value.slice(Constants.userLinkPrefix.length) + value = Utils.dropUserLinkPrefix(value.trim()) if (Utils.isChatKey(value)) { processContact(value) diff --git a/ui/imports/shared/popups/ImportCommunityPopup.qml b/ui/imports/shared/popups/ImportCommunityPopup.qml index f615e8de87..5645bbeb05 100644 --- a/ui/imports/shared/popups/ImportCommunityPopup.qml +++ b/ui/imports/shared/popups/ImportCommunityPopup.qml @@ -24,8 +24,9 @@ StatusDialog { property string importErrorMessage readonly property string inputErrorMessage: isInputValid ? "" : qsTr("Invalid key") readonly property string errorMessage: importErrorMessage || inputErrorMessage - readonly property bool isPrivateKey: Utils.isPrivateKey(keyInput.text) - readonly property bool isPublicKey: Utils.isChatKey(keyInput.text) + readonly property string inputKey: Utils.dropCommunityLinkPrefix(keyInput.text.trim()) + readonly property bool isPrivateKey: Utils.isPrivateKey(inputKey) + readonly property bool isPublicKey: Utils.isChatKey(inputKey) readonly property bool isInputValid: isPrivateKey || isPublicKey } @@ -36,24 +37,24 @@ StatusDialog { onClicked: root.reject() } StatusButton { - id: importButton - enabled: d.isInputValid - text: d.isPrivateKey ? qsTr("Make this an Owner Node") : qsTr("Import") - onClicked: { - let communityKey = keyInput.text.trim(); - if (d.isPrivateKey) { - if (!communityKey.startsWith("0x")) { - communityKey = "0x" + communityKey; + id: importButton + enabled: d.isInputValid + text: d.isPrivateKey ? qsTr("Make this an Owner Node") : qsTr("Import") + onClicked: { + let communityKey = d.inputKey + if (d.isPrivateKey) { + if (!communityKey.startsWith("0x")) { + communityKey = "0x" + communityKey; + } + root.store.importCommunity(communityKey); + root.close(); } - root.store.importCommunity(communityKey); - root.close(); - } - if (d.isPublicKey) { - importButton.loading = true - root.store.requestCommunityInfo(communityKey, true) - root.close(); - } - } + if (d.isPublicKey) { + importButton.loading = true + root.store.requestCommunityInfo(communityKey, true) + root.close(); + } + } } } } diff --git a/ui/imports/utils/Utils.qml b/ui/imports/utils/Utils.qml index 259ced48d3..4ac7b16591 100644 --- a/ui/imports/utils/Utils.qml +++ b/ui/imports/utils/Utils.qml @@ -656,6 +656,18 @@ QtObject { return key } + function dropUserLinkPrefix(text) { + if (text.startsWith(Constants.userLinkPrefix)) + text = text.slice(Constants.userLinkPrefix.length) + return text + } + + function dropCommunityLinkPrefix(text) { + if (text.startsWith(Constants.communityLinkPrefix)) + text = text.slice(Constants.communityLinkPrefix.length) + return text + } + // Leave this function at the bottom of the file as QT Creator messes up the code color after this function isPunct(c) { return /(!|\@|#|\$|%|\^|&|\*|\(|\)|\+|\||-|=|\\|{|}|[|]|"|;|'|<|>|\?|,|\.|\/)/.test(c)