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