Skip to content

Commit

Permalink
privacy lock - update label (#949)
Browse files Browse the repository at this point in the history
* feat: add authentication name to privacy lock label
Fixes #911

* translation: add entries

* feat: fix fingerprint check

* feat: refactor label to accept param

To allow localized string composition

* translation: update entries

* feat: replace device's passcode with device's lock
To avoid confusion with app passcode
  • Loading branch information
kyleleow authored Sep 28, 2021
1 parent c4af24b commit 8f1e080
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 6 deletions.
35 changes: 35 additions & 0 deletions mobile-app/app/contexts/LocalAuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as LocalAuthentication from 'expo-local-authentication'
import { AuthenticationType, LocalAuthenticationOptions, SecurityLevel } from 'expo-local-authentication'
import React, { createContext, useContext, useEffect, useState } from 'react'
import { PrivacyLockPersistence } from '@api/wallet/privacy_lock'
import { Platform } from 'react-native'

export interface PrivacyLockContextI {
// user's hardware condition, external
Expand All @@ -13,6 +14,7 @@ export interface PrivacyLockContextI {
isDeviceProtected: boolean
isAuthenticating: boolean
setIsAuthenticating: (isAuthenticating: boolean) => void
getAuthenticationNaming: () => string | undefined

// API
isEnabled: boolean
Expand Down Expand Up @@ -93,6 +95,39 @@ export function PrivacyLockContextProvider (props: React.PropsWithChildren<any>)
return
}
return await context.setEnabled(!isPrivacyLock)
},
getAuthenticationNaming: () => {
if (Platform.OS === 'ios') {
switch (securityLevel) {
case SecurityLevel.SECRET:
return 'device\'s lock'

case SecurityLevel.BIOMETRIC:
if (biometricHardwares.includes(AuthenticationType.FACIAL_RECOGNITION)) {
return 'Face ID'
} else if (biometricHardwares.includes(AuthenticationType.FINGERPRINT)) {
return 'Touch ID'
} else {
// no-op for iris scanner(android-only)
}
}
} else if (Platform.OS === 'android') {
switch (securityLevel) {
case SecurityLevel.SECRET:
return 'device\'s lock'

case SecurityLevel.BIOMETRIC:
if (biometricHardwares.includes(AuthenticationType.FACIAL_RECOGNITION)) {
return 'face recognition'
} else if (biometricHardwares.includes(AuthenticationType.FINGERPRINT)) {
return 'fingerprint'
} else {
return 'iris scan'
}
}
} else {
// no-op: does not handle other devices
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export function SettingsScreen ({ navigation }: Props): JSX.Element {
onToggle={async () => {
await localAuth.togglePrivacyLock()
}}
authenticationName={localAuth.getAuthenticationNaming()}
/>
)
}
Expand Down Expand Up @@ -224,8 +225,9 @@ function RowExitWalletItem (): JSX.Element {

function PrivacyLockToggle ({
value,
onToggle
}: { disabled?: boolean, value: boolean, onToggle: (newValue: boolean) => void }): JSX.Element {
onToggle,
authenticationName
}: { disabled?: boolean, value: boolean, onToggle: (newValue: boolean) => void, authenticationName?: string }): JSX.Element {
return (
<>
<ThemedView
Expand All @@ -234,7 +236,8 @@ function PrivacyLockToggle ({
style={tailwind('flex p-4 pr-2 flex-row items-center justify-between')}
>
<ThemedText testID='text_privacy_lock' style={tailwind('font-medium')}>
{translate('screens/Settings', 'Privacy Lock')}
{authenticationName !== undefined &&
translate('screens/Settings', 'Secure with {{option}}', { option: translate('screens/Settings', authenticationName) })}
</ThemedText>
<Switch
onValueChange={onToggle}
Expand Down
10 changes: 9 additions & 1 deletion mobile-app/app/translations/languages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,15 @@
"ADDITIONAL OPTIONS": "WEITERE OPTIONEN",
"SECURITY": "SICHERHEITSEINSTELLUNGEN",
"Privacy Lock": "App-Passwortschutz",
"Auto-locks wallet if there is no activity for 1 min.": "Automatische Wallet-Sperre bei 1 Min. Inaktivität"
"Auto-locks wallet if there is no activity for 1 min.": "Automatische Wallet-Sperre bei 1 Min. Inaktivität",
"Secure with {{option}}": "Secure with {{option}}",
"device's passcode": "device's passcode",
"Face ID": "Face ID",
"Touch ID": "Touch ID",
"device's lock": "device's lock",
"face recognition": "face recognition",
"fingerprint": "fingerprint",
"iris scan": "iris scan"
},
"screens/AboutScreen": {
"About": "Über",
Expand Down
10 changes: 9 additions & 1 deletion mobile-app/app/translations/languages/zh-Hans.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,15 @@
"ADDITIONAL OPTIONS": "更多选项",
"SECURITY": "安全设定",
"Privacy Lock": "隐私锁定",
"Auto-locks wallet if there is no activity for 1 min.": "钱包如静止超过 1 分钟,会自动上锁。"
"Auto-locks wallet if there is no activity for 1 min.": "钱包如静止超过 1 分钟,会自动上锁。",
"Secure with {{option}}": "Secure with {{option}}",
"device's passcode": "device's passcode",
"Face ID": "Face ID",
"Touch ID": "Touch ID",
"device's lock": "device's lock",
"face recognition": "face recognition",
"fingerprint": "fingerprint",
"iris scan": "iris scan"
},
"screens/AboutScreen": {
"About": "关于",
Expand Down
10 changes: 9 additions & 1 deletion mobile-app/app/translations/languages/zh-Hant.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,15 @@
"ADDITIONAL OPTIONS": "更多選項",
"SECURITY": "安全設定",
"Privacy Lock": "隱私鎖定",
"Auto-locks wallet if there is no activity for 1 min.": "錢包如静止超過 1 分鐘,會自動上鎖。"
"Auto-locks wallet if there is no activity for 1 min.": "錢包如静止超過 1 分鐘,會自動上鎖。",
"Secure with {{option}}": "Secure with {{option}}",
"device's passcode": "device's passcode",
"Face ID": "Face ID",
"Touch ID": "Touch ID",
"device's lock": "device's lock",
"face recognition": "face recognition",
"fingerprint": "fingerprint",
"iris scan": "iris scan"
},
"screens/AboutScreen": {
"About": "關於",
Expand Down

0 comments on commit 8f1e080

Please sign in to comment.