Skip to content

Commit

Permalink
added qrcode send or recieve functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
akintewe committed Oct 24, 2024
1 parent aecf73d commit 4b7ad7e
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions apps/mobile/src/modules/Cashu/qr/ScanCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,32 @@ const ScanCashuQRCode: React.FC<ScanCashuQRCodeProps> = ({onClose}) => {
const {showToast} = useToast();

const handleScannedCode = async ({data}: BarcodeScanningResult) => {
console.log('Scanned data:', data); // Debugging: Log the scanned data
if (!data) {
showToast({title: 'Invalid QR code', type: 'error'});
return;
}
setScanned(true);
setScannedData(data);

if (action === 'send' && data.startsWith('lightning:')) {
const invoice = data.replace('lightning:', '');
await handlePayInvoice(invoice);
onClose();
} else if (action === 'receive' && data.startsWith('cashu')) {
await handleGenerateEcash(Number(data.replace('cashu', '')));
onClose();
if (data.startsWith('lnbc')) {
// Lightning invoice
if (action === 'send') {
await handlePayInvoice(data);
showToast({title: 'Invoice paid successfully', type: 'success'});
} else {
showToast({title: 'This is a Lightning invoice. Please select "Pay".', type: 'info'});
}
} else {
showToast({title: 'Invalid QR code', type: 'error'});
// Assume eCash
if (action === 'receive') {
await handleGenerateEcash(Number(data.replace('cashu', '')));
showToast({title: 'eCash received successfully', type: 'success'});
} else {
showToast({title: 'This is an eCash token. Please select "Receive".', type: 'info'});
}
}
onClose();
};

const handleCopyToClipboard = () => {
Expand Down Expand Up @@ -90,7 +99,9 @@ const ScanCashuQRCode: React.FC<ScanCashuQRCodeProps> = ({onClose}) => {
</View>
{scannedData && (
<View style={styles.resultContainer}>
<Text style={styles.resultText}>{scannedData}</Text>
<Text style={styles.resultText}>
{action === 'send' ? 'Pay this invoice' : 'Receive this eCash'}
</Text>
<Button title="Copy to Clipboard" onPress={handleCopyToClipboard} />
</View>
)}
Expand Down Expand Up @@ -164,7 +175,7 @@ const styles = StyleSheet.create({
marginVertical: 20,
},
actionButton: {
backgroundColor: 'rgba(79, 168, 155, 1)', // Use your app's primary color
backgroundColor: 'rgba(79, 168, 155, 1)',
paddingVertical: 10,
paddingHorizontal: 20,
borderRadius: 5,
Expand Down

0 comments on commit 4b7ad7e

Please sign in to comment.