Skip to content

Commit

Permalink
fix: Enforce watch only account limits
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjba authored and alaibe committed Jan 16, 2025
1 parent bddb1ff commit 4fea2b5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 40 deletions.
16 changes: 5 additions & 11 deletions ui/imports/shared/popups/addaccount/AddAccountPopup.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
18 changes: 1 addition & 17 deletions ui/imports/shared/popups/addaccount/states/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
35 changes: 23 additions & 12 deletions ui/imports/shared/popups/addaccount/stores/AddAccountStore.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
}
}

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() {
Expand Down
6 changes: 6 additions & 0 deletions ui/imports/utils/Constants.qml
Original file line number Diff line number Diff line change
Expand Up @@ -1434,4 +1434,10 @@ QtObject {
Theme.svg("walletconnect"),
Theme.png("status-logo")
]

enum LimitWarning {
Accounts,
Keypairs,
WatchOnlyAccounts
}
}

0 comments on commit 4fea2b5

Please sign in to comment.