Skip to content

Commit

Permalink
Merge pull request #182 from MXCzkEVM/big_upgrade
Browse files Browse the repository at this point in the history
feat: JS channel get cookies
  • Loading branch information
reasje authored Feb 5, 2025
2 parents ecd45e0 + 15747bf commit 04dce2e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class BlueberryRingUseCase extends ReactiveUseCase {
_bluetoothUseCase.startScanning(
// withServices: [bluetoothServiceUUID],
// withKeywords: ['Mi', ],
// withKeywords: ['2301', 'BBRING'],
withKeywords: ['2301', 'BBRING'],
// withNames: ['Buds Pro'],
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:moonchain_wallet/app/logger.dart';
import 'package:flutter/material.dart';
import 'package:mxc_logic/mxc_logic.dart';

import '../../../open_dapp.dart';

class FrontEndRequiredHelper {
FrontEndRequiredHelper({
required this.state,
required this.context,
required this.jsChannelHandlerHelper,
});

OpenDAppState state;
BuildContext? context;
JsChannelHandlersHelper jsChannelHandlerHelper;

void injectFrontEndRequiredListeners() {
state.webviewController!.addJavaScriptHandler(
handlerName: JSChannelEvents.getCookies,
callback: (args) => jsChannelHandlerHelper.jsChannelErrorHandler(
args, handleGetCookies));
}

Future<Map<String, dynamic>> handleGetCookies(Map<String, dynamic> data) async {
collectLog('handleGetCookies : $data');

final host = data['url'];

CookieManager cookieManager = CookieManager.instance();
final allCookies =
await cookieManager.getCookies(url: WebUri('https://$host/'));

final cookies =
allCookies
.where((e) {
collectLog("handleGetCookies:e.domain ${e.domain ?? ""}");
return (e.domain?.contains(host) ?? false) && e.isHttpOnly == true;
}) // Exclude HttpOnly cookies
.map((e) =>
e.toMap()) // Convert each cookie to a JSON-serializable map
.toList(); // Convert the iterable to a list

collectLog("handleGetCookies:cookies $cookies");

return {'cookies': cookies};
}
}
2 changes: 1 addition & 1 deletion packages/shared

0 comments on commit 04dce2e

Please sign in to comment.