Skip to content

Commit

Permalink
Fix/bug biometric enable pin enter (#164)
Browse files Browse the repository at this point in the history
Co-authored-by: Sai Ranjit Tummalapalli <[email protected]>
Signed-off-by: Poonam Ghewande <[email protected]>
  • Loading branch information
poonam-ghewande and sairanjit committed Apr 16, 2024
1 parent fa3771c commit db9d567
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 50 deletions.
Binary file modified app/assets/img/adeya-logo-secondary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 10 additions & 50 deletions app/screens/PINEnter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ const PINEnter: React.FC<PINEnterProps> = ({ setAuthenticated, usage = PINEntryU
const { t } = useTranslation()
const { checkPIN, getWalletCredentials, isBiometricsActive, disableBiometrics } = useAuth()
const [store, dispatch] = useStore()
const [PIN, setPIN] = useState<string>('')
const [continueEnabled, setContinueEnabled] = useState(true)
const [displayLockoutWarning, setDisplayLockoutWarning] = useState(false)
const [biometricsErr, setBiometricsErr] = useState(false)
Expand Down Expand Up @@ -261,59 +260,24 @@ const PINEnter: React.FC<PINEnterProps> = ({ setAuthenticated, usage = PINEntryU
}
}

const handlePINInput = async (PIN: string) => {
setPIN(PIN)
if (usage === PINEntryUsage.PINCheck) {
await verifyPIN(PIN)
}
const handlePinInput = async (PIN: string) => {
if (PIN.length === minPINLength) {
try {
Keyboard.dismiss()
const result = await checkPIN(PIN)
if (!result) {
const newAttempt = store.loginAttempt.loginAttempts + 1
if (!getLockoutPenalty(newAttempt)) {
// skip displaying modals if we are going to lockout
setAlertModalVisible(true)
}
setContinueEnabled(true)
setContinueEnabled(false)

// log incorrect login attempts
dispatch({
type: DispatchAction.ATTEMPT_UPDATED,
payload: [{ loginAttempts: newAttempt }],
})

return
if (usage === PINEntryUsage.PINCheck) {
await verifyPIN(PIN)
}

// reset login attempts if login is successful
dispatch({
type: DispatchAction.ATTEMPT_UPDATED,
payload: [{ loginAttempts: 0 }],
})

setAuthenticated(true)
if (usage === PINEntryUsage.WalletUnlock) {
await unlockWalletWithPIN(PIN)
}
} catch (error: unknown) {
// TODO:(jl) process error
}
}
}
const onPINInputCompleted = async (PIN: string) => {
try {
setContinueEnabled(false)

if (usage === PINEntryUsage.PINCheck) {
await verifyPIN(PIN)
}

if (usage === PINEntryUsage.WalletUnlock) {
await unlockWalletWithPIN(PIN)
}
} catch (error: unknown) {
// TODO:(jl) process error
}
}

// NOTE: Using local state here is to prevent modal issues caused by other modals being left open when the device sleeps.
// When two modals are attempted to be mounted at once it causes issues on iOS - in this case it causes the second modal
Expand Down Expand Up @@ -362,7 +326,7 @@ const PINEnter: React.FC<PINEnterProps> = ({ setAuthenticated, usage = PINEntryU
<Text style={[TextTheme.normal, { alignSelf: 'center', marginBottom: 16 }]}>{t('PINEnter.EnterPIN')}</Text>
)}
<PINInput
onPINChanged={(p: string) => handlePINInput(p)}
onPINChanged={(p: string) => handlePinInput(p)}
testID={testIdWithKey('EnterPIN')}
accessibilityLabel={t('PINEnter.EnterPIN')}
autoFocus={true}
Expand Down Expand Up @@ -392,12 +356,8 @@ const PINEnter: React.FC<PINEnterProps> = ({ setAuthenticated, usage = PINEntryU
title={t('PINEnter.Unlock')}
buttonType={ButtonType.Primary}
testID={testIdWithKey('Enter')}
disabled={!continueEnabled}
accessibilityLabel={t('PINEnter.Unlock')}
onPress={() => {
Keyboard.dismiss()
onPINInputCompleted(PIN)
}}>
disabled={continueEnabled}
accessibilityLabel={t('PINEnter.Unlock')}>
{!continueEnabled && <ButtonLoading />}
</Button>
</View>
Expand Down

0 comments on commit db9d567

Please sign in to comment.