checkAllowance method

  1. @override
Future checkAllowance({
  1. required String senderAddress,
  2. required String receiverAddress,
  3. required String contractAddress,
  4. required String caip2Chain,
})
override

Implementation

@override
Future<dynamic> checkAllowance({
  required String senderAddress,
  required String receiverAddress,
  required String contractAddress,
  required String caip2Chain,
}) async {
  final data = _buildAllowanceCallData(senderAddress, receiverAddress);
  final body = _buildJsonRpcRequest(
    method: 'eth_call',
    params: [
      {'to': contractAddress, 'data': data},
      'latest',
    ],
  );
  final url = _buildRpcUrl(caip2Chain);
  final response = await http.post(
    url,
    headers: _requiredHeaders,
    body: body,
  );
  _core.logger.i(
    '[$runtimeType] checkAllowance $url, $body => ${response.body}',
  );

  try {
    final namespace = NamespaceUtils.getNamespaceFromChain(caip2Chain);
    final handler = ChainHandlerFactory.getHandlerOrThrow(namespace);
    return _handleResponse(
      response: response,
      parser: (body) => handler.parseBalance(body, _parseRpcResultAs),
      errorContext: 'checkAllowance',
    );
  } on JsonRpcError catch (e) {
    _core.logger.e('[$runtimeType] checkAllowance, parse error => $e');
    throw 'Failed checking allowance';
  }
}