Seperate Metamask and TrustWallet connect Flutter with WalletConnect_dart?

674 Views Asked by At

I am using walletconnect_dart pkg in flutter to connect to metamask and trustwallet application. But when clicking on the button, i have to choose between trustwallet and metamask. I want when i click MM btn it redirect to mm and the same with trustwallet.

     final connector = WalletConnect(
      bridge: 'https://bridge.walletconnect.org',
      clientMeta: const PeerMeta(
          name: 'Nika',
          description: 'An app for converting pictures to NFT',
          url: 'https://nikaguru.page.link/start',
          icons: [
            'https://files.gitbook.com/v0/b/gitbook-legacy-files/o/spaces%2F-LJJeCjcLrr53DcT1Ml7%2Favatar.png?alt=media'
          ]));

  var _session, _uri;

  loginUsingMetamask(BuildContext context) async {
    try {
      print(connector);
      var session = await connector.createSession(onDisplayUri: (uri) async {
        _uri = uri;
        print(uri);
        await launchUrlString(uri, mode: LaunchMode.externalApplication);
      });
      addr = session.accounts[0];
      print(session.accounts[0]);
      print(session.chainId);
      setState(() {
        _session = session;
      });
    } catch (exp) {
      print(exp);
    }
  }
1

There are 1 best solutions below

0
On

Hey sorry if this is late hope this helps what you can do is add "deep-links" of your respective apps while creating a session

i have tested this on android...

e.g.

Future<void> _launchOnlyMetaMaskWallet()async{
  final session = await connector.createSession(
        chainId: chainId,
        onDisplayUri: (uri) async {
          debugPrint("----> URL ---> $uri");
          String metamaskURL = "metamask://wc?uri=$uri";
          String trustwalletURL = "trust://wc?uri=$uri";
          String rainbowURL = "rainbow://wc?uri=$uri";

          try {
            await launchUrl(Uri.parse(metamaskURL), mode: LaunchMode.externalNonBrowserApplication);
          } catch (err) {
            debugPrint("error on launch --> $err");
            await launchStoreUrl();
          }
        },
      );
}