sendRequest method

  1. @override
Future<Map<String, dynamic>> sendRequest(
  1. dynamic request
)
override

Implementation

@override
Future<Map<String, dynamic>> sendRequest(dynamic request) async {
  if (_gateway == null || _session.walletPublicKey == null) {
    throw TonConnectError('Trying to send bridge request without session.');
  }
  final keyConnection =
      await _storage.getItem(key: IStorage.keyConnection, defaultValue: '{}');
  var connection = jsonDecode(keyConnection!) as Map<String, dynamic>;
  var id = connection['next_rpc_request_id'] != null
      ? connection['next_rpc_request_id'].toString()
      : '0';

  connection['next_rpc_request_id'] = (int.parse(id) + 1).toString();
  await _storage.setItem(
      key: IStorage.keyConnection, value: jsonEncode(connection));

  request['id'] = id;
  logger.d('Provider send http-bridge request: $request');

  final encodedRequest = _session.sessionCrypto.encrypt(
    jsonEncode(request),
    _session.walletPublicKey!,
  );

  await _gateway!
      .send(encodedRequest, _session.walletPublicKey!, request['method']);

  final completer = Completer<Map<String, dynamic>>();
  _pendingRequests[id] = completer;
  return _pendingRequests;
}