Skip to content

Commit

Permalink
fix: improve linking
Browse files Browse the repository at this point in the history
  • Loading branch information
reneaaron committed Sep 17, 2024
1 parent 45138f9 commit cb5c099
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 23 deletions.
2 changes: 1 addition & 1 deletion components/DualCurrencyInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,6 @@ export function DualCurrencyInput({
const styles = StyleSheet.create({
amountInput: {
fontSize: 80,
height: 90,
height: 100,
},
});
1 change: 0 additions & 1 deletion components/FocusableCamera.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export function FocusableCamera({ onScanned }: FocusableCameraProps) {
const handleBarCodeScanned = ({ data }: BarcodeScanningResult) => {
onScanned(data);
};

return (
<CameraView
onBarcodeScanned={handleBarCodeScanned}
Expand Down
27 changes: 14 additions & 13 deletions components/QRCodeScanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,27 @@ import { Camera } from "expo-camera";
import { Text } from "~/components/ui/text";
import { CameraOff } from "./Icons";

type QRCodeScannerProps = {
interface QRCodeScannerProps {
onScanned: (data: string) => void;
};
startScanning: boolean;
}

function QRCodeScanner({ onScanned }: QRCodeScannerProps) {
const [isScanning, setScanning] = React.useState(false);
function QRCodeScanner({ onScanned, startScanning = true }: QRCodeScannerProps) {
const [isScanning, setScanning] = React.useState(startScanning);
const [isLoading, setLoading] = React.useState(false);
const [permissionStatus, setPermissionStatus] = React.useState(PermissionStatus.UNDETERMINED);

useEffect(() => {
// Add some timeout to allow the screen transition to finish before
// starting the camera to avoid stutters
setLoading(true);
window.setTimeout(async () => {
await scan();
setLoading(false);
}, 200);
}, []);
if (startScanning) {
setLoading(true);
window.setTimeout(async () => {
await scan();
setLoading(false);
}, 200);
}
}, [startScanning]);

async function scan() {
const { status } = await Camera.requestCameraPermissionsAsync();
Expand Down Expand Up @@ -59,9 +62,7 @@ function QRCodeScanner({ onScanned }: QRCodeScannerProps) {
</View>
}
{isScanning && (
<>
<FocusableCamera onScanned={handleScanned} />
</>
<FocusableCamera onScanned={handleScanned} />
)}
</>
}
Expand Down
27 changes: 23 additions & 4 deletions pages/send/Send.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,22 @@ export function Send() {
const [isLoading, setLoading] = React.useState(false);
const [keyboardOpen, setKeyboardOpen] = React.useState(false);
const [keyboardText, setKeyboardText] = React.useState("");
const [startScanning, setStartScanning] = React.useState(false);

// Delay starting the QR scanner if url has no valid payment info
useEffect(() => {
if (url) {
loadPayment(url);
(async () => {
try {
const result = await loadPayment(url);
setStartScanning(!result);
} catch (error) {
console.error("failed to load payment", url, error);
errorToast(error);
}
})();
} else {
setStartScanning(true);
}
}, [url]);

Expand Down Expand Up @@ -55,10 +67,10 @@ export function Send() {

// TODO: Add a property for the human readable version of the url
// and use it across different send / receive screens (e.g. without "lightning:")
async function loadPayment(text: string) {
async function loadPayment(text: string): Promise<boolean> {
if (!text) {
errorToast(new Error("Your clipboard is empty."));
return;
return false;
}
console.log("loading payment", text);
const originalText = text;
Expand Down Expand Up @@ -92,6 +104,8 @@ export function Send() {
originalText,
},
});

return true;
} else {
// Check if this is a valid invoice
new Invoice({
Expand All @@ -102,12 +116,17 @@ export function Send() {
pathname: "/send/confirm",
params: { invoice: text, originalText },
});

return true;
}
} catch (error) {
console.error("failed to load payment", originalText, error);
errorToast(error);
} finally {
setLoading(false);
}

return false;
}

return (
Expand All @@ -122,7 +141,7 @@ export function Send() {
<>
{!keyboardOpen && (
<>
<QRCodeScanner onScanned={handleScanned} />
<QRCodeScanner onScanned={handleScanned} startScanning={startScanning} />
<View className="flex flex-row items-stretch justify-center gap-4 p-6">
<Button
onPress={openKeyboard}
Expand Down
4 changes: 0 additions & 4 deletions pages/settings/wallets/WalletConnection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ export function WalletConnection() {
return connect(data);
};

React.useEffect(() => {
scan();
}, []);

async function paste() {
let nostrWalletConnectUrl;
try {
Expand Down

0 comments on commit cb5c099

Please sign in to comment.