rebuildConnectionUri method

  1. @override
Future<void> rebuildConnectionUri()
override

Rebuilds the connection URI. If the dapp attempts to connect to a wallet, and the connection proposal is consumed, but not accepted or rejected (no response), and they navigate back to the dapp and try again then no connection proposal will be sent. This is because the connection proposal is already consumed. So, every time they tap on a button to connect to a wallet, we need to rebuild the connection URI to ensure that each time they tap on a wallet, a new connection proposal is sent.

This will do nothing if isConnected is true.

Implementation

@override
Future<void> rebuildConnectionUri() async {
  // If we aren't connected, connect!
  if (!_isConnected) {
    LoggerUtil.logger.i(
      'Connecting to WalletConnect, required namespaces: $_requiredNamespaces',
    );

    if (connectResponse != null) {
      try {
        sessionFuture!.timeout(Duration.zero);
      } on TimeoutException {
        // Ignore this error, just wanted to cancel the previous future.
      }
    }

    connectResponse = await web3App!.connect(
      requiredNamespaces: _requiredNamespaces,
    );

    notifyListeners();

    _awaitConnectResponse();
  }
}