Skip to content

Commit 265af93

Browse files
feat: PoC UI changes + Request Bluetooth permission on app startup (#318)
* feat: request Bluetooth permission on app startup - Add Bluetooth permission request in _layout.tsx for both poc-pos-app and pos-app - Permission is requested on first app load (Android only) - Enables printer availability check as soon as app is installed * chore: add log in case user rejects bluetooth permissions
1 parent 13dd3f0 commit 265af93

File tree

10 files changed

+86
-8
lines changed

10 files changed

+86
-8
lines changed

dapps/poc-pos-app/app/_layout.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ import * as Sentry from "@sentry/react-native";
2424

2525
import { WalletConnectLoading } from "@/components/walletconnect-loading";
2626
import { Spacing } from "@/constants/spacing";
27+
import { useLogsStore } from "@/store/useLogsStore";
2728
import { useSettingsStore } from "@/store/useSettingsStore";
2829
import { getDeviceIdentifier } from "@/utils/misc";
30+
import { requestBluetoothPermission } from "@/utils/printer";
31+
import { showInfoToast } from "@/utils/toast";
2932
import { toastConfig } from "@/utils/toasts";
3033
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
3134
import React, { useEffect } from "react";
@@ -77,6 +80,37 @@ export default Sentry.wrap(function RootLayout() {
7780
// eslint-disable-next-line react-hooks/exhaustive-deps
7881
}, [deviceId]);
7982

83+
// Request Bluetooth permission on first app load (Android only)
84+
useEffect(() => {
85+
async function checkBluetoothPermission() {
86+
if (Platform.OS !== "android") return;
87+
88+
try {
89+
const granted = await requestBluetoothPermission();
90+
if (!granted) {
91+
useLogsStore
92+
.getState()
93+
.addLog(
94+
"error",
95+
"Bluetooth permission denied",
96+
"layout",
97+
"checkBluetoothPermission",
98+
);
99+
showInfoToast("Bluetooth permission is needed to connect to printer");
100+
}
101+
} catch (error) {
102+
const errorMessage =
103+
error instanceof Error ? error.message : String(error);
104+
useLogsStore
105+
.getState()
106+
.addLog("error", errorMessage, "layout", "checkBluetoothPermission", {
107+
error,
108+
});
109+
}
110+
}
111+
checkBluetoothPermission();
112+
}, []);
113+
80114
if (!_hasHydrated || !fontsLoaded) {
81115
return (
82116
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
-3.91 KB
Loading

dapps/poc-pos-app/components/header-image.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ interface HeaderImageProps {
1010

1111
export default function HeaderImage({ tintColor, padding }: HeaderImageProps) {
1212
const variant = useSettingsStore((state) => state.variant);
13-
const brandLogo = Variants[variant].brandLogo;
13+
const brandLogo = Variants[variant].brandLogo as string;
14+
1415
return (
1516
<Image
1617
source={brandLogo}
@@ -20,7 +21,7 @@ export default function HeaderImage({ tintColor, padding }: HeaderImageProps) {
2021
tintColor={tintColor}
2122
style={{
2223
height: 18,
23-
width: 185,
24+
width: Variants[variant].brandLogoWidth ?? 185,
2425
marginTop: Spacing["spacing-1"],
2526
tintColor: tintColor,
2627
marginRight: padding ? Spacing["spacing-2"] : 0,

dapps/poc-pos-app/constants/printer-logos.ts

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dapps/poc-pos-app/constants/theme.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const Colors = {
1717
"bg-primary": "#FFFFFF",
1818
"bg-invert": "#202020",
1919
"bg-accent-primary": "#0988F0",
20-
"bg-payment-success": "#30A46B",
20+
"bg-payment-success": "#0988F0",
2121

2222
// Text colors
2323
"text-primary": "#202020",
@@ -47,7 +47,7 @@ export const Colors = {
4747
"bg-primary": "#202020",
4848
"bg-invert": "#FFFFFF",
4949
"bg-accent-primary": "#0988F0",
50-
"bg-payment-success": "#30A46B",
50+
"bg-payment-success": "#0988F0",
5151

5252
// Text colors
5353
"text-primary": "#FFFFFF",

dapps/poc-pos-app/constants/variants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type VariantColorOverrides = Partial<typeof Colors.light>;
1919
interface Variant {
2020
name: string;
2121
brandLogo: ReturnType<typeof require>; // require() asset
22+
brandLogoWidth?: number;
2223
printerLogo: string; // base64 string
2324
defaultTheme?: "light" | "dark";
2425
colors: {
@@ -31,6 +32,7 @@ export const Variants: Record<VariantName, Variant> = {
3132
default: {
3233
name: "Default",
3334
brandLogo: require("@/assets/images/brand.png"),
35+
brandLogoWidth: 60,
3436
printerLogo: DEFAULT_LOGO_BASE64,
3537
colors: {
3638
light: {},

dapps/poc-pos-app/utils/printer.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,10 @@ export const printReceipt = async (
106106
const normal = { size: 10 } as TextOptions;
107107
const normalCenter = { size: 10, align: "CENTER" } as TextOptions;
108108
const bold = { size: 10, bold: true } as TextOptions;
109+
const idStyle = { size: 9, bold: true } as TextOptions;
109110

110111
await ReactNativePosPrinter.printText("ID ", normal);
111-
await ReactNativePosPrinter.printText(`${txnId}\n`, bold);
112+
await ReactNativePosPrinter.printText(`${txnId}\n`, idStyle);
112113

113114
await ReactNativePosPrinter.printText("DATE ", normal);
114115
await ReactNativePosPrinter.printText(`${date}\n`, bold);
@@ -134,7 +135,7 @@ export const printReceipt = async (
134135
await ReactNativePosPrinter.newLine(2);
135136

136137
await ReactNativePosPrinter.printText(
137-
"Thank you for your purchase!\n",
138+
"Thank you for your payment!\n",
138139
normalCenter,
139140
);
140141

dapps/pos-app/app/_layout.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ import * as Sentry from "@sentry/react-native";
2424

2525
import { WalletConnectLoading } from "@/components/walletconnect-loading";
2626
import { Spacing } from "@/constants/spacing";
27+
import { useLogsStore } from "@/store/useLogsStore";
2728
import { useSettingsStore } from "@/store/useSettingsStore";
2829
import { getDeviceIdentifier } from "@/utils/misc";
30+
import { requestBluetoothPermission } from "@/utils/printer";
2931
import { clearStaleSecureStorage } from "@/utils/secure-storage";
32+
import { showInfoToast } from "@/utils/toast";
3033
import { toastConfig } from "@/utils/toasts";
3134
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
3235
import React, { useEffect } from "react";
@@ -82,6 +85,37 @@ export default Sentry.wrap(function RootLayout() {
8285
// eslint-disable-next-line react-hooks/exhaustive-deps
8386
}, [deviceId]);
8487

88+
// Request Bluetooth permission on first app load (Android only)
89+
useEffect(() => {
90+
async function checkBluetoothPermission() {
91+
if (Platform.OS !== "android") return;
92+
93+
try {
94+
const granted = await requestBluetoothPermission();
95+
if (!granted) {
96+
useLogsStore
97+
.getState()
98+
.addLog(
99+
"error",
100+
"Bluetooth permission denied",
101+
"layout",
102+
"checkBluetoothPermission",
103+
);
104+
showInfoToast("Bluetooth permission is needed to connect to printer");
105+
}
106+
} catch (error) {
107+
const errorMessage =
108+
error instanceof Error ? error.message : String(error);
109+
useLogsStore
110+
.getState()
111+
.addLog("error", errorMessage, "layout", "checkBluetoothPermission", {
112+
error,
113+
});
114+
}
115+
}
116+
checkBluetoothPermission();
117+
}, []);
118+
85119
if (!_hasHydrated || !fontsLoaded) {
86120
return (
87121
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>

dapps/pos-app/constants/printer-logos.ts

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)