Skip to content

Commit 5aec82a

Browse files
author
NankaiPosition
committed
Upgrade to 1.1.3 - fixed mechanism handle request via EIP1193
Signed-off-by: NankaiPosition <nankai@position.exchange>
1 parent 9124076 commit 5aec82a

File tree

3 files changed

+14
-23
lines changed

3 files changed

+14
-23
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 1.1.3
2+
* fixed mechanism handle request via EIP1193
3+
14
## 1.1.2
25
* update mechanism handle request via EIP1193
36

lib/inapp_webview_eip1193.dart

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -825,9 +825,6 @@ class InAppWebViewEIP1193 extends StatefulWidget {
825825
}
826826

827827
class _InAppWebViewEIP1193State extends State<InAppWebViewEIP1193> {
828-
///Constant message additional receive
829-
final _alertTitle = "messagePayTube";
830-
831828
/// Script provider will inject in web app
832829
String? jsProviderScript;
833830

@@ -872,7 +869,9 @@ class _InAppWebViewEIP1193State extends State<InAppWebViewEIP1193> {
872869
var config = $paramConfig;
873870
window.ethereum = new ${widget.customWalletName}.Provider(config);
874871
${widget.customWalletName}.postMessage = (jsonString) => {
875-
alert("$_alertTitle" + JSON.stringify(jsonString || "{}"))
872+
if (window.flutter_inappwebview.callHandler) {
873+
window.flutter_inappwebview.callHandler('handleRequestEIP1193', JSON.stringify(jsonString));
874+
}
876875
};
877876
})();
878877
""";
@@ -937,6 +936,12 @@ class _InAppWebViewEIP1193State extends State<InAppWebViewEIP1193> {
937936
contextMenu: widget.contextMenu,
938937
onWebViewCreated: (controller) async {
939938
_webViewController = controller;
939+
controller.addJavaScriptHandler(
940+
handlerName: 'handleRequestEIP1193',
941+
callback: (args) {
942+
_jsBridgeCallBack(args[0]);
943+
},
944+
);
940945
widget.onWebViewCreated?.call(controller);
941946
},
942947
onLoadStart: (controller, url) async {
@@ -962,24 +967,7 @@ class _InAppWebViewEIP1193State extends State<InAppWebViewEIP1193> {
962967
onLoadResourceCustomScheme: widget.onLoadResourceCustomScheme,
963968
onCreateWindow: widget.onCreateWindow,
964969
onCloseWindow: widget.onCloseWindow,
965-
onJsAlert: widget.onJsAlert ??
966-
(controller, request) {
967-
final message = request.message;
968-
bool handledByClient = false;
969-
if (message?.contains(_alertTitle) == true) {
970-
handledByClient = true;
971-
_jsBridgeCallBack(
972-
request.message!.replaceFirst(_alertTitle, ""),
973-
);
974-
}
975-
976-
return Future.value(
977-
JsAlertResponse(
978-
message: message ?? "",
979-
handledByClient: handledByClient,
980-
),
981-
);
982-
},
970+
onJsAlert: widget.onJsAlert,
983971
onJsConfirm: widget.onJsConfirm,
984972
onJsPrompt: widget.onJsPrompt,
985973
onReceivedHttpAuthRequest: widget.onReceivedHttpAuthRequest,

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: web3_provider
22
description: The bridge communicate between in-app webview and mobile-app by standard EIP-1193.
3-
version: 1.1.2
3+
version: 1.1.3
44
homepage: https://github.com/PositionExchange/flutter-web3-provider
55

66
environment:

0 commit comments

Comments
 (0)