walletconnect-dart-sdk icon indicating copy to clipboard operation
walletconnect-dart-sdk copied to clipboard

Switch Network popup

Open VivekMakwana24 opened this issue 2 years ago • 15 comments

Hello,

Is there a way in which I can provide a SwitchNetwork popup to the user?

just like the below-attached screenshot

Image from iOS

VivekMakwana24 avatar Aug 02 '22 06:08 VivekMakwana24

Does any one have any idea about showing the switch network popup?

VivekMakwana24 avatar Aug 03 '22 05:08 VivekMakwana24

Are you trying to show a popup in your own wallet or call the MetaMask switch network popup?

RootSoft avatar Aug 08 '22 08:08 RootSoft

@RootSoft I want to call the MetaMask switchNetwork popup,

VivekMakwana24 avatar Aug 08 '22 13:08 VivekMakwana24

@RootSoft Could you please update on this? Thanks :)

VivekMakwana24 avatar Aug 10 '22 06:08 VivekMakwana24

@RootSoft Any update on my query?

VivekMakwana24 avatar Aug 12 '22 10:08 VivekMakwana24

@VivekMakwana24 I don't think it's possible to do that since that's native to MM, and I don't think they provide an API to show the switch network popup. Your best bet would be to ask in the MM repo?

RootSoft avatar Aug 12 '22 14:08 RootSoft

Ok let me check with them, I have found the below link, do you think it will be useful? https://community.metamask.io/t/how-to-send-switch-network-request-from-dapp-to-metamask-mobile/13501

VivekMakwana24 avatar Aug 16 '22 05:08 VivekMakwana24

@RootSoft Below is the code that I have tried, but unfortunately I am not getting any response from it.

`

Future<dynamic> switchNetwork() async {
    final request = JsonRpcRequest(
      id: payloadId,
      method: 'wallet_switchEthereumChain',
      params: [
        {
          "chainId": "0xa86a",
        }
      ],
    );

    session.handshakeId = request.id;
    session.handshakeTopic = const Uuid().v4();

    debugPrint("req2 ${request.toJson()}");

    final response = await sendRequest(request, topic: session.handshakeTopic);
    debugPrint("response ${response}");

    return response;
  }

` Request : {id: 1660718671093646, jsonrpc: 2.0, method: wallet_switchEthereumChain, params: [{chainId: 0xa86a}]} Response : null

VivekMakwana24 avatar Aug 17 '22 06:08 VivekMakwana24

Any updates on this issue? I am also trying to switch the network but no luck.

robmagario avatar Sep 22 '22 03:09 robmagario

@robmagario No, I have tried by contacting the walletConnect community but no solution yet

VivekMakwana24 avatar Sep 22 '22 13:09 VivekMakwana24

@VivekMakwana24 I think you'll have to dig in the Metamask source code. Maybe build the app and step through it. Unfortunately, at the moment I don't have a lot of time to dig deep into this. This is more related to Metamask then WC in my opinion.

RootSoft avatar Sep 22 '22 22:09 RootSoft

@VivekMakwana24 Try this

await connector.sendCustomRequest( method: 'wallet_switchEthereumChain', params: [ { 'chainId': '0x${provider.chainId.toRadixString(16)}', }, ], );

olegys avatar Oct 01 '22 10:10 olegys

@olegys Did it worked with metamask?

VivekMakwana24 avatar Oct 03 '22 06:10 VivekMakwana24

@VivekMakwana24 Yes

olegys avatar Oct 03 '22 19:10 olegys

@olegys

This is how I have tried it, But Unfortunately, I am receiving null response.

I tried to call this method before launching the walletURI for connection.

Is it the correct flow?

Screenshot from 2022-10-04 18-45-11

VivekMakwana24 avatar Oct 04 '22 13:10 VivekMakwana24