fix: Enforce watch only account limits

This commit is contained in:
Alex Jbanca 2025-01-14 17:12:38 +02:00 committed by Anthony Laibe
parent bddb1ff8c7
commit 4fea2b5f2a
4 changed files with 37 additions and 42 deletions

View File

@ -20,12 +20,6 @@ StatusModal {
property AddAccountStore store: AddAccountStore { }
enum LimitWarning {
Accounts,
Keypairs,
WatchOnlyAccounts
}
width: Constants.addAccountPopup.popupWidth
closePolicy: root.store.disablePopup? Popup.NoAutoClose : Popup.CloseOnEscape | Popup.CloseOnPressOutside
@ -74,13 +68,13 @@ StatusModal {
property string content
function showPopup(warningType) {
if (warningType === AddAccountPopup.LimitWarning.Accounts) {
if (warningType === Constants.LimitWarning.Accounts) {
limitPopup.title = Constants.walletConstants.maxNumberOfAccountsTitle
limitPopup.content = Constants.walletConstants.maxNumberOfAccountsContent
} else if (warningType === AddAccountPopup.LimitWarning.Keypairs) {
} else if (warningType === Constants.LimitWarning.Keypairs) {
limitPopup.title = Constants.walletConstants.maxNumberOfKeypairsTitle
limitPopup.content = Constants.walletConstants.maxNumberOfKeypairsContent
} else if (warningType === AddAccountPopup.LimitWarning.WatchOnlyAccounts) {
} else if (warningType === Constants.LimitWarning.WatchOnlyAccounts) {
limitPopup.title = Constants.walletConstants.maxNumberOfWatchOnlyAccountsTitle
limitPopup.content = Constants.walletConstants.maxNumberOfSavedAddressesContent
} else {
@ -158,10 +152,10 @@ StatusModal {
store: root.store
onWatchOnlyAccountsLimitReached: {
limitPopup.showPopup(AddAccountPopup.LimitWarning.WatchOnlyAccounts)
limitPopup.showPopup(Constants.LimitWarning.WatchOnlyAccounts)
}
onKeypairLimitReached: {
limitPopup.showPopup(AddAccountPopup.LimitWarning.Keypairs)
limitPopup.showPopup(Constants.LimitWarning.Keypairs)
}
}
}

View File

@ -9,8 +9,6 @@ import StatusQ.Controls 0.1
import StatusQ.Controls.Validators 0.1
import utils 1.0
import StatusQ 0.1
import SortFilterProxyModel 0.2
import "../stores"
import "../panels"
@ -55,20 +53,6 @@ Item {
id: d
readonly property bool isEdit: root.store.editMode
readonly property SortFilterProxyModel originModelWithoutWatchOnlyAcc: SortFilterProxyModel {
id: originModelWithoutWatchOnlyAcc
objectName: "originModelWithoutWatchOnlyAcc"
sourceModel: root.store.originModel
readonly property string addWatchOnlyAccKeyUid: Constants.appTranslatableConstants.addAccountLabelOptionAddWatchOnlyAcc
filters: [
FastExpressionFilter {
expression: model.keyPair.keyUid !== originModelWithoutWatchOnlyAcc.addWatchOnlyAccKeyUid
expectedRoles: ["keyPair"]
}
]
}
function openEmojiPopup(showLeft) {
if (!root.store.emojiPopup) {
return
@ -191,7 +175,7 @@ Item {
anchors.horizontalCenter: parent.horizontalCenter
userProfilePublicKey: root.store.userProfilePublicKey
originModel: root.store.editMode? [] : d.originModelWithoutWatchOnlyAcc
originModel: root.store.editMode? [] : root.store.originModel
selectedOrigin: root.store.selectedOrigin
caretVisible: !root.store.editMode
enabled: !root.store.editMode

View File

@ -54,6 +54,9 @@ BasePopupStore {
Constants.addAccountPopup.predefinedPaths.ethereumLedgerLive
]
readonly property bool isWatchOnlyImport: root.selectedOrigin.pairType === Constants.addAccountPopup.keyPairType.unknown &&
root.selectedOrigin.keyUid === Constants.appTranslatableConstants.addAccountLabelOptionAddWatchOnlyAcc
signal showLimitPopup(int warningType)
signal resolvedENS(string resolvedPubKey, string resolvedAddress, string uuid)
@ -97,23 +100,31 @@ BasePopupStore {
return
}
if(!event) {
if (!root.editMode && root.remainingAccountCapacity() === 0) {
root.showLimitPopup(0)
return
}
root.currentState.doPrimaryAction()
const handleEvent = !event || event.key === Qt.Key_Return || event.key === Qt.Key_Enter
if (!handleEvent) {
return
}
else if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter) {
if (handleEvent && !!event) {
event.accepted = true
if (!root.editMode && root.remainingAccountCapacity() === 0) {
root.showLimitPopup(0)
return
}
root.currentState.doPrimaryAction()
}
if (root.editMode) {
root.currentState.doPrimaryAction()
return
}
if (root.isWatchOnlyImport && root.remainingWatchOnlyAccountCapacity() === 0) {
root.showLimitPopup(Constants.LimitWarning.WatchOnlyAccounts)
return
}
if (root.remainingAccountCapacity() === 0) {
root.showLimitPopup(Constants.LimitWarning.Accounts)
return
}
root.currentState.doPrimaryAction()
}
function getSeedPhrase() {

View File

@ -1434,4 +1434,10 @@ QtObject {
Theme.svg("walletconnect"),
Theme.png("status-logo")
]
enum LimitWarning {
Accounts,
Keypairs,
WatchOnlyAccounts
}
}