@@ -22,7 +22,7 @@ use futures::channel::mpsc::{unbounded, UnboundedReceiver, UnboundedSender};
22
22
use futures:: lock:: Mutex ;
23
23
use futures:: StreamExt ;
24
24
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 } ;
26
26
use mm2_core:: mm_ctx:: { from_ctx, MmArc } ;
27
27
use mm2_err_handle:: prelude:: * ;
28
28
use pairing_api:: PairingClient ;
@@ -109,7 +109,7 @@ impl WalletConnectCtx {
109
109
|r, h| abortable_system. weak_spawner ( ) . spawn ( client_event_loop ( r, h) ) ,
110
110
) ;
111
111
112
- let inner = Arc :: new ( WalletConnectCtxImpl {
112
+ let context = Arc :: new ( WalletConnectCtxImpl {
113
113
client,
114
114
pairing,
115
115
relay,
@@ -121,22 +121,23 @@ impl WalletConnectCtx {
121
121
} ) ;
122
122
123
123
// Connect to relayer client and spawn a watcher loop for disconnection.
124
- let inner_clone = inner. clone ( ) ;
125
- inner
124
+ context
126
125
. abortable_system
127
126
. weak_spawner ( )
128
- . spawn ( inner_clone . spawn_connection_initialization ( conn_live_receiver) ) ;
127
+ . spawn ( context . clone ( ) . spawn_connection_initialization ( conn_live_receiver) ) ;
129
128
// 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
+ }
135
136
}
136
137
}
137
138
} ) ;
138
139
139
- Ok ( Self ( inner ) )
140
+ Ok ( Self ( context ) )
140
141
}
141
142
142
143
pub fn from_ctx ( ctx : & MmArc ) -> MmResult < Arc < WalletConnectCtx > , WalletConnectError > {
@@ -149,7 +150,7 @@ impl WalletConnectCtx {
149
150
150
151
impl WalletConnectCtxImpl {
151
152
/// 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 .
153
154
/// After successful connection, attempts to restore previous session state from storage.
154
155
pub ( crate ) async fn spawn_connection_initialization (
155
156
self : Arc < Self > ,
@@ -159,6 +160,7 @@ impl WalletConnectCtxImpl {
159
160
let mut retry_count = 0 ;
160
161
let mut retry_secs = 1 ;
161
162
163
+ // Connect to WalletConnect relay client(retry until successful) before proceeeding with other initializations.
162
164
while let Err ( err) = self . connect_client ( ) . await {
163
165
retry_count += 1 ;
164
166
error ! (
@@ -190,7 +192,7 @@ impl WalletConnectCtxImpl {
190
192
let key = SigningKey :: generate ( & mut rand:: thread_rng ( ) ) ;
191
193
AuthToken :: new ( AUTH_TOKEN_SUB )
192
194
. aud ( RELAY_ADDRESS )
193
- . ttl ( Duration :: from_secs ( 5 * 60 * 60 ) )
195
+ . ttl ( AUTH_TOKEN_DURATION )
194
196
. as_jwt ( & key)
195
197
. map_to_mm ( |err| WalletConnectError :: InternalError ( err. to_string ( ) ) ) ?
196
198
} ;
0 commit comments