Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions mm2src/kdf_walletconnect/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ use wc_common::{decode_and_decrypt_type0, encrypt_and_encode, EnvelopeType, SymK
const PUBLISH_TIMEOUT_SECS: f64 = 6.;
const CONNECTION_TIMEOUT_S: f64 = 30.;

/// The necessary data to establish a new WalletConnect connection to a newly
/// established pairing by KDF (via [`WalletConnectCtxImpl::new_connection`]).
pub struct NewConnection {
pub url: String,
// TODO: Convert this to a `Topic` instead (after the merger of
// https://github.com/KomodoPlatform/komodo-defi-framework/pull/2499, which pub-uses/exposes `Topic` to other dependent crates)
pub pairing_topic: String,
}

/// Broadcast by the lifecycle task so every RPC can cheaply await connectivity.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum ConnectionState {
Expand Down Expand Up @@ -281,7 +290,7 @@ impl WalletConnectCtxImpl {
&self,
required_namespaces: serde_json::Value,
optional_namespaces: Option<serde_json::Value>,
) -> MmResult<String, WalletConnectError> {
) -> MmResult<NewConnection, WalletConnectError> {
self.await_connection().await?;

let required_namespaces = serde_json::from_value(required_namespaces)?;
Expand All @@ -304,7 +313,10 @@ impl WalletConnectCtxImpl {

send_proposal_request(self, &topic, required_namespaces, optional_namespaces).await?;

Ok(url)
Ok(NewConnection {
url,
pairing_topic: topic.to_string(),
})
}

/// Get symmetric key associated with a for `topic`.
Expand Down
2 changes: 1 addition & 1 deletion mm2src/kdf_walletconnect/src/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ impl SessionManager {
/// Retrieves a cloned session associated with a given topic.
pub fn get_session(&self, topic: &Topic) -> Option<Session> { self.read().get(topic).cloned() }

/// Retrieves a cloned session associated with a given sessionn or pairing topic.
/// Retrieves a cloned session associated with a given session or pairing topic.
pub fn get_session_with_any_topic(&self, topic: &Topic, with_pairing_topic: bool) -> Option<Session> {
if with_pairing_topic {
return self.read().values().find(|s| &s.pairing_topic == topic).cloned();
Expand Down
7 changes: 4 additions & 3 deletions mm2src/mm2_main/src/rpc/wc_commands/new_connection.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use kdf_walletconnect::WalletConnectCtx;
use kdf_walletconnect::{NewConnection, WalletConnectCtx};
use mm2_core::mm_ctx::MmArc;
use mm2_err_handle::prelude::*;
use serde::{Deserialize, Serialize};
Expand All @@ -8,6 +8,7 @@ use super::WalletConnectRpcError;
#[derive(Debug, PartialEq, Serialize)]
pub struct CreateConnectionResponse {
pub url: String,
pub pairing_topic: String,
}

#[derive(Deserialize)]
Expand All @@ -23,10 +24,10 @@ pub async fn new_connection(
) -> MmResult<CreateConnectionResponse, WalletConnectRpcError> {
let wc_ctx =
WalletConnectCtx::from_ctx(&ctx).mm_err(|err| WalletConnectRpcError::InitializationError(err.to_string()))?;
let url = wc_ctx
let NewConnection { url, pairing_topic } = wc_ctx
.new_connection(req.required_namespaces, req.optional_namespaces)
.await
.mm_err(|err| WalletConnectRpcError::SessionRequestError(err.to_string()))?;

Ok(CreateConnectionResponse { url })
Ok(CreateConnectionResponse { url, pairing_topic })
}
Loading