Skip to content

Commit

Permalink
feat(wallet): useCheckAppLock hook uses biometrics
Browse files Browse the repository at this point in the history
  • Loading branch information
omniwired committed Feb 16, 2024
1 parent 842eea5 commit 3754567
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 29 deletions.
31 changes: 31 additions & 0 deletions packages/hooks/useCheckAppLock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {
authenticateAsync,
hasHardwareAsync,
isEnrolledAsync,
} from "expo-local-authentication";
import { useSelector } from "react-redux";

import { selectIsAppLocked, setLock } from "@/store/slices/settings";
import { useAppDispatch } from "@/store/store";

export const useCheckAppLock = () => {
const isAppLocked = useSelector(selectIsAppLocked);
const dispatch = useAppDispatch();

// is wallet unlocked?
console.log(isAppLocked);
if (isAppLocked) {
hasHardwareAsync().then((hasHardware) => {
console.log("hasHardware", hasHardware);
if (hasHardware) {
isEnrolledAsync().then((result) => {
console.log("authenticateAsync", result);
authenticateAsync().then((result) => {
console.log("authenticateAsync", result);
dispatch(setLock(!result.success));
});
});
}
});
}
};
32 changes: 3 additions & 29 deletions packages/screens/Mini/Wallet/TokenScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import {
authenticateAsync,
hasHardwareAsync,
isEnrolledAsync,
} from "expo-local-authentication";
import { Fragment, useState } from "react";
import { Fragment } from "react";
import { FlatList, View } from "react-native";
import { useSelector } from "react-redux";

import { AddedToken } from "./components/AddedToken";
import TransactionItem from "./components/TransactionItem";
Expand All @@ -20,11 +14,10 @@ import { CustomPressable } from "@/components/buttons/CustomPressable";
import { Separator } from "@/components/separators/Separator";
import { SpacerColumn } from "@/components/spacer";
import { useBalances } from "@/hooks/useBalances";
import { useCheckAppLock } from "@/hooks/useCheckAppLock";
import { useSelectedNetworkId } from "@/hooks/useSelectedNetwork";
import { useSearchTx } from "@/hooks/wallet/useSearchTx";
import { useSelectedNativeWallet } from "@/hooks/wallet/useSelectedNativeWallet";
import { selectIsAppLocked, setLock } from "@/store/slices/settings";
import { useAppDispatch } from "@/store/store";
import { ScreenFC, useAppNavigation } from "@/utils/navigation";
import { neutral88, neutralA3, secondaryColor } from "@/utils/style/colors";
import {
Expand All @@ -35,33 +28,14 @@ import {
import { layout } from "@/utils/style/layout";

const TokenScreen: ScreenFC<"MiniWallets"> = ({ navigation }) => {
useCheckAppLock();
const selectedWallet = useSelectedNativeWallet();

const isAppLocked = useSelector(selectIsAppLocked);
const dispatch = useAppDispatch();

const balances = useBalances(
selectedWallet?.networkId,
selectedWallet?.address,
);

// is wallet unlocked?
console.log(isAppLocked);
if (isAppLocked) {
hasHardwareAsync().then((hasHardware) => {
console.log("hasHardware", hasHardware);
if (hasHardware) {
isEnrolledAsync().then((result) => {
console.log("authenticateAsync", result);
authenticateAsync().then((result) => {
console.log("authenticateAsync", result);
dispatch(setLock(result.success));
});
});
}
});
}

return (
<>
<View
Expand Down

0 comments on commit 3754567

Please sign in to comment.