forked from MXCzkEVM/datadash-wallet
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #182 from MXCzkEVM/big_upgrade
feat: JS channel get cookies
- Loading branch information
Showing
3 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...res/dapps/subfeatures/open_dapp/domain/helpers/js_channels/front_end_required_helper.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}; | ||
} | ||
} |