mirror of
https://github.com/status-im/status-desktop.git
synced 2025-03-04 00:11:12 +00:00
chore(@desktop/keycard): usingBiometricLogin
prop added to the user profile global instance
This commit is contained in:
parent
3687df2a2f
commit
4e257539b8
@ -48,7 +48,7 @@ proc localAppSettings*(self: GlobalSingleton): LocalAppSettings =
|
||||
proc userProfile*(self: GlobalSingleton): UserProfile =
|
||||
var userProfile {.global.}: UserProfile
|
||||
if (userProfile.isNil):
|
||||
userProfile = newUserProfile()
|
||||
userProfile = newUserProfile(singletonInstance.localAccountSettings)
|
||||
return userProfile
|
||||
|
||||
proc utils*(self: GlobalSingleton): Utils =
|
||||
|
@ -2,8 +2,11 @@ import NimQml
|
||||
|
||||
import ../../app_service/common/utils
|
||||
|
||||
import local_account_settings
|
||||
|
||||
QtObject:
|
||||
type UserProfile* = ref object of QObject
|
||||
localAccountSettings: LocalAccountSettings
|
||||
# fields which cannot change
|
||||
username: string
|
||||
keyUid: string
|
||||
@ -24,9 +27,10 @@ QtObject:
|
||||
proc delete*(self: UserProfile) =
|
||||
self.QObject.delete
|
||||
|
||||
proc newUserProfile*(): UserProfile =
|
||||
proc newUserProfile*(localAccountSettings: LocalAccountSettings): UserProfile =
|
||||
new(result, delete)
|
||||
result.setup
|
||||
result.localAccountSettings = localAccountSettings
|
||||
|
||||
proc setFixedData*(self: UserProfile, username: string, keyUid: string, pubKey: string, isKeycardUser: bool) =
|
||||
self.username = username
|
||||
@ -50,6 +54,14 @@ QtObject:
|
||||
QtProperty[bool] isKeycardUser:
|
||||
read = getIsKeycardUser
|
||||
|
||||
proc getUsingBiometricLogin*(self: UserProfile): bool {.slot.} =
|
||||
if(not defined(macosx)):
|
||||
return false
|
||||
return self.localAccountSettings.getStoreToKeychainValue() == LS_VALUE_STORE
|
||||
QtProperty[bool] usingBiometricLogin:
|
||||
read = getUsingBiometricLogin
|
||||
|
||||
|
||||
proc nameChanged*(self: UserProfile) {.signal.}
|
||||
|
||||
proc getUsername*(self: UserProfile): string {.slot.} =
|
||||
|
@ -69,14 +69,6 @@ proc validSeedPhrase*(self: Controller, seedPhrase: string): bool =
|
||||
let err = self.accountsService.validateMnemonic(seedPhrase)
|
||||
return err.len == 0
|
||||
|
||||
proc loggedInUserUsesBiometricLogin*(self: Controller): bool =
|
||||
if(not defined(macosx)):
|
||||
return false
|
||||
let value = singletonInstance.localAccountSettings.getStoreToKeychainValue()
|
||||
if (value != LS_VALUE_STORE):
|
||||
return false
|
||||
return true
|
||||
|
||||
proc authenticateUser*(self: Controller, keyUid = "") =
|
||||
let data = SharedKeycarModuleAuthenticationArgs(uniqueIdentifier: UNIQUE_WALLET_SECTION_ACCOUNTS_MODULE_IDENTIFIER,
|
||||
keyUid: keyUid)
|
||||
|
@ -53,7 +53,4 @@ method authenticateUser*(self: AccessInterface) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method onUserAuthenticated*(self: AccessInterface, password: string) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method loggedInUserUsesBiometricLogin*(self: AccessInterface): bool {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
@ -173,9 +173,6 @@ method getDerivedAddressForPrivateKey*(self: Module, privateKey: string) =
|
||||
method validSeedPhrase*(self: Module, value: string): bool =
|
||||
return self.controller.validSeedPhrase(value)
|
||||
|
||||
method loggedInUserUsesBiometricLogin*(self: Module): bool =
|
||||
return self.controller.loggedInUserUsesBiometricLogin()
|
||||
|
||||
method authenticateUser*(self: Module) =
|
||||
if singletonInstance.userProfile.getIsKeycardUser():
|
||||
let keyUid = singletonInstance.userProfile.getKeyUid()
|
||||
|
@ -282,7 +282,4 @@ QtObject:
|
||||
proc userAuthentiactionFail*(self: View) {.signal.}
|
||||
|
||||
proc authenticateUser*(self: View) {.slot.} =
|
||||
self.delegate.authenticateUser()
|
||||
|
||||
proc loggedInUserUsesBiometricLogin*(self: View): bool {.slot.} =
|
||||
return self.delegate.loggedInUserUsesBiometricLogin()
|
||||
self.delegate.authenticateUser()
|
@ -412,16 +412,8 @@ proc getMnemonicWordAtIndex*(self: Controller, index: int): string =
|
||||
return
|
||||
return self.privacyService.getMnemonicWordAtIndex(index)
|
||||
|
||||
proc loggedInUserUsesBiometricLogin*(self: Controller): bool =
|
||||
if(not defined(macosx)):
|
||||
return false
|
||||
let value = singletonInstance.localAccountSettings.getStoreToKeychainValue()
|
||||
if (value != LS_VALUE_STORE):
|
||||
return false
|
||||
return true
|
||||
|
||||
proc tryToObtainDataFromKeychain*(self: Controller) =
|
||||
if(not self.loggedInUserUsesBiometricLogin()):
|
||||
if(not singletonInstance.userProfile.getUsingBiometricLogin()):
|
||||
return
|
||||
let loggedInAccount = self.getLoggedInAccount()
|
||||
self.keychainService.tryToObtainData(loggedInAccount.name)
|
||||
|
@ -85,7 +85,7 @@ method resolveKeycardNextState*(self: EnterPinState, keycardFlowType: string, ke
|
||||
keycardEvent.error == ErrorPIN:
|
||||
controller.setKeycardData($keycardEvent.pinRetries)
|
||||
if keycardEvent.pinRetries > 0:
|
||||
if controller.loggedInUserUsesBiometricLogin() and not controller.usePinFromBiometrics():
|
||||
if singletonInstance.userProfile.getUsingBiometricLogin() and not controller.usePinFromBiometrics():
|
||||
return createState(StateType.WrongKeychainPin, self.flowType, nil)
|
||||
return createState(StateType.WrongPin, self.flowType, nil)
|
||||
return createState(StateType.MaxPinRetriesReached, self.flowType, nil)
|
||||
|
@ -1,9 +1,10 @@
|
||||
import parseutils, sequtils, sugar, chronicles
|
||||
import ../../../../global/global_singleton
|
||||
import ../../../../../app_service/service/keycard/constants
|
||||
import ../controller
|
||||
from ../../../../../app_service/service/keycard/service import KCSFlowType
|
||||
from ../../../../../app_service/service/keycard/service import PINLengthForStatusApp
|
||||
from ../../../../../app_service/service/keycard/service import PUKLengthForStatusApp
|
||||
import ../controller
|
||||
import state
|
||||
|
||||
logScope:
|
||||
@ -325,7 +326,7 @@ proc ensureReaderAndCardPresenceAndResolveNextState*(state: State, keycardFlowTy
|
||||
return createState(StateType.MaxPukRetriesReached, state.flowType, nil)
|
||||
if keycardFlowType == ResponseTypeValueEnterPIN:
|
||||
if keycardEvent.keyUid == controller.getKeyUidWhichIsBeingAuthenticating():
|
||||
if controller.loggedInUserUsesBiometricLogin():
|
||||
if singletonInstance.userProfile.getUsingBiometricLogin():
|
||||
if keycardEvent.error.len > 0 and
|
||||
keycardEvent.error == ErrorPIN:
|
||||
controller.setKeycardData($keycardEvent.pinRetries)
|
||||
|
@ -121,9 +121,6 @@ method setSelectedKeyPair*(self: AccessInterface, item: KeyPairItem) {.base.} =
|
||||
method setKeyPairStoredOnKeycard*(self: AccessInterface, cardMetadata: CardMetadata) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method loggedInUserUsesBiometricLogin*(self: AccessInterface): bool {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method migratingProfileKeyPair*(self: AccessInterface): bool {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
|
@ -102,9 +102,6 @@ method getSeedPhrase*[T](self: Module[T]): string =
|
||||
method validSeedPhrase*[T](self: Module[T], value: string): bool =
|
||||
return self.controller.validSeedPhrase(value)
|
||||
|
||||
method loggedInUserUsesBiometricLogin*[T](self: Module[T]): bool =
|
||||
return self.controller.loggedInUserUsesBiometricLogin()
|
||||
|
||||
method migratingProfileKeyPair*[T](self: Module[T]): bool =
|
||||
return self.controller.getSelectedKeyPairIsProfile()
|
||||
|
||||
@ -332,7 +329,7 @@ method runFlow*[T](self: Module[T], flowToRun: FlowType, keyUid = "", bip44Path
|
||||
self.tmpLocalState = newReadingKeycardState(flowToRun, nil)
|
||||
self.controller.runSignFlow(keyUid, bip44Path, txHash)
|
||||
return
|
||||
if self.controller.loggedInUserUsesBiometricLogin():
|
||||
if singletonInstance.userProfile.getUsingBiometricLogin():
|
||||
self.controller.tryToObtainDataFromKeychain()
|
||||
return
|
||||
self.view.setCurrentState(newEnterPasswordState(flowToRun, nil))
|
||||
|
@ -188,9 +188,6 @@ QtObject:
|
||||
proc validSeedPhrase*(self: View, value: string): bool {.slot.} =
|
||||
return self.delegate.validSeedPhrase(value)
|
||||
|
||||
proc loggedInUserUsesBiometricLogin*(self: View): bool {.slot.} =
|
||||
return self.delegate.loggedInUserUsesBiometricLogin()
|
||||
|
||||
proc migratingProfileKeyPair*(self: View): bool {.slot.} =
|
||||
return self.delegate.migratingProfileKeyPair()
|
||||
|
||||
|
@ -63,6 +63,7 @@ StatusModal {
|
||||
property int selectedAccountType: SelectGeneratedAccount.AddAccountType.GenerateNew
|
||||
readonly property bool authenticationNeeded: d.selectedAccountType !== SelectGeneratedAccount.AddAccountType.WatchOnly &&
|
||||
d.password === ""
|
||||
property string addAccountIcon: ""
|
||||
|
||||
|
||||
|
||||
@ -133,6 +134,14 @@ StatusModal {
|
||||
}
|
||||
|
||||
onOpened: {
|
||||
d.addAccountIcon = "password"
|
||||
if (RootStore.loggedInUserUsesBiometricLogin()) {
|
||||
d.addAccountIcon = "touch-id"
|
||||
}
|
||||
else if (RootStore.loggedInUserIsKeycardUser()) {
|
||||
d.addAccountIcon = "keycard"
|
||||
}
|
||||
|
||||
accountNameInput.input.asset.emoji = StatusQUtils.Emoji.getRandomEmoji(StatusQUtils.Emoji.size.verySmall)
|
||||
colorSelectionGrid.selectedColorIndex = Math.floor(Math.random() * colorSelectionGrid.model.length)
|
||||
accountNameInput.input.edit.forceActiveFocus()
|
||||
@ -277,17 +286,7 @@ StatusModal {
|
||||
return accountNameInput.text !== "" && advancedSelection.isValid
|
||||
}
|
||||
|
||||
icon.name: {
|
||||
if (d.authenticationNeeded) {
|
||||
if (RootStore.loggedInUserUsesBiometricLogin())
|
||||
return "touch-id"
|
||||
if (RootStore.loggedInUserIsKeycardUser())
|
||||
return "keycard"
|
||||
return "password"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
icon.name: d.authenticationNeeded? d.addAccountIcon : ""
|
||||
highlighted: focus
|
||||
|
||||
Keys.onReturnPressed: d.nextButtonClicked()
|
||||
|
@ -228,7 +228,7 @@ QtObject {
|
||||
}
|
||||
|
||||
function loggedInUserUsesBiometricLogin() {
|
||||
return walletSectionAccounts.loggedInUserUsesBiometricLogin()
|
||||
return userProfile.usingBiometricLogin
|
||||
}
|
||||
|
||||
function loggedInUserIsKeycardUser() {
|
||||
|
@ -423,7 +423,7 @@ StatusModal {
|
||||
height: Constants.keycard.general.footerButtonsHeight
|
||||
text: {
|
||||
if (root.sharedKeycardModule.currentState.flowType === Constants.keycardSharedFlow.authentication) {
|
||||
if (root.sharedKeycardModule.loggedInUserUsesBiometricLogin()) {
|
||||
if (userProfile.usingBiometricLogin) {
|
||||
if (root.sharedKeycardModule.currentState.stateType === Constants.keycardSharedState.enterPassword ||
|
||||
root.sharedKeycardModule.currentState.stateType === Constants.keycardSharedState.wrongPassword)
|
||||
return qsTr("Use biometrics instead")
|
||||
@ -462,7 +462,7 @@ StatusModal {
|
||||
}
|
||||
}
|
||||
if (root.sharedKeycardModule.currentState.flowType === Constants.keycardSharedFlow.authentication) {
|
||||
if (root.sharedKeycardModule.loggedInUserUsesBiometricLogin() &&
|
||||
if (userProfile.usingBiometricLogin &&
|
||||
(root.sharedKeycardModule.currentState.stateType === Constants.keycardSharedState.pluginReader ||
|
||||
root.sharedKeycardModule.currentState.stateType === Constants.keycardSharedState.insertKeycard ||
|
||||
root.sharedKeycardModule.currentState.stateType === Constants.keycardSharedState.keycardInserted ||
|
||||
@ -704,18 +704,18 @@ StatusModal {
|
||||
}
|
||||
icon.name: {
|
||||
if (root.sharedKeycardModule.currentState.flowType === Constants.keycardSharedFlow.setupNewKeycard) {
|
||||
if (root.sharedKeycardModule.currentState.stateType === Constants.keycardSharedState.seedPhraseEnterWords ||
|
||||
root.sharedKeycardModule.currentState.stateType === Constants.keycardSharedState.enterSeedPhrase) {
|
||||
if (root.sharedKeycardModule.loggedInUserUsesBiometricLogin())
|
||||
return "touch-id"
|
||||
if (userProfile.isKeycardUser())
|
||||
return "keycard"
|
||||
return "password"
|
||||
if (root.sharedKeycardModule.migratingProfileKeyPair() &&
|
||||
(root.sharedKeycardModule.currentState.stateType === Constants.keycardSharedState.seedPhraseEnterWords ||
|
||||
root.sharedKeycardModule.currentState.stateType === Constants.keycardSharedState.enterSeedPhrase)) {
|
||||
if (userProfile.usingBiometricLogin)
|
||||
return "touch-id"
|
||||
if (userProfile.isKeycardUser)
|
||||
return "keycard"
|
||||
return "password"
|
||||
}
|
||||
}
|
||||
if (root.sharedKeycardModule.currentState.flowType === Constants.keycardSharedFlow.authentication) {
|
||||
if (root.sharedKeycardModule.loggedInUserUsesBiometricLogin()) {
|
||||
if (userProfile.usingBiometricLogin) {
|
||||
if (root.sharedKeycardModule.currentState.stateType === Constants.keycardSharedState.pluginReader ||
|
||||
root.sharedKeycardModule.currentState.stateType === Constants.keycardSharedState.insertKeycard ||
|
||||
root.sharedKeycardModule.currentState.stateType === Constants.keycardSharedState.keycardInserted ||
|
||||
|
Loading…
x
Reference in New Issue
Block a user