diff --git a/android/app/build.gradle b/android/app/build.gradle index 195db1b..ea80cee 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -101,8 +101,8 @@ android { /* * https://www.epochconverter.com/ */ - versionCode 1701031135 - versionName "1.3.3" + versionCode 1701051529 + versionName "1.4.0" missingDimensionStrategy 'react-native-camera', 'general' diff --git a/android/app/src/main/java/org/boltcard/boltcardpos/MainActivity.java b/android/app/src/main/java/org/boltcard/boltcardpos/MainActivity.java index de7b7a2..fb62a90 100644 --- a/android/app/src/main/java/org/boltcard/boltcardpos/MainActivity.java +++ b/android/app/src/main/java/org/boltcard/boltcardpos/MainActivity.java @@ -139,7 +139,7 @@ public void printQRCode(String text, int width, int height) { public void printQRCodeCiontek(String text, int width, int height) { try { int result = posApiHelper.PrintInit(); - result = posApiHelper.PrintQrCode_Cut(text, width, height, "QR_CODE"); + result = posApiHelper.PrintBarcode(text, width, height, "QR_CODE"); result = posApiHelper.PrintStart(); } catch (Exception e) { e.printStackTrace(); @@ -147,7 +147,6 @@ public void printQRCodeCiontek(String text, int width, int height) { } } - public void testPrint(Callback callBack) { Log.d(TAG, "Test Print!"); try { diff --git a/android/app/src/main/java/org/boltcard/boltcardpos/PrintModule.java b/android/app/src/main/java/org/boltcard/boltcardpos/PrintModule.java index 3b83c3b..8e4c858 100644 --- a/android/app/src/main/java/org/boltcard/boltcardpos/PrintModule.java +++ b/android/app/src/main/java/org/boltcard/boltcardpos/PrintModule.java @@ -43,7 +43,7 @@ public void paperOut(int pixels) { MainActivity activity = (MainActivity) getCurrentActivity(); if(activity != null) activity.paperOut(pixels); } - + @ReactMethod public void testPrint( Callback callBack @@ -52,6 +52,24 @@ public void testPrint( if(activity != null) activity.testPrint(callBack); } + @ReactMethod + public void printTextCiontek(String text, int size) { + MainActivity activity = (MainActivity) getCurrentActivity(); + if(activity != null) activity.printTextCiontek(text, size); + } + + @ReactMethod + public void printQRCodeCiontek(String text, int width, int height) { + MainActivity activity = (MainActivity) getCurrentActivity(); + if(activity != null) activity.printQRCodeCiontek(text, width, height); + } + + @ReactMethod + public void paperOutCiontek() { + MainActivity activity = (MainActivity) getCurrentActivity(); + if(activity != null) activity.paperOutCiontek(); + } + @ReactMethod public void testPrintCiontek() { MainActivity activity = (MainActivity) getCurrentActivity(); diff --git a/contexts/ShopSettingsContext.js b/contexts/ShopSettingsContext.js index 0369a2c..e85eb8b 100644 --- a/contexts/ShopSettingsContext.js +++ b/contexts/ShopSettingsContext.js @@ -78,7 +78,7 @@ const ShopSettingsProvider = ({children}) => { } } saveShopSettings(); - }, [shopName, lndhub, lndhubUser]); + }, [shopName, lndhub, lndhubUser, printer]); useEffect(() => { async function initWallet() { diff --git a/helper/printing.js b/helper/printing.js new file mode 100644 index 0000000..cf62b5b --- /dev/null +++ b/helper/printing.js @@ -0,0 +1,91 @@ +import {NativeModules, Alert} from 'react-native'; +import moment from 'moment'; + +export const printBitcoinize = async ( + description, + timestamp, + ispaid, + payment_hash, + amt, +) => { + try { + await NativeModules.PrintModule.printText(description, 32); + await NativeModules.PrintModule.paperOut(24); + + await NativeModules.PrintModule.printText('Payment made in Bitcoin', 24); + await NativeModules.PrintModule.paperOut(24); + + await NativeModules.PrintModule.printText( + moment(timestamp * 1000).format('DD/MM/YY HH:mm:ss'), + 24, + ); + await NativeModules.PrintModule.paperOut(24); + + await NativeModules.PrintModule.printText( + amt + ' sats ' + (ispaid ? '(PAID)' : '(PENDING)'), + 32, + ); + await NativeModules.PrintModule.paperOut(24); + + await NativeModules.PrintModule.printText(payment_hash, 24); + await NativeModules.PrintModule.paperOut(24); + await NativeModules.PrintModule.printQRCode( + JSON.stringify({payment_hash: payment_hash}), + 400, + 400, + ); + + await NativeModules.PrintModule.paperOut(100); + } catch (e) { + Alert.alert('Error', 'There was an error when printing ' + e.message, [ + {text: 'OK', onPress: () => console.log('OK Pressed')}, + ]); + } +}; + +export const printCiontek = async ( + description, + timestamp, + ispaid, + payment_hash, + amt, +) => { + try { + await NativeModules.PrintModule.printTextCiontek(description, 32); + await NativeModules.PrintModule.paperOutCiontek(); + + await NativeModules.PrintModule.printTextCiontek( + 'Payment made in Bitcoin', + 24, + ); + await NativeModules.PrintModule.paperOutCiontek(); + + await NativeModules.PrintModule.printTextCiontek( + moment(timestamp * 1000).format('DD/MM/YY HH:mm:ss'), + 24, + ); + await NativeModules.PrintModule.paperOutCiontek(); + + await NativeModules.PrintModule.printTextCiontek( + amt + ' sats ' + (ispaid ? '(PAID)' : '(PENDING)'), + 32, + ); + await NativeModules.PrintModule.paperOutCiontek(); + + await NativeModules.PrintModule.printTextCiontek(payment_hash, 24); + await NativeModules.PrintModule.paperOutCiontek(); + await NativeModules.PrintModule.printQRCodeCiontek( + JSON.stringify({payment_hash: payment_hash}), + 360, + 360, + ); + + await NativeModules.PrintModule.paperOutCiontek(); + await NativeModules.PrintModule.paperOutCiontek(); + await NativeModules.PrintModule.paperOutCiontek(); + } catch (e) { + Alert.alert('Error', 'There was an error when printing ' + e.message, [ + {text: 'OK', onPress: () => console.log('OK Pressed')}, + ]); + } +}; diff --git a/package.json b/package.json index 6a2d65b..a643688 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "boltcardpos", - "version": "1.2.2", + "version": "1.4.0", "private": true, "scripts": { "android": "react-native run-android", diff --git a/screens/Home.tsx b/screens/Home.tsx index 914ec17..ce801fc 100644 --- a/screens/Home.tsx +++ b/screens/Home.tsx @@ -40,6 +40,7 @@ import LottieView from 'lottie-react-native'; import RNHTMLtoPDF from 'react-native-html-to-pdf'; import FileViewer from 'react-native-file-viewer'; import moment from 'moment'; +import {printCiontek, printBitcoinize} from '../helper/printing'; const currency = require('../helper/currency'); @@ -87,7 +88,8 @@ function Home({navigation}): React.FC { const [lndWallet, setLndWallet] = useState(); //shop settings - const {shopName, lndhub, lndhubUser} = useContext(ShopSettingsContext); + const {shopName, lndhub, lndhubUser, printer} = + useContext(ShopSettingsContext); //PIN const [showPinModal, setShowPinModal] = useState(false); @@ -675,38 +677,24 @@ function Home({navigation}): React.FC { }; const onPrint = async invoice => { - try { - await NativeModules.PrintModule.printText(invoice.description, 32); - await NativeModules.PrintModule.paperOut(24); - - await NativeModules.PrintModule.printText('Payment made in Bitcoin', 24); - await NativeModules.PrintModule.paperOut(24); - - await NativeModules.PrintModule.printText( - moment(invoice.timestamp * 1000).format('DD/MM/YY HH:mm:ss'), - 24, - ); - await NativeModules.PrintModule.paperOut(24); - - await NativeModules.PrintModule.printText( - invoice.amt + ' sats ' + (invoice.ispaid ? '(PAID)' : '(PENDING)'), - 32, + if (printer == 'ciontek') { + console.log('printCiontek'); + printCiontek( + invoice.description, + invoice.timestamp, + invoice.ispaid, + invoice.payment_hash, + invoice.amt, ); - await NativeModules.PrintModule.paperOut(24); - - await NativeModules.PrintModule.printText(invoice.payment_hash, 24); - await NativeModules.PrintModule.paperOut(24); - await NativeModules.PrintModule.printQRCode( - JSON.stringify({payment_hash: invoice.payment_hash}), - 400, - 400, + } else { + console.log('printBitcoinize'); + printBitcoinize( + invoice.description, + invoice.timestamp, + invoice.ispaid, + invoice.payment_hash, + invoice.amt, ); - - await NativeModules.PrintModule.paperOut(100); - } catch (e) { - Alert.alert('Error', 'There was an error when printing ' + e.message, [ - {text: 'OK', onPress: () => console.log('OK Pressed')}, - ]); } }; diff --git a/screens/recentInvoices/InvoiceDetail.tsx b/screens/recentInvoices/InvoiceDetail.tsx index 8a27650..a086f91 100644 --- a/screens/recentInvoices/InvoiceDetail.tsx +++ b/screens/recentInvoices/InvoiceDetail.tsx @@ -14,11 +14,14 @@ import RNHTMLtoPDF from 'react-native-html-to-pdf'; import FileViewer from 'react-native-file-viewer'; import QRCode from 'react-native-qrcode-svg'; import Toast from 'react-native-toast-message'; - +import {printCiontek, printBitcoinize} from '../../helper/printing'; +import {ShopSettingsContext} from '../../contexts/ShopSettingsContext'; import moment from 'moment'; const InvoiceDetail = ({route}) => { const {navigate} = useNavigation(); + const {shopName, lndhub, lndhubUser, printer} = + useContext(ShopSettingsContext); const isDarkMode = useColorScheme() === 'dark'; const backgroundStyle = { @@ -77,51 +80,25 @@ const InvoiceDetail = ({route}) => { }; const print = async () => { - Alert.alert('Print Receipt', 'Are you sure?', [ - { - text: 'Cancel', - onPress: () => console.log('Cancel Pressed'), - style: 'cancel', - }, - { - text: 'OK', - onPress: async () => { - await NativeModules.PrintModule.printText(invoice.description, 32); - await NativeModules.PrintModule.paperOut(24); - - await NativeModules.PrintModule.printText( - 'Payment made in Bitcoin', - 24, - ); - await NativeModules.PrintModule.paperOut(24); - - await NativeModules.PrintModule.printText( - formatDate(invoice.timestamp), - 24, - ); - await NativeModules.PrintModule.paperOut(24); - - await NativeModules.PrintModule.printText( - invoice.amt + ' sats ' + (invoice.ispaid ? '(PAID)' : '(PENDING)'), - 32, - ); - await NativeModules.PrintModule.paperOut(24); - - await NativeModules.PrintModule.printText(invoice.payment_hash, 24); - await NativeModules.PrintModule.paperOut(24); - await NativeModules.PrintModule.printQRCode( - JSON.stringify({payment_hash: invoice.payment_hash}), - 400, - 400, - result => { - console.log(result); - }, - ); - - await NativeModules.PrintModule.paperOut(100); - }, - }, - ]); + if (printer == 'ciontek') { + console.log('printCiontek'); + printCiontek( + invoice.description, + invoice.timestamp, + invoice.ispaid, + invoice.payment_hash, + invoice.amt, + ); + } else { + console.log('printBitcoinize'); + printBitcoinize( + invoice.description, + invoice.timestamp, + invoice.ispaid, + invoice.payment_hash, + invoice.amt, + ); + } }; return (