Skip to content

Commit 85f20cb

Browse files
committedNov 27, 2023
finised adding Ciontek printer support
1 parent aa74fc2 commit 85f20cb

File tree

8 files changed

+157
-84
lines changed

8 files changed

+157
-84
lines changed
 

‎android/app/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ android {
101101
/*
102102
* https://www.epochconverter.com/
103103
*/
104-
versionCode 1701031135
105-
versionName "1.3.3"
104+
versionCode 1701051529
105+
versionName "1.4.0"
106106

107107
missingDimensionStrategy 'react-native-camera', 'general'
108108

‎android/app/src/main/java/org/boltcard/boltcardpos/MainActivity.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,14 @@ public void printQRCode(String text, int width, int height) {
139139
public void printQRCodeCiontek(String text, int width, int height) {
140140
try {
141141
int result = posApiHelper.PrintInit();
142-
result = posApiHelper.PrintQrCode_Cut(text, width, height, "QR_CODE");
142+
result = posApiHelper.PrintBarcode(text, width, height, "QR_CODE");
143143
result = posApiHelper.PrintStart();
144144
} catch (Exception e) {
145145
e.printStackTrace();
146146
// callBack.invoke("Error: "+e.getMessage());
147147
}
148148
}
149149

150-
151150
public void testPrint(Callback callBack) {
152151
Log.d(TAG, "Test Print!");
153152
try {

‎android/app/src/main/java/org/boltcard/boltcardpos/PrintModule.java

+19-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void paperOut(int pixels) {
4343
MainActivity activity = (MainActivity) getCurrentActivity();
4444
if(activity != null) activity.paperOut(pixels);
4545
}
46-
46+
4747
@ReactMethod
4848
public void testPrint(
4949
Callback callBack
@@ -52,6 +52,24 @@ public void testPrint(
5252
if(activity != null) activity.testPrint(callBack);
5353
}
5454

55+
@ReactMethod
56+
public void printTextCiontek(String text, int size) {
57+
MainActivity activity = (MainActivity) getCurrentActivity();
58+
if(activity != null) activity.printTextCiontek(text, size);
59+
}
60+
61+
@ReactMethod
62+
public void printQRCodeCiontek(String text, int width, int height) {
63+
MainActivity activity = (MainActivity) getCurrentActivity();
64+
if(activity != null) activity.printQRCodeCiontek(text, width, height);
65+
}
66+
67+
@ReactMethod
68+
public void paperOutCiontek() {
69+
MainActivity activity = (MainActivity) getCurrentActivity();
70+
if(activity != null) activity.paperOutCiontek();
71+
}
72+
5573
@ReactMethod
5674
public void testPrintCiontek() {
5775
MainActivity activity = (MainActivity) getCurrentActivity();

‎contexts/ShopSettingsContext.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ const ShopSettingsProvider = ({children}) => {
7878
}
7979
}
8080
saveShopSettings();
81-
}, [shopName, lndhub, lndhubUser]);
81+
}, [shopName, lndhub, lndhubUser, printer]);
8282

8383
useEffect(() => {
8484
async function initWallet() {

‎helper/printing.js

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import {NativeModules, Alert} from 'react-native';
2+
import moment from 'moment';
3+
4+
export const printBitcoinize = async (
5+
description,
6+
timestamp,
7+
ispaid,
8+
payment_hash,
9+
amt,
10+
) => {
11+
try {
12+
await NativeModules.PrintModule.printText(description, 32);
13+
await NativeModules.PrintModule.paperOut(24);
14+
15+
await NativeModules.PrintModule.printText('Payment made in Bitcoin', 24);
16+
await NativeModules.PrintModule.paperOut(24);
17+
18+
await NativeModules.PrintModule.printText(
19+
moment(timestamp * 1000).format('DD/MM/YY HH:mm:ss'),
20+
24,
21+
);
22+
await NativeModules.PrintModule.paperOut(24);
23+
24+
await NativeModules.PrintModule.printText(
25+
amt + ' sats ' + (ispaid ? '(PAID)' : '(PENDING)'),
26+
32,
27+
);
28+
await NativeModules.PrintModule.paperOut(24);
29+
30+
await NativeModules.PrintModule.printText(payment_hash, 24);
31+
await NativeModules.PrintModule.paperOut(24);
32+
await NativeModules.PrintModule.printQRCode(
33+
JSON.stringify({payment_hash: payment_hash}),
34+
400,
35+
400,
36+
);
37+
38+
await NativeModules.PrintModule.paperOut(100);
39+
} catch (e) {
40+
Alert.alert('Error', 'There was an error when printing ' + e.message, [
41+
{text: 'OK', onPress: () => console.log('OK Pressed')},
42+
]);
43+
}
44+
};
45+
46+
export const printCiontek = async (
47+
description,
48+
timestamp,
49+
ispaid,
50+
payment_hash,
51+
amt,
52+
) => {
53+
try {
54+
await NativeModules.PrintModule.printTextCiontek(description, 32);
55+
await NativeModules.PrintModule.paperOutCiontek();
56+
57+
await NativeModules.PrintModule.printTextCiontek(
58+
'Payment made in Bitcoin',
59+
24,
60+
);
61+
await NativeModules.PrintModule.paperOutCiontek();
62+
63+
await NativeModules.PrintModule.printTextCiontek(
64+
moment(timestamp * 1000).format('DD/MM/YY HH:mm:ss'),
65+
24,
66+
);
67+
await NativeModules.PrintModule.paperOutCiontek();
68+
69+
await NativeModules.PrintModule.printTextCiontek(
70+
amt + ' sats ' + (ispaid ? '(PAID)' : '(PENDING)'),
71+
32,
72+
);
73+
await NativeModules.PrintModule.paperOutCiontek();
74+
75+
await NativeModules.PrintModule.printTextCiontek(payment_hash, 24);
76+
await NativeModules.PrintModule.paperOutCiontek();
77+
await NativeModules.PrintModule.printQRCodeCiontek(
78+
JSON.stringify({payment_hash: payment_hash}),
79+
360,
80+
360,
81+
);
82+
83+
await NativeModules.PrintModule.paperOutCiontek();
84+
await NativeModules.PrintModule.paperOutCiontek();
85+
await NativeModules.PrintModule.paperOutCiontek();
86+
} catch (e) {
87+
Alert.alert('Error', 'There was an error when printing ' + e.message, [
88+
{text: 'OK', onPress: () => console.log('OK Pressed')},
89+
]);
90+
}
91+
};

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "boltcardpos",
3-
"version": "1.2.2",
3+
"version": "1.4.0",
44
"private": true,
55
"scripts": {
66
"android": "react-native run-android",

‎screens/Home.tsx

+19-31
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import LottieView from 'lottie-react-native';
4040
import RNHTMLtoPDF from 'react-native-html-to-pdf';
4141
import FileViewer from 'react-native-file-viewer';
4242
import moment from 'moment';
43+
import {printCiontek, printBitcoinize} from '../helper/printing';
4344

4445
const currency = require('../helper/currency');
4546

@@ -87,7 +88,8 @@ function Home({navigation}): React.FC<Props> {
8788
const [lndWallet, setLndWallet] = useState<LightningCustodianWallet>();
8889

8990
//shop settings
90-
const {shopName, lndhub, lndhubUser} = useContext(ShopSettingsContext);
91+
const {shopName, lndhub, lndhubUser, printer} =
92+
useContext(ShopSettingsContext);
9193

9294
//PIN
9395
const [showPinModal, setShowPinModal] = useState(false);
@@ -675,38 +677,24 @@ function Home({navigation}): React.FC<Props> {
675677
};
676678

677679
const onPrint = async invoice => {
678-
try {
679-
await NativeModules.PrintModule.printText(invoice.description, 32);
680-
await NativeModules.PrintModule.paperOut(24);
681-
682-
await NativeModules.PrintModule.printText('Payment made in Bitcoin', 24);
683-
await NativeModules.PrintModule.paperOut(24);
684-
685-
await NativeModules.PrintModule.printText(
686-
moment(invoice.timestamp * 1000).format('DD/MM/YY HH:mm:ss'),
687-
24,
688-
);
689-
await NativeModules.PrintModule.paperOut(24);
690-
691-
await NativeModules.PrintModule.printText(
692-
invoice.amt + ' sats ' + (invoice.ispaid ? '(PAID)' : '(PENDING)'),
693-
32,
680+
if (printer == 'ciontek') {
681+
console.log('printCiontek');
682+
printCiontek(
683+
invoice.description,
684+
invoice.timestamp,
685+
invoice.ispaid,
686+
invoice.payment_hash,
687+
invoice.amt,
694688
);
695-
await NativeModules.PrintModule.paperOut(24);
696-
697-
await NativeModules.PrintModule.printText(invoice.payment_hash, 24);
698-
await NativeModules.PrintModule.paperOut(24);
699-
await NativeModules.PrintModule.printQRCode(
700-
JSON.stringify({payment_hash: invoice.payment_hash}),
701-
400,
702-
400,
689+
} else {
690+
console.log('printBitcoinize');
691+
printBitcoinize(
692+
invoice.description,
693+
invoice.timestamp,
694+
invoice.ispaid,
695+
invoice.payment_hash,
696+
invoice.amt,
703697
);
704-
705-
await NativeModules.PrintModule.paperOut(100);
706-
} catch (e) {
707-
Alert.alert('Error', 'There was an error when printing ' + e.message, [
708-
{text: 'OK', onPress: () => console.log('OK Pressed')},
709-
]);
710698
}
711699
};
712700

‎screens/recentInvoices/InvoiceDetail.tsx

+23-46
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ import RNHTMLtoPDF from 'react-native-html-to-pdf';
1414
import FileViewer from 'react-native-file-viewer';
1515
import QRCode from 'react-native-qrcode-svg';
1616
import Toast from 'react-native-toast-message';
17-
17+
import {printCiontek, printBitcoinize} from '../../helper/printing';
18+
import {ShopSettingsContext} from '../../contexts/ShopSettingsContext';
1819
import moment from 'moment';
1920

2021
const InvoiceDetail = ({route}) => {
2122
const {navigate} = useNavigation();
23+
const {shopName, lndhub, lndhubUser, printer} =
24+
useContext(ShopSettingsContext);
2225

2326
const isDarkMode = useColorScheme() === 'dark';
2427
const backgroundStyle = {
@@ -77,51 +80,25 @@ const InvoiceDetail = ({route}) => {
7780
};
7881

7982
const print = async () => {
80-
Alert.alert('Print Receipt', 'Are you sure?', [
81-
{
82-
text: 'Cancel',
83-
onPress: () => console.log('Cancel Pressed'),
84-
style: 'cancel',
85-
},
86-
{
87-
text: 'OK',
88-
onPress: async () => {
89-
await NativeModules.PrintModule.printText(invoice.description, 32);
90-
await NativeModules.PrintModule.paperOut(24);
91-
92-
await NativeModules.PrintModule.printText(
93-
'Payment made in Bitcoin',
94-
24,
95-
);
96-
await NativeModules.PrintModule.paperOut(24);
97-
98-
await NativeModules.PrintModule.printText(
99-
formatDate(invoice.timestamp),
100-
24,
101-
);
102-
await NativeModules.PrintModule.paperOut(24);
103-
104-
await NativeModules.PrintModule.printText(
105-
invoice.amt + ' sats ' + (invoice.ispaid ? '(PAID)' : '(PENDING)'),
106-
32,
107-
);
108-
await NativeModules.PrintModule.paperOut(24);
109-
110-
await NativeModules.PrintModule.printText(invoice.payment_hash, 24);
111-
await NativeModules.PrintModule.paperOut(24);
112-
await NativeModules.PrintModule.printQRCode(
113-
JSON.stringify({payment_hash: invoice.payment_hash}),
114-
400,
115-
400,
116-
result => {
117-
console.log(result);
118-
},
119-
);
120-
121-
await NativeModules.PrintModule.paperOut(100);
122-
},
123-
},
124-
]);
83+
if (printer == 'ciontek') {
84+
console.log('printCiontek');
85+
printCiontek(
86+
invoice.description,
87+
invoice.timestamp,
88+
invoice.ispaid,
89+
invoice.payment_hash,
90+
invoice.amt,
91+
);
92+
} else {
93+
console.log('printBitcoinize');
94+
printBitcoinize(
95+
invoice.description,
96+
invoice.timestamp,
97+
invoice.ispaid,
98+
invoice.payment_hash,
99+
invoice.amt,
100+
);
101+
}
125102
};
126103

127104
return (

0 commit comments

Comments
 (0)