forked from getAlby/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnlock.tsx
65 lines (59 loc) · 1.86 KB
/
Unlock.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import * as LocalAuthentication from "expo-local-authentication";
import { router, Stack } from "expo-router";
import React, { useCallback, useEffect } from "react";
import { Image, View } from "react-native";
import { Button } from "~/components/ui/button";
import { Text } from "~/components/ui/text";
import { useSession } from "~/hooks/useSession";
export function Unlock() {
const [isUnlocking, setIsUnlocking] = React.useState(false);
const { signIn } = useSession();
const handleUnlock = useCallback(async () => {
// The call `signIn()` below triggers a re-render of the component
// and would prompt the user again (before the actual redirect
// happens and the view is replaced)
if (isUnlocking) {
return;
}
try {
setIsUnlocking(true);
const biometricAuth = await LocalAuthentication.authenticateAsync({
promptMessage: "Unlock Alby Go",
});
if (biometricAuth.success) {
signIn();
router.replace("/");
}
} catch (e) {
console.error(e);
} finally {
setIsUnlocking(false);
}
}, [isUnlocking, signIn]);
useEffect(() => {
handleUnlock();
}, [handleUnlock]);
return (
<View className="flex-1 flex flex-col p-6 gap-3">
<Stack.Screen
options={{
title: "Unlock",
headerShown: false,
}}
/>
<View className="flex-1 flex items-center justify-center gap-4">
<Image
source={require("./../assets/logo.png")}
className="mb-10 w-52 h-52"
resizeMode="contain"
/>
<Text className="font-semibold2 text-4xl text-center text-foreground">
Unlock to continue
</Text>
</View>
<Button size="lg" onPress={handleUnlock} disabled={isUnlocking}>
<Text>{isUnlocking ? "Unlocking..." : "Unlock Wallet"}</Text>
</Button>
</View>
);
}