Skip to content

Commit 1860776

Browse files
committed
nits
1 parent 5f47368 commit 1860776

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

mm2src/kdf_walletconnect/src/lib.rs

+15-13
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use futures::channel::mpsc::{unbounded, UnboundedReceiver, UnboundedSender};
2222
use futures::lock::Mutex;
2323
use futures::StreamExt;
2424
use inbound_message::{process_inbound_request, process_inbound_response, SessionMessageType};
25-
use metadata::{generate_metadata, AUTH_TOKEN_SUB, PROJECT_ID, RELAY_ADDRESS};
25+
use metadata::{generate_metadata, AUTH_TOKEN_DURATION, AUTH_TOKEN_SUB, PROJECT_ID, RELAY_ADDRESS};
2626
use mm2_core::mm_ctx::{from_ctx, MmArc};
2727
use mm2_err_handle::prelude::*;
2828
use pairing_api::PairingClient;
@@ -109,7 +109,7 @@ impl WalletConnectCtx {
109109
|r, h| abortable_system.weak_spawner().spawn(client_event_loop(r, h)),
110110
);
111111

112-
let inner = Arc::new(WalletConnectCtxImpl {
112+
let context = Arc::new(WalletConnectCtxImpl {
113113
client,
114114
pairing,
115115
relay,
@@ -121,22 +121,23 @@ impl WalletConnectCtx {
121121
});
122122

123123
// Connect to relayer client and spawn a watcher loop for disconnection.
124-
let inner_clone = inner.clone();
125-
inner
124+
context
126125
.abortable_system
127126
.weak_spawner()
128-
.spawn(inner_clone.spawn_connection_initialization(conn_live_receiver));
127+
.spawn(context.clone().spawn_connection_initialization(conn_live_receiver));
129128
// spawn message handler event loop
130-
let inner_clone = inner.clone();
131-
inner_clone.abortable_system.weak_spawner().spawn(async move {
132-
while let Some(msg) = inbound_message_rx.next().await {
133-
if let Err(e) = inner_clone.handle_published_message(msg, message_tx.clone()).await {
134-
debug!("Error processing message: {:?}", e);
129+
context.abortable_system.weak_spawner().spawn({
130+
let context = context.clone();
131+
async move {
132+
while let Some(msg) = inbound_message_rx.next().await {
133+
if let Err(e) = context.handle_published_message(msg, message_tx.clone()).await {
134+
error!("Error processing message: {:?}", e);
135+
}
135136
}
136137
}
137138
});
138139

139-
Ok(Self(inner))
140+
Ok(Self(context))
140141
}
141142

142143
pub fn from_ctx(ctx: &MmArc) -> MmResult<Arc<WalletConnectCtx>, WalletConnectError> {
@@ -149,7 +150,7 @@ impl WalletConnectCtx {
149150

150151
impl WalletConnectCtxImpl {
151152
/// Establishes initial connection to WalletConnect relay server with linear retry mechanism.
152-
/// Uses increasing delay between retry attempts starting from 1sec.
153+
/// Uses increasing delay between retry attempts starting from 1sec and increase exponentially.
153154
/// After successful connection, attempts to restore previous session state from storage.
154155
pub(crate) async fn spawn_connection_initialization(
155156
self: Arc<Self>,
@@ -159,6 +160,7 @@ impl WalletConnectCtxImpl {
159160
let mut retry_count = 0;
160161
let mut retry_secs = 1;
161162

163+
// Connect to WalletConnect relay client(retry until successful) before proceeeding with other initializations.
162164
while let Err(err) = self.connect_client().await {
163165
retry_count += 1;
164166
error!(
@@ -190,7 +192,7 @@ impl WalletConnectCtxImpl {
190192
let key = SigningKey::generate(&mut rand::thread_rng());
191193
AuthToken::new(AUTH_TOKEN_SUB)
192194
.aud(RELAY_ADDRESS)
193-
.ttl(Duration::from_secs(5 * 60 * 60))
195+
.ttl(AUTH_TOKEN_DURATION)
194196
.as_jwt(&key)
195197
.map_to_mm(|err| WalletConnectError::InternalError(err.to_string()))?
196198
};

mm2src/kdf_walletconnect/src/metadata.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
use std::time::Duration;
2+
13
use relay_rpc::rpc::params::Metadata;
24

35
pub(crate) const RELAY_ADDRESS: &str = "wss://relay.walletconnect.com";
46
pub(crate) const PROJECT_ID: &str = "86e916bcbacee7f98225dde86b697f5b";
57
pub(crate) const AUTH_TOKEN_SUB: &str = "http://127.0.0.1:8000";
8+
pub(crate) const AUTH_TOKEN_DURATION: Duration = Duration::from_secs(5 * 60 * 60);
69
pub(crate) const APP_NAME: &str = "Komodefi Framework";
710
pub(crate) const APP_DESCRIPTION: &str = "WallectConnect Komodefi Framework Playground";
811

0 commit comments

Comments
 (0)