RootSoft / walletconnect-dart-sdk

Open protocol for connecting dApps to mobile wallets with QR code scanning or deep linking.
MIT License
102 stars 61 forks source link

Switch Network popup #67

Open VivekMakwana24 opened 2 years ago

VivekMakwana24 commented 2 years ago

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 commented 2 years ago

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

RootSoft commented 2 years ago

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

VivekMakwana24 commented 2 years ago

@RootSoft I want to call the MetaMask switchNetwork popup,

VivekMakwana24 commented 2 years ago

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

VivekMakwana24 commented 2 years ago

@RootSoft Any update on my query?

RootSoft commented 2 years ago

@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?

VivekMakwana24 commented 2 years ago

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 commented 2 years ago

@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

robmagario commented 2 years ago

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

VivekMakwana24 commented 2 years ago

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

RootSoft commented 2 years ago

@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.

olegys commented 2 years ago

@VivekMakwana24 Try this

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

VivekMakwana24 commented 2 years ago

@olegys Did it worked with metamask?

olegys commented 2 years ago

@VivekMakwana24 Yes

VivekMakwana24 commented 2 years ago

@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