Skip to content

Commit ad3e41f

Browse files
chore: printer handling improvements + readme changes
1 parent 2acc6c4 commit ad3e41f

File tree

5 files changed

+73
-12
lines changed

5 files changed

+73
-12
lines changed

dapps/pos-app/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,36 @@ android/
6262
└── wc_rn_upload.keystore ← Place here
6363
```
6464

65+
**Build the release APK:**
66+
67+
```bash
68+
npm run android:build
69+
```
70+
71+
The release APK will be generated at `android/app/build/outputs/apk/release/app-release.apk`
72+
73+
**Install on a device via USB:**
74+
75+
> **Note**: Make sure USB debugging is enabled on your Android device. Go to Settings → About phone → Tap "Build number" 7 times → Developer options → Enable "USB debugging".
76+
77+
1. Connect your device via USB and get its device ID:
78+
79+
```bash
80+
adb devices
81+
```
82+
83+
Example output: `V510BAC07114B000171`
84+
85+
2. Build the release APK:
86+
87+
```bash
88+
npm run android:build
89+
```
90+
91+
3. Install the APK on your device (replace with your device ID):
92+
93+
```bash
94+
adb -s V510BAC07114B000171 install android/app/build/outputs/apk/release/app-release.apk
95+
```
96+
6597
> **⚠️ Security Note**: Never commit `secrets.properties` or keystore files to version control.

dapps/pos-app/app/payment-success.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,11 @@ export default function PaymentSuccessScreen() {
5050

5151
const setPrinter = async () => {
5252
try {
53-
const isConnected = await connectPrinter();
54-
setIsPrinterConnected(isConnected);
53+
const { connected, error } = await connectPrinter();
54+
setIsPrinterConnected(connected);
55+
if (!connected && error) {
56+
console.error("Printer connection failed:", error);
57+
}
5558
} catch (error) {
5659
console.error("Connection failed:", error);
5760
setIsPrinterConnected(false);

dapps/pos-app/app/scan.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ export default function QRModalScreen() {
7878
refId: uuidv4(),
7979
amount: Number(amount) * 100, // amount in cents i.e. $1 = 100
8080
currency: "USD",
81-
chainId: 8453,
8281
};
8382

8483
const data = await startPayment(paymentRequest);

dapps/pos-app/app/settings.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ export default function Settings() {
2828
showErrorToast("Failed to request Bluetooth permission");
2929
return;
3030
}
31-
const isConnected = await connectPrinter();
32-
if (!isConnected) {
33-
showErrorToast("Failed to connect to printer");
31+
const { connected, error } = await connectPrinter();
32+
if (!connected) {
33+
showErrorToast(error || "Failed to connect to printer");
3434
return;
3535
}
3636
await printWalletConnectReceipt(

dapps/pos-app/utils/printer.ts

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,47 @@ export const requestBluetoothPermission = async () => {
1010
return result === RESULTS.GRANTED || result === RESULTS.LIMITED;
1111
};
1212

13-
export const connectPrinter = async () => {
13+
export const connectPrinter = async (): Promise<{
14+
connected: boolean;
15+
error?: string;
16+
}> => {
1417
try {
1518
// Scan for devices
1619
const devices = await ReactNativePosPrinter.getDeviceList();
17-
if (devices.length === 0) throw new Error("No printers found");
18-
19-
// Connect to first device (filter for your iMin, e.g., by name/vendor)
20+
if (devices.length === 0) {
21+
return {
22+
connected: false,
23+
error: "No printer detected on this device",
24+
};
25+
}
26+
27+
// Connect to first device
2028
const printer = devices[0].getDevice(); // { name, address, vendorId, productId, ... }
2129
await ReactNativePosPrinter.connectPrinter(printer.address); // e.g., 'USB' or mac address
2230
console.log("Connected to:", printer);
23-
return true;
31+
return { connected: true };
2432
} catch (error) {
2533
console.error("Connection failed:", error);
26-
return false;
34+
35+
// Check for Bluetooth permission error
36+
const errorMessage = error instanceof Error ? error.message : String(error);
37+
if (
38+
errorMessage.includes("BLUETOOTH_CONNECT") ||
39+
errorMessage.includes("bluetooth") ||
40+
errorMessage.includes("permission")
41+
) {
42+
return {
43+
connected: false,
44+
error:
45+
"Please enable Bluetooth on your device to connect to the printer",
46+
};
47+
}
48+
49+
// Generic error with details
50+
return {
51+
connected: false,
52+
error: `Failed to connect: ${errorMessage}`,
53+
};
2754
}
2855
};
2956

0 commit comments

Comments
 (0)