Skip to content

Commit

Permalink
feat: camera permissions (#48)
Browse files Browse the repository at this point in the history
* fix: wallet list spacing

* fix: improve camera permission handling and enable usage without camera permissions

* Update pages/send/Send.tsx

Co-authored-by: Roland <33993199+rolznz@users.noreply.github.com>

* fix: remove obsolete section

* fix: revert wallet changes

---------

Co-authored-by: Roland Bewick <roland.bewick@gmail.com>
Co-authored-by: Roland <33993199+rolznz@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 27, 2024
1 parent 31dabf3 commit 379f20f
Showing 1 changed file with 48 additions and 40 deletions.
88 changes: 48 additions & 40 deletions pages/send/Send.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ import { Input } from "~/components/ui/input";
import { errorToast } from "~/lib/errorToast";
import Loading from "~/components/Loading";
import { FocusableCamera } from "~/components/FocusableCamera";
import { PermissionStatus } from "expo-modules-core/src/PermissionsInterface";
import { Invoice } from "@getalby/lightning-tools";

export function Send() {
const { url } = useLocalSearchParams<{ url: string }>();
const [isScanning, setScanning] = React.useState(false);
const [isLoading, setLoading] = React.useState(false);
const [keyboardOpen, setKeyboardOpen] = React.useState(false);
const [keyboardText, setKeyboardText] = React.useState("");
const [permissionStatus, setPermissionStatus] = React.useState(PermissionStatus.UNDETERMINED);

useEffect(() => {
if (url) {
Expand All @@ -40,6 +43,7 @@ export function Send() {

async function scan() {
const { status } = await Camera.requestCameraPermissionsAsync();
setPermissionStatus(status);
setScanning(status === "granted");
}

Expand Down Expand Up @@ -110,6 +114,12 @@ export function Send() {
},
});
} else {

// Check if this is a valid invoice
new Invoice({
pr: text,
});

router.replace({
pathname: "/send/confirm",
params: { invoice: text, originalText },
Expand Down Expand Up @@ -139,36 +149,15 @@ export function Send() {
{isScanning && (
<>
<FocusableCamera onScanned={handleScanned} />
<View className="flex flex-row items-stretch justify-center gap-4 p-6">
<Button
onPress={openKeyboard}
variant="secondary"
className="flex flex-col gap-2 flex-1"
>
<KeyboardIcon className="text-secondary-foreground" />
<Text>Manual</Text>
</Button>
<Button
variant="secondary"
className="flex flex-col gap-2"
onPress={() => {
router.push("/send/address-book");
}}
>
<BookUser className="text-secondary-foreground" />
<Text>Contacts</Text>
</Button>
<Button
onPress={paste}
variant="secondary"
className="flex flex-col gap-2 flex-1"
>
<ClipboardPaste className="text-secondary-foreground" />
<Text>Paste</Text>
</Button>
</View>
</>
)}
{!isScanning && !keyboardOpen && permissionStatus === PermissionStatus.DENIED &&
<View className="flex-1 h-full flex flex-col items-center justify-center gap-2 p-6">
<CameraIcon className="text-foreground" size={72} />
<Text className="text-2xl text-foreground text-center">Camera Permissions Denied</Text>
<Text className="text-muted-foreground text-xl text-center">It seems you denied permissions to use your camera. You might need to go to your device settings to allow access to your camera again.</Text>
</View>
}
{keyboardOpen && (
<TouchableWithoutFeedback
onPress={() => {
Expand All @@ -188,7 +177,7 @@ export function Send() {
onChangeText={setKeyboardText}
inputMode="email"
autoFocus
// aria-errormessage="inputError"
// aria-errormessage="inputError"
/>
</View>
<Button onPress={submitKeyboardText} size="lg">
Expand All @@ -197,17 +186,36 @@ export function Send() {
</View>
</TouchableWithoutFeedback>
)}
{!isScanning && !keyboardOpen && (
<>
<View className="flex-1 h-full flex flex-col items-center justify-center gap-5">
<CameraIcon className="text-black w-32 h-32" />
<Text className="text-2xl">Camera Permissions Needed</Text>
<Button onPress={scan}>
<Text className="text-background">Grant Permissions</Text>
</Button>
</View>
</>
)}
{!keyboardOpen &&
<View className="flex flex-row items-stretch justify-center gap-4 p-6">
<Button
onPress={openKeyboard}
variant="secondary"
className="flex flex-col gap-2 flex-1"
>
<KeyboardIcon className="text-secondary-foreground" />
<Text>Manual</Text>
</Button>
<Button
variant="secondary"
className="flex flex-col gap-2"
onPress={() => {
router.push("/send/address-book");
}}
>
<BookUser className="text-secondary-foreground" />
<Text>Contacts</Text>
</Button>
<Button
onPress={paste}
variant="secondary"
className="flex flex-col gap-2 flex-1"
>
<ClipboardPaste className="text-secondary-foreground" />
<Text>Paste</Text>
</Button>
</View>
}
</>
)}
</>
Expand Down

0 comments on commit 379f20f

Please sign in to comment.