requestAddChain method

  1. @override
Future<void> requestAddChain(
  1. ReownAppKitModalNetworkInfo newChain
)
override

Implementation

@override
Future<void> requestAddChain(ReownAppKitModalNetworkInfo newChain) async {
  final topic = _currentSession?.topic ?? '';
  _appKit.core.logger.i(
    '[$runtimeType] requesting add chain ${newChain.chainId}',
  );
  try {
    await request(
      topic: topic,
      chainId: _selectedChainID!,
      switchToChainId: newChain.chainId,
      request: SessionRequestParams(
        method: MethodsConstants.walletAddEthChain,
        params: [newChain.toRawJson()],
      ),
    );
    _selectedChainID = newChain.chainId;
    await _setSesionAndChainData(_currentSession!);
    return;
  } on JsonRpcError {
    await _setLocalEthChain(_selectedChainID!);
    rethrow;
  } catch (e, s) {
    await _setLocalEthChain(_selectedChainID!);
    throw ReownAppKitModalException(e.toString(), s);
  }
}