sendProposeSessionRequest method
Future
sendProposeSessionRequest(
- String topic,
- Map<
String, dynamic> params, { - int? id,
- EncodeOptions? encodeOptions,
override
Sign 2.5 Substitutes wc_sessionPropose sendRequest() during signEngine.connect()
Implementation
@override
Future<dynamic> sendProposeSessionRequest(
String topic,
Map<String, dynamic> params, {
int? id,
EncodeOptions? encodeOptions,
}) async {
final proposeSessionPayload = JsonRpcUtils.formatJsonRpcRequest(
MethodConstants.WC_SESSION_PROPOSE,
params,
id: id,
);
final requestId = proposeSessionPayload['id'] as int;
final proposeSessionMessage = await core.crypto.encode(
topic,
proposeSessionPayload,
options: encodeOptions,
);
if (proposeSessionMessage == null) {
return;
}
// print('adding payload to pending requests: $requestId');
final resp = PendingRequestResponse(
completer: Completer(),
method: MethodConstants.WC_SESSION_PROPOSE,
);
resp.completer.future.catchError(
(err) => core.events.recordEvent(BasicCoreEvent(
event: CoreEventType.ERROR,
properties: CoreEventProperties(topic: topic, method: resp.method),
)),
);
pendingRequests[requestId] = resp;
final payload = {
'pairingTopic': topic,
'sessionProposal': proposeSessionMessage,
};
// ttl and tag are not required on Sign 2.5 methods, it's assigned relay-side
final options = PublishOptions(
correlationId: requestId,
publishMethod: RelayClient.WC_PROPOSE_SESSION,
);
await core.relayClient.publishPayload(
payload: payload,
options: options,
);
core.logger.d(
'[$runtimeType] sendProposeSessionRequest relayClient, '
'payload: ${jsonEncode(payload)}, options: ${jsonEncode(options.toJson())}',
);
// Get the result from the completer, if it's an error, throw it
try {
if (resp.error != null) {
throw resp.error!;
}
// print('checking if completed');
if (resp.completer.isCompleted) {
return resp.response;
}
return await resp.completer.future;
} catch (e) {
rethrow;
}
}