mirror of
https://github.com/status-im/status-desktop.git
synced 2025-02-23 20:18:47 +00:00
83 lines
1.9 KiB
QML
83 lines
1.9 KiB
QML
import QtQuick 2.15
|
|
|
|
import StatusQ 0.1
|
|
import StatusQ.Core.Utils 0.1
|
|
|
|
import Storybook 1.0
|
|
|
|
Keychain {
|
|
id: root
|
|
|
|
required property Item parent
|
|
|
|
service: "StatusStorybookMocked"
|
|
|
|
// shadowing Keychain's "loading" property
|
|
readonly property alias loading: d.loading
|
|
|
|
readonly property QObject _d: QObject {
|
|
id: d
|
|
|
|
property bool loading: false
|
|
property string key
|
|
property string value
|
|
property var store: ({})
|
|
|
|
BiometricsPopup {
|
|
id: biometricsPopup
|
|
|
|
parent: root.parent
|
|
x: parent.width - width
|
|
}
|
|
}
|
|
|
|
// shadowing Keychain's functions
|
|
function saveCredential(account, password) {
|
|
d.store[account] = password
|
|
return Keychain.StatusSuccess
|
|
}
|
|
|
|
function deleteCredential(account) {
|
|
delete d.store[account]
|
|
return Keychain.StatusSuccess
|
|
}
|
|
|
|
function requestGetCredential(reason, account) {
|
|
d.loading = true
|
|
d.key = account
|
|
biometricsPopup.open()
|
|
}
|
|
|
|
function hasCredential(account) {
|
|
return d.store[account] === undefined ? Keychain.StatusNotFound
|
|
: Keychain.StatusSuccess
|
|
}
|
|
|
|
function cancelActiveRequest() {
|
|
if (!d.loading)
|
|
return
|
|
|
|
d.loading = false
|
|
biometricsPopup.cancel()
|
|
}
|
|
|
|
readonly property Connections connections: Connections {
|
|
target: biometricsPopup
|
|
|
|
function onObtainingPasswordSuccess(password) {
|
|
d.loading = false
|
|
|
|
const value = d.store[d.key]
|
|
const status = (value === undefined) ? Keychain.StatusNotFound
|
|
: Keychain.StatusSuccess
|
|
|
|
root.getCredentialRequestCompleted(status, value)
|
|
}
|
|
|
|
function onCancelled() {
|
|
d.loading = false
|
|
root.getCredentialRequestCompleted(Keychain.StatusCancelled, "")
|
|
}
|
|
}
|
|
}
|