Skip to content

Commit 7edf48e

Browse files
Merge pull request #6 from NNdok/main
Add Alert in Scanner
2 parents 0ced421 + 6b072d0 commit 7edf48e

3 files changed

Lines changed: 36 additions & 13 deletions

File tree

app/index.tsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { router } from "expo-router";
77
import * as SecureStore from "expo-secure-store";
88
import { useEffect, useState } from "react";
99
import {
10+
Alert,
1011
Modal,
1112
Pressable,
1213
StyleSheet,
@@ -52,7 +53,7 @@ export default function Index() {
5253

5354
// Validate if the pasted text looks like a valid NWC URL
5455
if (!text || !text.startsWith("nostr+walletconnect://")) {
55-
console.error("Invalid NWC URL format");
56+
Alert.alert("Invalid NWC URL format", "Please start with nostr+walletconnect://");
5657
// You might want to show an error message to the user here
5758
return;
5859
}
@@ -180,16 +181,16 @@ export default function Index() {
180181

181182
<HeaderIcon />
182183

183-
{/* NOTE: Test when store nwc already */}
184-
{/* <View style={{ justifyContent: "center", alignItems: "center" }}> */}
185-
{/* <Pressable */}
186-
{/* onPress={async () => { */}
187-
{/* await SecureStore.deleteItemAsync("nwcUrl"); */}
188-
{/* }} */}
189-
{/* > */}
190-
{/* <Text> Test delete nwcUrl</Text> */}
191-
{/* </Pressable> */}
192-
{/* </View> */}
184+
{/* NOTE: Test when store nwc already */}
185+
{/* <View style={{ justifyContent: "center", alignItems: "center" }}>
186+
<Pressable
187+
onPress={async () => {
188+
await SecureStore.deleteItemAsync("nwcUrl"); }
189+
}
190+
>
191+
<Text> Test delete nwcUrl</Text>
192+
</Pressable>
193+
</View> */}
193194

194195
{/* NOTE: Test go to screen cremara */}
195196
{/* <View style={{ justifyContent: "center", alignItems: "center" }}> */}

app/scanner/index.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { CameraView, useCameraPermissions } from "expo-camera";
33
import { Stack, router } from "expo-router";
44
import * as SecureStore from "expo-secure-store";
55
import React, { useEffect, useRef } from "react";
6-
import { AppState, Button, Linking, Platform, StatusBar, Text } from "react-native";
6+
import { Alert, AppState, Button, Linking, Platform, StatusBar, Text } from "react-native";
77
import { SafeAreaView } from "react-native-safe-area-context";
88

99
export default function Scanner() {
@@ -59,17 +59,38 @@ export default function Scanner() {
5959
style={{ flex: 1 }}
6060
facing="back"
6161
onBarcodeScanned={({ data }) => {
62+
if (!data || qrLock.current) return;
63+
6264
if (
6365
data &&
6466
!qrLock.current &&
6567
data.startsWith("nostr+walletconnect://")
6668
) {
69+
6770
qrLock.current = true;
6871
setTimeout(async () => {
6972
setNwcUrl(data);
7073
await SecureStore.setItemAsync("nwcUrl", data);
7174
router.replace("/");
7275
}, 500);
76+
}else{
77+
// Handle Invalid URL
78+
qrLock.current = true;
79+
Alert.alert(
80+
"Invalid QR Code",
81+
"The scanned code is not a valid NWC format.",
82+
[
83+
{
84+
text: "OK",
85+
onPress: () => {
86+
// Unlock scanning only after user acknowledges the alert
87+
setTimeout(() => {
88+
qrLock.current = false;
89+
}, 1000);
90+
},
91+
},
92+
]
93+
);
7394
}
7495
}}
7596
barcodeScannerSettings={{ barcodeTypes: ["qr"] }}

components/index/HeaderIcon.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { router } from "expo-router";
88
import * as SecureStore from "expo-secure-store";
99
import { useState } from "react";
1010
import {
11+
Alert,
1112
Modal,
1213
Platform,
1314
Pressable,
@@ -43,7 +44,7 @@ export default function HeaderIcon() {
4344

4445
// Validate if the pasted text looks like a valid NWC URL
4546
if (!text || !text.startsWith("nostr+walletconnect://")) {
46-
console.error("Invalid NWC URL format");
47+
Alert.alert("Invalid NWC URL format","Please start with nostr+walletconnect://")
4748
// You might want to show an error message to the user here
4849
return;
4950
}

0 commit comments

Comments
 (0)