react-native-fpay 0.3.5 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/module/FountainPayProvider.js +108 -18
- package/lib/module/FountainPayProvider.js.map +1 -1
- package/lib/module/core/api/client.js +13 -1
- package/lib/module/core/api/client.js.map +1 -1
- package/lib/module/core/api/index.js +66 -24
- package/lib/module/core/api/index.js.map +1 -1
- package/lib/module/engine/BLEReceiverService.js.map +1 -1
- package/lib/module/engine/BLESenderService.js.map +1 -1
- package/lib/module/engine/FPEngine.js +164 -43
- package/lib/module/engine/FPEngine.js.map +1 -1
- package/lib/module/engine/NearbyUsersService.js +1 -1
- package/lib/module/engine/NearbyUsersService.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/store/FPStore.js +155 -0
- package/lib/module/store/FPStore.js.map +1 -0
- package/lib/module/ui/components/AnimatedDots.js +3 -3
- package/lib/module/ui/components/AnimatedDots.js.map +1 -1
- package/lib/module/ui/components/ConfirmScreen.js +137 -123
- package/lib/module/ui/components/ConfirmScreen.js.map +1 -1
- package/lib/module/ui/components/FPButton.js.map +1 -1
- package/lib/module/ui/components/LoadingAnimation/InLoading.js +3 -3
- package/lib/module/ui/components/LoadingAnimation/InLoading.js.map +1 -1
- package/lib/module/ui/components/LoadingAnimation/index.js +3 -3
- package/lib/module/ui/components/LoadingAnimation/index.js.map +1 -1
- package/lib/module/ui/components/OtpInput/OTPInputView.js +11 -11
- package/lib/module/ui/components/OtpInput/OTPInputView.js.map +1 -1
- package/lib/module/ui/components/OtpInput/Styles.js +1 -1
- package/lib/module/ui/components/OtpInput/helpers/codeToArray.js +1 -1
- package/lib/module/ui/components/OtpInput/helpers/device.js.map +1 -1
- package/lib/module/ui/components/OtpInput/helpers/styles.js.map +1 -1
- package/lib/module/ui/components/OtpInput/index.js +3 -1
- package/lib/module/ui/components/OtpInput/index.js.map +1 -1
- package/lib/module/ui/components/PulseAnimation.js +2 -2
- package/lib/module/ui/components/PulseAnimation.js.map +1 -1
- package/lib/module/ui/modals/FPPaymentRequestModal.js +8 -7
- package/lib/module/ui/modals/FPPaymentRequestModal.js.map +1 -1
- package/lib/module/ui/modals/FPShell.js +2 -0
- package/lib/module/ui/modals/FPShell.js.map +1 -1
- package/lib/module/ui/screens/ReceiveScreen.js +8 -9
- package/lib/module/ui/screens/ReceiveScreen.js.map +1 -1
- package/lib/module/ui/screens/SendScreen.js +43 -94
- package/lib/module/ui/screens/SendScreen.js.map +1 -1
- package/lib/module/ui/screens/styles.js +15 -3
- package/lib/module/ui/screens/styles.js.map +1 -1
- package/lib/module/ui/screens/sub/receivePayment/Nfc/index.js +4 -4
- package/lib/module/ui/screens/sub/receivePayment/Nfc/index.js.map +1 -1
- package/lib/module/ui/screens/sub/receivePayment/Qr/index.js +5 -5
- package/lib/module/ui/screens/sub/receivePayment/Qr/index.js.map +1 -1
- package/lib/module/ui/screens/sub/receivePayment/Transfer/index.js +10 -11
- package/lib/module/ui/screens/sub/receivePayment/Transfer/index.js.map +1 -1
- package/lib/module/ui/screens/sub/sendPayment/BluetoothSubScreen.js +31 -8
- package/lib/module/ui/screens/sub/sendPayment/BluetoothSubScreen.js.map +1 -1
- package/lib/module/ui/screens/sub/sendPayment/NFCSubScreen.js +12 -8
- package/lib/module/ui/screens/sub/sendPayment/NFCSubScreen.js.map +1 -1
- package/lib/module/ui/screens/sub/sendPayment/NQRSubScreen.js +17 -5
- package/lib/module/ui/screens/sub/sendPayment/NQRSubScreen.js.map +1 -1
- package/lib/module/ui/screens/sub/sendPayment/ProximitySubScreen.js +67 -35
- package/lib/module/ui/screens/sub/sendPayment/ProximitySubScreen.js.map +1 -1
- package/lib/module/ui/screens/sub/sendPayment/TransferSubScreen.js +110 -34
- package/lib/module/ui/screens/sub/sendPayment/TransferSubScreen.js.map +1 -1
- package/lib/module/ui/theme/index.js.map +1 -1
- package/lib/typescript/src/FountainPayProvider.d.ts +1 -1
- package/lib/typescript/src/FountainPayProvider.d.ts.map +1 -1
- package/lib/typescript/src/core/api/client.d.ts.map +1 -1
- package/lib/typescript/src/core/api/index.d.ts +42 -26
- package/lib/typescript/src/core/api/index.d.ts.map +1 -1
- package/lib/typescript/src/core/types/index.d.ts +53 -28
- package/lib/typescript/src/core/types/index.d.ts.map +1 -1
- package/lib/typescript/src/engine/BLEReceiverService.d.ts +2 -0
- package/lib/typescript/src/engine/BLEReceiverService.d.ts.map +1 -1
- package/lib/typescript/src/engine/BLESenderService.d.ts.map +1 -1
- package/lib/typescript/src/engine/FPEngine.d.ts +5 -3
- package/lib/typescript/src/engine/FPEngine.d.ts.map +1 -1
- package/lib/typescript/src/engine/useIsForeground.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/store/FPStore.d.ts +60 -0
- package/lib/typescript/src/store/FPStore.d.ts.map +1 -0
- package/lib/typescript/src/ui/components/AnimatedDots.d.ts.map +1 -1
- package/lib/typescript/src/ui/components/ConfirmScreen.d.ts +5 -5
- package/lib/typescript/src/ui/components/ConfirmScreen.d.ts.map +1 -1
- package/lib/typescript/src/ui/components/FPButton.d.ts +1 -1
- package/lib/typescript/src/ui/components/FPButton.d.ts.map +1 -1
- package/lib/typescript/src/ui/components/LoadingAnimation/InLoading.d.ts.map +1 -1
- package/lib/typescript/src/ui/components/LoadingAnimation/index.d.ts.map +1 -1
- package/lib/typescript/src/ui/components/OtpInput/OTPInputView.d.ts.map +1 -1
- package/lib/typescript/src/ui/components/OtpInput/helpers/codeToArray.d.ts.map +1 -1
- package/lib/typescript/src/ui/components/OtpInput/helpers/device.d.ts.map +1 -1
- package/lib/typescript/src/ui/components/OtpInput/helpers/styles.d.ts.map +1 -1
- package/lib/typescript/src/ui/components/OtpInput/helpers/types.d.ts +1 -2
- package/lib/typescript/src/ui/components/OtpInput/helpers/types.d.ts.map +1 -1
- package/lib/typescript/src/ui/components/OtpInput/index.d.ts +3 -1
- package/lib/typescript/src/ui/components/OtpInput/index.d.ts.map +1 -1
- package/lib/typescript/src/ui/components/PulseAnimation.d.ts.map +1 -1
- package/lib/typescript/src/ui/modals/FPPaymentRequestModal.d.ts.map +1 -1
- package/lib/typescript/src/ui/modals/FPShell.d.ts.map +1 -1
- package/lib/typescript/src/ui/screens/ReceiveScreen.d.ts +1 -1
- package/lib/typescript/src/ui/screens/ReceiveScreen.d.ts.map +1 -1
- package/lib/typescript/src/ui/screens/SendScreen.d.ts +1 -1
- package/lib/typescript/src/ui/screens/SendScreen.d.ts.map +1 -1
- package/lib/typescript/src/ui/screens/styles.d.ts +197 -0
- package/lib/typescript/src/ui/screens/styles.d.ts.map +1 -1
- package/lib/typescript/src/ui/screens/sub/receivePayment/Nfc/index.d.ts.map +1 -1
- package/lib/typescript/src/ui/screens/sub/receivePayment/Qr/index.d.ts.map +1 -1
- package/lib/typescript/src/ui/screens/sub/receivePayment/Transfer/index.d.ts.map +1 -1
- package/lib/typescript/src/ui/screens/sub/sendPayment/BluetoothSubScreen.d.ts.map +1 -1
- package/lib/typescript/src/ui/screens/sub/sendPayment/NFCSubScreen.d.ts +1 -1
- package/lib/typescript/src/ui/screens/sub/sendPayment/NFCSubScreen.d.ts.map +1 -1
- package/lib/typescript/src/ui/screens/sub/sendPayment/NQRSubScreen.d.ts +1 -1
- package/lib/typescript/src/ui/screens/sub/sendPayment/NQRSubScreen.d.ts.map +1 -1
- package/lib/typescript/src/ui/screens/sub/sendPayment/ProximitySubScreen.d.ts +1 -1
- package/lib/typescript/src/ui/screens/sub/sendPayment/ProximitySubScreen.d.ts.map +1 -1
- package/lib/typescript/src/ui/screens/sub/sendPayment/TransferSubScreen.d.ts +1 -1
- package/lib/typescript/src/ui/screens/sub/sendPayment/TransferSubScreen.d.ts.map +1 -1
- package/lib/typescript/src/ui/theme/index.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/FountainPayProvider.tsx +163 -24
- package/src/core/api/client.ts +26 -4
- package/src/core/api/index.ts +170 -49
- package/src/core/types/index.ts +81 -48
- package/src/engine/BLEReceiverService.ts +86 -28
- package/src/engine/BLESenderService.ts +133 -69
- package/src/engine/FPEngine.ts +316 -97
- package/src/engine/NearbyUsersService.ts +6 -6
- package/src/engine/useIsForeground.ts +12 -12
- package/src/index.ts +10 -4
- package/src/store/FPStore.ts +216 -0
- package/src/ui/components/AnimatedDots.tsx +4 -5
- package/src/ui/components/ConfirmScreen.tsx +182 -169
- package/src/ui/components/FPButton.tsx +50 -9
- package/src/ui/components/LoadingAnimation/InLoading.tsx +23 -27
- package/src/ui/components/LoadingAnimation/index.tsx +3 -7
- package/src/ui/components/OtpInput/OTPInputView.tsx +254 -205
- package/src/ui/components/OtpInput/Styles.ts +1 -1
- package/src/ui/components/OtpInput/helpers/codeToArray.ts +2 -2
- package/src/ui/components/OtpInput/helpers/device.ts +4 -3
- package/src/ui/components/OtpInput/helpers/styles.ts +13 -14
- package/src/ui/components/OtpInput/helpers/types.ts +83 -79
- package/src/ui/components/OtpInput/index.tsx +18 -15
- package/src/ui/components/PulseAnimation.tsx +3 -5
- package/src/ui/modals/FPPaymentRequestModal.tsx +111 -28
- package/src/ui/modals/FPShell.tsx +60 -34
- package/src/ui/screens/ReceiveScreen.tsx +245 -84
- package/src/ui/screens/SendScreen.tsx +419 -167
- package/src/ui/screens/styles.ts +17 -5
- package/src/ui/screens/sub/receivePayment/Nfc/index.tsx +17 -25
- package/src/ui/screens/sub/receivePayment/Qr/index.tsx +21 -20
- package/src/ui/screens/sub/receivePayment/Transfer/index.tsx +34 -28
- package/src/ui/screens/sub/sendPayment/BluetoothSubScreen.tsx +135 -67
- package/src/ui/screens/sub/sendPayment/NFCSubScreen.tsx +188 -112
- package/src/ui/screens/sub/sendPayment/NQRSubScreen.tsx +102 -69
- package/src/ui/screens/sub/sendPayment/ProximitySubScreen.tsx +225 -99
- package/src/ui/screens/sub/sendPayment/TransferSubScreen.tsx +209 -89
- package/src/ui/theme/index.ts +14 -2
|
@@ -4,7 +4,12 @@
|
|
|
4
4
|
// same write fallback (writeWithoutResponse → writeWithResponse).
|
|
5
5
|
// Only changes: renamed types to match SDK conventions, removed Alert imports.
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
BleManager,
|
|
9
|
+
Device,
|
|
10
|
+
State as BluetoothState,
|
|
11
|
+
ScanMode,
|
|
12
|
+
} from 'react-native-ble-plx';
|
|
8
13
|
import { PermissionsAndroid, Platform } from 'react-native';
|
|
9
14
|
import { Buffer } from 'buffer';
|
|
10
15
|
import {
|
|
@@ -19,7 +24,6 @@ import type { FintechDevice } from '../core/types';
|
|
|
19
24
|
|
|
20
25
|
// A discovered FountainPay-capable BLE device (shown in BluetoothSubScreen list)
|
|
21
26
|
|
|
22
|
-
|
|
23
27
|
// The payment request written to the receiver's characteristic
|
|
24
28
|
export interface BLESendPaymentRequest {
|
|
25
29
|
amount: number;
|
|
@@ -72,18 +76,26 @@ class BLESenderService {
|
|
|
72
76
|
PermissionsAndroid.PERMISSIONS.BLUETOOTH_CONNECT,
|
|
73
77
|
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
|
|
74
78
|
]);
|
|
75
|
-
return Object.values(results).every(
|
|
79
|
+
return Object.values(results).every(
|
|
80
|
+
(r) => r === PermissionsAndroid.RESULTS.GRANTED
|
|
81
|
+
);
|
|
76
82
|
}
|
|
77
|
-
const granted = await PermissionsAndroid.request(
|
|
83
|
+
const granted = await PermissionsAndroid.request(
|
|
84
|
+
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION
|
|
85
|
+
);
|
|
78
86
|
return granted === PermissionsAndroid.RESULTS.GRANTED;
|
|
79
87
|
}
|
|
80
88
|
|
|
81
89
|
private _initializeBLE(): Promise<void> {
|
|
82
90
|
return new Promise((resolve, reject) => {
|
|
83
|
-
const sub = this.bleManager.onStateChange(state => {
|
|
91
|
+
const sub = this.bleManager.onStateChange((state) => {
|
|
84
92
|
switch (state) {
|
|
85
93
|
case BluetoothState.Unsupported:
|
|
86
|
-
reject(
|
|
94
|
+
reject(
|
|
95
|
+
new Error(
|
|
96
|
+
'[FPay BLE Sender] Bluetooth not supported on this device'
|
|
97
|
+
)
|
|
98
|
+
);
|
|
87
99
|
sub.remove();
|
|
88
100
|
break;
|
|
89
101
|
case BluetoothState.PoweredOff:
|
|
@@ -131,12 +143,18 @@ class BLESenderService {
|
|
|
131
143
|
|
|
132
144
|
if (device && !seen.has(device.id)) {
|
|
133
145
|
seen.add(device.id);
|
|
134
|
-
console.log(
|
|
146
|
+
console.log(
|
|
147
|
+
'[FPay BLE Sender] Found device:',
|
|
148
|
+
device.name ?? device.id
|
|
149
|
+
);
|
|
135
150
|
try {
|
|
136
151
|
const fp = await this._readDeviceInfo(device);
|
|
137
152
|
if (fp) onDeviceFound(fp);
|
|
138
153
|
} catch (err) {
|
|
139
|
-
console.warn(
|
|
154
|
+
console.warn(
|
|
155
|
+
'[FPay BLE Sender] Could not read device info:',
|
|
156
|
+
err
|
|
157
|
+
);
|
|
140
158
|
}
|
|
141
159
|
}
|
|
142
160
|
}
|
|
@@ -144,7 +162,11 @@ class BLESenderService {
|
|
|
144
162
|
|
|
145
163
|
setTimeout(() => {
|
|
146
164
|
this.bleManager.stopDeviceScan();
|
|
147
|
-
console.log(
|
|
165
|
+
console.log(
|
|
166
|
+
'[FPay BLE Sender] Scan complete. Found:',
|
|
167
|
+
seen.size,
|
|
168
|
+
'FPay device(s)'
|
|
169
|
+
);
|
|
148
170
|
resolve();
|
|
149
171
|
}, durationMs);
|
|
150
172
|
});
|
|
@@ -154,21 +176,28 @@ class BLESenderService {
|
|
|
154
176
|
try {
|
|
155
177
|
const connected = await this.bleManager.connectToDevice(device.id);
|
|
156
178
|
await connected.discoverAllServicesAndCharacteristics();
|
|
157
|
-
const char = await connected.readCharacteristicForService(
|
|
179
|
+
const char = await connected.readCharacteristicForService(
|
|
180
|
+
FP_SERVICE_UUID,
|
|
181
|
+
FP_USERINFO_CHAR_UUID
|
|
182
|
+
);
|
|
158
183
|
await this.bleManager.cancelDeviceConnection(device.id);
|
|
159
184
|
|
|
160
185
|
if (!char.value) return null;
|
|
161
|
-
const info = JSON.parse(
|
|
186
|
+
const info = JSON.parse(
|
|
187
|
+
Buffer.from(char.value, 'base64').toString('utf8')
|
|
188
|
+
);
|
|
162
189
|
return {
|
|
163
|
-
id:
|
|
164
|
-
name:
|
|
165
|
-
appName:
|
|
166
|
-
userName:
|
|
167
|
-
rssi:
|
|
190
|
+
id: device.id,
|
|
191
|
+
name: device.name ?? 'Unknown Device',
|
|
192
|
+
appName: info.appName ?? 'FountainPay',
|
|
193
|
+
userName: info.userName ?? '',
|
|
194
|
+
rssi: device.rssi ?? -100,
|
|
168
195
|
rawDevice: device,
|
|
169
196
|
};
|
|
170
197
|
} catch (err) {
|
|
171
|
-
try {
|
|
198
|
+
try {
|
|
199
|
+
await this.bleManager.cancelDeviceConnection(device.id);
|
|
200
|
+
} catch {}
|
|
172
201
|
return null;
|
|
173
202
|
}
|
|
174
203
|
}
|
|
@@ -177,7 +206,9 @@ class BLESenderService {
|
|
|
177
206
|
|
|
178
207
|
async connectToDevice(deviceId: string): Promise<Device> {
|
|
179
208
|
console.log('[FPay BLE Sender] Connecting to', deviceId);
|
|
180
|
-
const device = await this.bleManager.connectToDevice(deviceId, {
|
|
209
|
+
const device = await this.bleManager.connectToDevice(deviceId, {
|
|
210
|
+
timeout: 15000,
|
|
211
|
+
});
|
|
181
212
|
await device.discoverAllServicesAndCharacteristics();
|
|
182
213
|
this.connectedDevices.set(deviceId, device);
|
|
183
214
|
console.log('[FPay BLE Sender] Connected and services discovered');
|
|
@@ -207,57 +238,76 @@ class BLESenderService {
|
|
|
207
238
|
if (!device) device = await this.connectToDevice(deviceId);
|
|
208
239
|
|
|
209
240
|
// Start polling BEFORE writing the request, so we don't miss a fast response
|
|
210
|
-
const responsePromise = new Promise<BLESendPaymentResponse>(
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
console.log('[FPay BLE Sender] Polling response characteristic...');
|
|
225
|
-
const char = await device!.readCharacteristicForService(
|
|
226
|
-
FP_SERVICE_UUID, FP_RESPONSE_CHAR_UUID
|
|
227
|
-
);
|
|
241
|
+
const responsePromise = new Promise<BLESendPaymentResponse>(
|
|
242
|
+
async (resolve, reject) => {
|
|
243
|
+
const startTime = Date.now();
|
|
244
|
+
|
|
245
|
+
const poll = async () => {
|
|
246
|
+
while (!responseReceived) {
|
|
247
|
+
if (Date.now() - startTime > 60000) {
|
|
248
|
+
reject(
|
|
249
|
+
new Error(
|
|
250
|
+
'[FPay BLE Sender] Response timeout — receiver did not respond in 60s'
|
|
251
|
+
)
|
|
252
|
+
);
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
228
255
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
256
|
+
try {
|
|
257
|
+
await new Promise((r) => setTimeout(r, 1000));
|
|
258
|
+
if (responseReceived) break;
|
|
259
|
+
|
|
260
|
+
console.log(
|
|
261
|
+
'[FPay BLE Sender] Polling response characteristic...'
|
|
262
|
+
);
|
|
263
|
+
const char = await device!.readCharacteristicForService(
|
|
264
|
+
FP_SERVICE_UUID,
|
|
265
|
+
FP_RESPONSE_CHAR_UUID
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
if (char.value && char.value.length > 0) {
|
|
269
|
+
const decoded = Buffer.from(char.value, 'base64').toString(
|
|
270
|
+
'utf8'
|
|
271
|
+
);
|
|
272
|
+
const resp: BLESendPaymentResponse = JSON.parse(decoded);
|
|
273
|
+
|
|
274
|
+
// Verify this response matches OUR request via the echoed timestamp
|
|
275
|
+
if (
|
|
276
|
+
resp.timestamp &&
|
|
277
|
+
resp.requestTimestamp &&
|
|
278
|
+
resp.requestTimestamp === request.timestamp
|
|
279
|
+
) {
|
|
280
|
+
console.log(
|
|
281
|
+
'[FPay BLE Sender] Response received — accepted:',
|
|
282
|
+
resp.accepted
|
|
283
|
+
);
|
|
284
|
+
responseReceived = true;
|
|
285
|
+
resolve(resp);
|
|
286
|
+
break;
|
|
287
|
+
} else {
|
|
288
|
+
console.log(
|
|
289
|
+
'[FPay BLE Sender] Old/unrelated response, still polling...'
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
} catch (pollErr: any) {
|
|
294
|
+
// errorCode 205 = device disconnected — abort immediately
|
|
295
|
+
if (pollErr.errorCode === 205) {
|
|
296
|
+
reject(new Error('[FPay BLE Sender] Device disconnected'));
|
|
242
297
|
break;
|
|
243
|
-
} else {
|
|
244
|
-
console.log('[FPay BLE Sender] Old/unrelated response, still polling...');
|
|
245
298
|
}
|
|
299
|
+
// All other errors: log and keep polling
|
|
300
|
+
console.warn(
|
|
301
|
+
'[FPay BLE Sender] Poll error (non-fatal):',
|
|
302
|
+
pollErr.message
|
|
303
|
+
);
|
|
246
304
|
}
|
|
247
|
-
} catch (pollErr: any) {
|
|
248
|
-
// errorCode 205 = device disconnected — abort immediately
|
|
249
|
-
if (pollErr.errorCode === 205) {
|
|
250
|
-
reject(new Error('[FPay BLE Sender] Device disconnected'));
|
|
251
|
-
break;
|
|
252
|
-
}
|
|
253
|
-
// All other errors: log and keep polling
|
|
254
|
-
console.warn('[FPay BLE Sender] Poll error (non-fatal):', pollErr.message);
|
|
255
305
|
}
|
|
256
|
-
}
|
|
257
|
-
};
|
|
306
|
+
};
|
|
258
307
|
|
|
259
|
-
|
|
260
|
-
|
|
308
|
+
poll().catch(reject);
|
|
309
|
+
}
|
|
310
|
+
);
|
|
261
311
|
|
|
262
312
|
// Write the payment request
|
|
263
313
|
const base64 = Buffer.from(JSON.stringify(request)).toString('base64');
|
|
@@ -265,18 +315,24 @@ class BLESenderService {
|
|
|
265
315
|
|
|
266
316
|
try {
|
|
267
317
|
await device.writeCharacteristicWithoutResponseForService(
|
|
268
|
-
FP_SERVICE_UUID,
|
|
318
|
+
FP_SERVICE_UUID,
|
|
319
|
+
FP_REQUEST_CHAR_UUID,
|
|
320
|
+
base64
|
|
269
321
|
);
|
|
270
322
|
console.log('[FPay BLE Sender] Written without response (preferred)');
|
|
271
323
|
} catch {
|
|
272
324
|
console.log('[FPay BLE Sender] Retrying with response...');
|
|
273
325
|
await device.writeCharacteristicWithResponseForService(
|
|
274
|
-
FP_SERVICE_UUID,
|
|
326
|
+
FP_SERVICE_UUID,
|
|
327
|
+
FP_REQUEST_CHAR_UUID,
|
|
328
|
+
base64
|
|
275
329
|
);
|
|
276
330
|
console.log('[FPay BLE Sender] Written with response');
|
|
277
331
|
}
|
|
278
332
|
|
|
279
|
-
console.log(
|
|
333
|
+
console.log(
|
|
334
|
+
'[FPay BLE Sender] Request sent. Waiting for accept/decline...'
|
|
335
|
+
);
|
|
280
336
|
|
|
281
337
|
const response = await responsePromise;
|
|
282
338
|
await this.disconnectDevice(deviceId);
|
|
@@ -291,11 +347,15 @@ class BLESenderService {
|
|
|
291
347
|
|
|
292
348
|
async disconnectDevice(deviceId: string): Promise<void> {
|
|
293
349
|
if (this.monitorSubscription) {
|
|
294
|
-
try {
|
|
350
|
+
try {
|
|
351
|
+
this.monitorSubscription.remove();
|
|
352
|
+
} catch {}
|
|
295
353
|
this.monitorSubscription = null;
|
|
296
354
|
}
|
|
297
355
|
if (this.connectedDevices.has(deviceId)) {
|
|
298
|
-
try {
|
|
356
|
+
try {
|
|
357
|
+
await this.bleManager.cancelDeviceConnection(deviceId);
|
|
358
|
+
} catch {}
|
|
299
359
|
this.connectedDevices.delete(deviceId);
|
|
300
360
|
console.log('[FPay BLE Sender] Disconnected from', deviceId);
|
|
301
361
|
}
|
|
@@ -306,7 +366,11 @@ class BLESenderService {
|
|
|
306
366
|
destroy(): void {
|
|
307
367
|
this.bleManager.stopDeviceScan();
|
|
308
368
|
this.connectedDevices.clear();
|
|
309
|
-
if (this.monitorSubscription) {
|
|
369
|
+
if (this.monitorSubscription) {
|
|
370
|
+
try {
|
|
371
|
+
this.monitorSubscription.remove();
|
|
372
|
+
} catch {}
|
|
373
|
+
}
|
|
310
374
|
this.bleManager.destroy();
|
|
311
375
|
}
|
|
312
376
|
}
|