Skip to content

Commit a221579

Browse files
authored
Merge pull request #184 from MXCzkEVM/pre_main_qa
Pre main qa
2 parents 0e7570a + 0780308 commit a221579

File tree

12 files changed

+146
-82
lines changed

12 files changed

+146
-82
lines changed

.fvmrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"flutter": "3.27.1"
3+
}

assets/js/bluetooth/bluetooth.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ class AXSBluetooth {
337337
}
338338

339339
async requestDevice(options) {
340-
console.log("AXSBluetooth:requestDevice ", options);
340+
console.log("AXSBluetooth:requestDevice ", JSON.stringify(options, null, 4));
341341
const response = await window.axs?.callHandlerWrapper("requestDevice", options);
342342

343343
const gatt = new BluetoothRemoteGATTServer(

lib/common/dialogs/network_details/network_details_dialog.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Future<bool?> showNetworkDetailsDialog(
1515
context: context,
1616
bottomSheetTitle: network.label ?? network.web3RpcHttpUrl,
1717
hasCloseButton: false,
18+
closeButtonReturnValue: false,
1819
widgets: [
1920
// Column(
2021
// crossAxisAlignment: CrossAxisAlignment.center,

lib/features/common/packages/bluetooth/blue_plus/bluetooth_use_case.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import 'dart:developer';
33
import 'dart:io';
44

55
import 'package:app_settings/app_settings.dart';
6+
import 'package:flutter/material.dart';
67
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
8+
import 'package:moonchain_wallet/common/common.dart';
79
import 'package:mxc_logic/mxc_logic.dart';
810

911
import 'package:moonchain_wallet/core/core.dart';
@@ -41,6 +43,7 @@ class BluetoothUseCase extends ReactiveUseCase {
4143
late final ValueStream<BluetoothAdapterState> bluetoothStatus =
4244
reactive(BluetoothAdapterState.off);
4345
late final ValueStream<List<ScanResult>> scanResults = reactive([]);
46+
late final ValueStream<ScanResult> selectedScanResult = reactive();
4447

4548
void initBluetoothUseCase() {
4649
initStateListener();
@@ -209,6 +212,27 @@ class BluetoothUseCase extends ReactiveUseCase {
209212
);
210213
}
211214

215+
Future<void> getScanResults(BuildContext context) async {
216+
await Future.delayed(const Duration(seconds: 4), () async {
217+
final currentScanResults = scanResults.value;
218+
final showBottomSheet =
219+
currentScanResults.length > 1 || currentScanResults.isEmpty;
220+
if (showBottomSheet) {
221+
// We need to let the user to choose If two or more devices of rings are available and even If empty maybe let the user to wait
222+
final scanResult = await showBlueberryRingsBottomSheet(
223+
context,
224+
);
225+
if (scanResult != null) {
226+
update(selectedScanResult, scanResult);
227+
}
228+
} else {
229+
// only one scan results
230+
final scanResult = currentScanResults.first;
231+
update(selectedScanResult, scanResult);
232+
}
233+
});
234+
}
235+
212236
void _cancelScannerListen() {
213237
// cleanup: cancel subscription when scanning stops
214238
if (scannerListener != null) {
@@ -225,6 +249,7 @@ class BluetoothUseCase extends ReactiveUseCase {
225249
}
226250

227251
void stopScanner() {
252+
update(scanResults, <ScanResult>[]);
228253
FlutterBluePlus.stopScan();
229254
}
230255
}

lib/features/common/packages/bluetooth/blueberry_ring/domain/blueberry_ring_use_case.dart

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -71,25 +71,14 @@ class BlueberryRingUseCase extends ReactiveUseCase {
7171
// Sets the selectedBlueberryRing
7272
Future<void> getBlueberryRingsNearby(BuildContext context) async {
7373
_bluetoothUseCase.startScanning(
74-
withServices: [bluetoothServiceUUID],
74+
// withServices: [bluetoothServiceUUID],
75+
// withKeywords: ['Mi', ],
76+
withKeywords: ['2301', 'BBRING'],
77+
// withNames: ['Buds Pro'],
7578
);
7679

77-
await Future.delayed(const Duration(seconds: 3), () async {
78-
final scanResults = _bluetoothUseCase.scanResults.value;
79-
if (scanResults.length > 1 || scanResults.isEmpty) {
80-
// We need to let the user to choose If two or more devices of rings are available and even If empty maybe let the user to wait
81-
final scanResult = await showBlueberryRingsBottomSheet(
82-
context,
83-
);
84-
if (scanResult != null) {
85-
update(selectedBlueberryRing, scanResult);
86-
}
87-
} else {
88-
// only one scan results
89-
final scanResult = scanResults.first;
90-
update(selectedBlueberryRing, scanResult);
91-
}
92-
});
80+
await _bluetoothUseCase.getScanResults(context);
81+
update(selectedBlueberryRing, _bluetoothUseCase.selectedScanResult.value);
9382

9483
_bluetoothUseCase.stopScanner();
9584
}

lib/features/dapps/subfeatures/open_dapp/domain/helpers/js_channels/bluetooth_helper.dart

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class BluetoothHelper {
1616
required this.translate,
1717
required this.collectLog,
1818
required this.bluetoothUseCase,
19+
required this.blueberryRingUseCase,
1920
required this.navigator,
2021
required this.minerHooksHelper,
2122
required this.loading,
@@ -25,6 +26,7 @@ class BluetoothHelper {
2526

2627
OpenDAppState state;
2728
BluetoothUseCase bluetoothUseCase;
29+
BlueberryRingUseCase blueberryRingUseCase;
2830
void Function(String line) collectLog;
2931
NavigatorState? navigator;
3032
MinerHooksHelper minerHooksHelper;
@@ -37,7 +39,9 @@ class BluetoothHelper {
3739
Future<Map<String, dynamic>> handleBluetoothRequestDevice(
3840
Map<String, dynamic> channelData,
3941
) async {
42+
collectLog('handleBluetoothRequestDevice:channelData : $channelData');
4043
// final options = RequestDeviceOptions.fromJson(channelData['data']);
44+
4145
final options = RequestDeviceOptions.fromMap(channelData);
4246
late BluetoothDevice responseDevice;
4347

@@ -273,29 +277,15 @@ class BluetoothHelper {
273277

274278
Future<BluetoothDevice?> getBlueberryRing() async {
275279
loading(true);
276-
return Future.delayed(const Duration(seconds: 3), () async {
277-
loading(false);
278-
BluetoothDevice? responseDevice;
279-
final scanResults = bluetoothUseCase.scanResults.value;
280-
if (scanResults.length == 1) {
281-
// only one scan results
282-
final scanResult = scanResults.first;
283-
state.selectedScanResult = scanResult;
284-
} else {
285-
// We need to let the user to choose If two or more devices of rings are available and even If empty maybe let the user to wait
286-
final scanResult = await showBlueberryRingsBottomSheet(
287-
context!,
288-
);
289-
if (scanResult != null) {
290-
state.selectedScanResult = scanResult;
291-
}
292-
}
293-
if (state.selectedScanResult != null) {
294-
responseDevice = BluetoothDevice.getBluetoothDeviceFromScanResult(
295-
state.selectedScanResult!);
296-
}
297-
298-
return responseDevice;
299-
});
280+
await bluetoothUseCase.getScanResults(context!);
281+
loading(false);
282+
BluetoothDevice? responseDevice;
283+
state.selectedScanResult = bluetoothUseCase.selectedScanResult.value;
284+
if (state.selectedScanResult != null) {
285+
responseDevice = BluetoothDevice.getBluetoothDeviceFromScanResult(
286+
state.selectedScanResult!);
287+
}
288+
289+
return responseDevice;
300290
}
301291
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
2+
import 'package:moonchain_wallet/app/logger.dart';
3+
import 'package:flutter/material.dart';
4+
import 'package:mxc_logic/mxc_logic.dart';
5+
6+
import '../../../open_dapp.dart';
7+
8+
class FrontEndRequiredHelper {
9+
FrontEndRequiredHelper({
10+
required this.state,
11+
required this.context,
12+
required this.jsChannelHandlerHelper,
13+
});
14+
15+
OpenDAppState state;
16+
BuildContext? context;
17+
JsChannelHandlersHelper jsChannelHandlerHelper;
18+
19+
void injectFrontEndRequiredListeners() {
20+
state.webviewController!.addJavaScriptHandler(
21+
handlerName: JSChannelEvents.getCookies,
22+
callback: (args) => jsChannelHandlerHelper.jsChannelErrorHandler(
23+
args, handleGetCookies));
24+
}
25+
26+
Future<Map<String, dynamic>> handleGetCookies(Map<String, dynamic> data) async {
27+
collectLog('handleGetCookies : $data');
28+
29+
final host = data['url'];
30+
31+
CookieManager cookieManager = CookieManager.instance();
32+
final allCookies =
33+
await cookieManager.getCookies(url: WebUri('https://$host/'));
34+
35+
final cookies =
36+
allCookies
37+
.where((e) {
38+
collectLog("handleGetCookies:e.domain ${e.domain ?? ""}");
39+
return (e.domain?.contains(host) ?? false) && e.isHttpOnly == true;
40+
}) // Exclude HttpOnly cookies
41+
.map((e) =>
42+
e.toMap()) // Convert each cookie to a JSON-serializable map
43+
.toList(); // Convert the iterable to a list
44+
45+
collectLog("handleGetCookies:cookies $cookies");
46+
47+
return {'cookies': cookies};
48+
}
49+
}

lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'dart:async';
2+
import 'dart:convert';
23
import 'package:flutter/services.dart';
34

45
import 'package:clipboard/clipboard.dart';
@@ -34,6 +35,7 @@ class OpenDAppPresenter extends CompletePresenter<OpenDAppState> {
3435
late final _backgroundFetchConfigUseCase =
3536
ref.read(backgroundFetchConfigUseCaseProvider);
3637
late final _bluetoothUseCase = ref.read(bluetoothUseCaseProvider);
38+
late final _blueberryRingUseCase = ref.read(blueberryRingUseCaseProvider);
3739

3840
Timer? characteristicListenerTimer;
3941
StreamSubscription<List<int>>? characteristicValueStreamSubscription;
@@ -73,6 +75,7 @@ class OpenDAppPresenter extends CompletePresenter<OpenDAppState> {
7375
state: state,
7476
loading: (bool value) => loading = value,
7577
bluetoothUseCase: _bluetoothUseCase,
78+
blueberryRingUseCase: _blueberryRingUseCase,
7679
characteristicListenerTimer: characteristicListenerTimer,
7780
characteristicValueStreamSubscription:
7881
characteristicValueStreamSubscription,
@@ -273,7 +276,6 @@ class OpenDAppPresenter extends CompletePresenter<OpenDAppState> {
273276
injectDAppOrigin();
274277
}
275278

276-
277279
Future<void> injectHairyScript() async {
278280
const hairyScript = """
279281
const send = XMLHttpRequest.prototype.send
@@ -301,8 +303,8 @@ XMLHttpRequest.prototype.send = function (body) {
301303
// This is requested by Hairy on Xiaomi related feature
302304
void injectDAppOrigin() async {
303305
collectLog('Injecting origin $initialUrl to axs.origin object');
304-
await state.webviewController!
305-
.evaluateJavascript(source: "window.axs.origin = '${initialUrl!.origin}';");
306+
await state.webviewController!.evaluateJavascript(
307+
source: "window.axs.origin = '${initialUrl!.origin}';");
306308
await state.webviewController!.evaluateJavascript(
307309
source: "console.log(\"window.axs.origin \" + window.axs.origin)");
308310
}

0 commit comments

Comments
 (0)