request method
Future
request({
- required String? topic,
- required String chainId,
- required SessionRequestParams request,
- String? switchToChainId,
override
Make a request
Implementation
@override
Future<dynamic> request({
required String? topic,
required String chainId,
required SessionRequestParams request,
String? switchToChainId,
}) async {
if (_currentSession == null) {
throw ReownAppKitModalException('Session is null');
}
String reqChainId = chainId;
final isValidChainId = NamespaceUtils.isValidChainId(chainId);
if (!isValidChainId) {
if (selectedChain!.chainId == chainId) {
reqChainId = ReownAppKitModalNetworks.getCaip2Chain(chainId);
} else {
throw Errors.getSdkError(
Errors.UNSUPPORTED_CHAINS,
context: 'chainId should conform to "CAIP-2" format',
);
}
}
//
_appKit.core.logger.d(
'[$runtimeType] request, chainId: $reqChainId, '
'${jsonEncode(request.toJson())}',
);
try {
if (_currentSession!.sessionService.isMagic) {
return await _magicService.request(
chainId: reqChainId,
request: request,
);
}
if (_currentSession!.sessionService.isCoinbase) {
return await await _coinbaseService.request(
chainId: switchToChainId ?? reqChainId,
request: request,
);
}
return await _appKit.request(
topic: topic!,
chainId: reqChainId,
request: request,
);
} catch (e) {
if (_isUserRejectedError(e)) {
onModalError.broadcast(UserRejectedConnection());
if (request.method == MethodsConstants.walletSwitchEthChain ||
request.method == MethodsConstants.walletAddEthChain) {
rethrow;
}
return 'User rejected';
} else {
if (e is CoinbaseServiceException) {
// If the error is due to no session on Coinbase Wallet we disconnnect the session on Modal.
// This is the only way to detect a missing session since Coinbase Wallet is not sending any event.
// disconnect();
throw ReownAppKitModalException('Coinbase Wallet Error');
}
rethrow;
}
}
}