Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Commit

Permalink
fix: Improved switch chain to support more dapps
Browse files Browse the repository at this point in the history
  • Loading branch information
reasje committed Sep 12, 2023
1 parent f213330 commit 16c5b67
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class OpenAppPage extends HookConsumerWidget {
collectLog('onLoadError: $code: $message'),
onLoadHttpError: (controller, url, statusCode, description) =>
collectLog('onLoadHttpError: $description'),
onConsoleMessage: (controller, consoleMessage) => collectLog(
onConsoleMessage: (controller, consoleMessage) => print(
'onConsoleMessage: ${consoleMessage.toString()}'),
onWebViewCreated: (controller) =>
presenter.onWebViewCreated(controller),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ class OpenDAppPresenter extends CompletePresenter<OpenDAppState> {
}
}""";
state.webviewController
?.setConfig(config, "0x${toNetwork.chainId.toRadixString(16)}");
state.webviewController?.sendResult('null', id);
?.setChain(config, toNetwork.chainId, id);
}
}
11 changes: 7 additions & 4 deletions packages/web3_provider/lib/js_bridge_callback_bean.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@ extension Web3Result on InAppWebViewController {
await evaluateJavascript(source: script);
sendResults([address], id);
}

void setConfig(String config, String chainId) async {
final script = "window.ethereum.setConfig($config);";
final script2 = "window.ethereum.emitConnect($chainId);";

void setChain(String config, int chainId, int id) async {
final script = "console.log(window.ethereum.setConfig($config))";
final script2 = "console.log(window.ethereum.emitConnect($chainId))";
final script3 = "console.log(window.ethereum.emitChainChanged($chainId))";
await evaluateJavascript(source: script);
await evaluateJavascript(source: script2);
await evaluateJavascript(source: script3);
sendResult(chainId.toRadixString(16), id);
}
}

0 comments on commit 16c5b67

Please sign in to comment.