requestAddChain method
Implementation
@override
Future<void> requestAddChain(W3MChainInfo newChain) async {
final topic = _currentSession?.topic ?? '';
final currentChainId = 'eip155:$_currentSelectedChainId';
final newChainId = newChain.namespace;
_logger.i('[$runtimeType] requesting switch to add chain $newChainId');
try {
await request(
topic: topic,
chainId: currentChainId,
switchToChainId: newChainId,
request: SessionRequestParams(
method: MethodsConstants.walletAddEthChain,
params: [newChain.toJson()],
),
);
_currentSelectedChainId = newChain.chainId;
await _setSesionAndChainData(_currentSession!);
return;
} catch (e) {
_logger.i('[$runtimeType] requestAddChain error $e');
await _setLocalEthChain(_currentSelectedChainId!);
throw JsonRpcError(code: 5002, message: 'User rejected methods.');
}
}