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

Commit

Permalink
fix: Switch network bug
Browse files Browse the repository at this point in the history
  • Loading branch information
reasje committed Sep 12, 2023
1 parent c50ce82 commit f213330
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,19 @@ class OpenDAppPresenter extends CompletePresenter<OpenDAppState> {
_chainConfigurationUseCase.switchDefaultNetwork(toNetwork);
_authUseCase.resetNetwork(toNetwork);
notify(() => state.network = toNetwork);
// state.webviewController?.send("eth_chainId");
var config = """{
ethereum: {
chainId: ${toNetwork.chainId},
rpcUrl: "${toNetwork.web3RpcHttpUrl}",
address: "${state.account!.address}",
isDebug: true,
networkVersion: "${toNetwork.chainId}",
isMetaMask: true
}
}""";
state.webviewController
?.setConfig(config, "0x${toNetwork.chainId.toRadixString(16)}");
state.webviewController?.sendResult('null', id);
}
}
7 changes: 7 additions & 0 deletions packages/web3_provider/lib/js_bridge_callback_bean.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,11 @@ 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);";
await evaluateJavascript(source: script);
await evaluateJavascript(source: script2);
}
}

0 comments on commit f213330

Please sign in to comment.