@@ -5,6 +5,7 @@ use reqwest::{Client, Response};
55use serde_json:: json;
66use solana_client:: rpc_client:: RpcClient ;
77use solana_sdk:: pubkey:: Pubkey ;
8+ use std:: sync:: atomic:: { Ordering } ;
89use std:: thread;
910use std:: time:: { Duration , Instant } ;
1011
@@ -13,6 +14,7 @@ use crate::api::models::{
1314 VerifyResponse ,
1415} ;
1516use crate :: solana_program:: get_program_pda;
17+ use crate :: SIGNAL_RECEIVED ;
1618use crate :: { get_genesis_hash, MAINNET_GENESIS_HASH } ;
1719
1820// URL for the remote server
@@ -27,8 +29,16 @@ fn loading_animation(receiver: Receiver<bool>) {
2729
2830 let pb = ProgressBar :: new_spinner ( ) ;
2931 pb. set_style ( spinner_style) ;
32+ pb. enable_steady_tick ( Duration :: from_millis ( 100 ) ) ;
3033 pb. set_message ( "Request sent. Awaiting server response. This may take a moment... ⏳" ) ;
34+
3135 loop {
36+ // Check if interrupt signal was received
37+ if SIGNAL_RECEIVED . load ( Ordering :: Relaxed ) {
38+ pb. finish_with_message ( "❌ Operation interrupted by user." ) ;
39+ break ;
40+ }
41+
3242 match receiver. try_recv ( ) {
3343 Ok ( result) => {
3444 if result {
@@ -42,13 +52,16 @@ fn loading_animation(receiver: Receiver<bool>) {
4252 }
4353 break ;
4454 }
45-
4655 Err ( _) => {
47- pb. inc ( 1 ) ;
48- thread:: sleep ( Duration :: from_millis ( 100 ) ) ;
56+ if SIGNAL_RECEIVED . load ( Ordering :: Relaxed ) {
57+ pb. finish_with_message ( "❌ Operation interrupted by user." ) ;
58+ break ;
59+ }
60+ thread:: sleep ( Duration :: from_millis ( 10 ) ) ;
4961 }
5062 }
5163 }
64+ pb. abandon ( ) ; // Ensure the progress bar is cleaned up
5265}
5366
5467fn print_verification_status (
@@ -163,16 +176,28 @@ pub async fn handle_submission_response(
163176 let request_id = status_response. request_id ;
164177 println ! ( "Verification request sent with request id: {}" , request_id) ;
165178 println ! ( "Verification in progress... ⏳" ) ;
179+
166180 // Span new thread for polling the server for status
167181 // Create a channel for communication between threads
168182 let ( sender, receiver) = unbounded ( ) ;
169-
170183 let handle = thread:: spawn ( move || loading_animation ( receiver) ) ;
171- // Poll the server for status
184+
172185 loop {
186+ // Check for interrupt signal before polling
187+ if SIGNAL_RECEIVED . load ( Ordering :: Relaxed ) {
188+ let _ = sender. send ( false ) ;
189+ handle. join ( ) . unwrap ( ) ;
190+ break ; // Exit the loop and continue with normal error handling
191+ }
192+
173193 let status = check_job_status ( & client, & request_id) . await ?;
174194 match status. status {
175195 JobStatus :: InProgress => {
196+ if SIGNAL_RECEIVED . load ( Ordering :: Relaxed ) {
197+ let _ = sender. send ( false ) ;
198+ handle. join ( ) . unwrap ( ) ;
199+ break ;
200+ }
176201 thread:: sleep ( Duration :: from_secs ( 10 ) ) ;
177202 }
178203 JobStatus :: Completed => {
@@ -197,7 +222,6 @@ pub async fn handle_submission_response(
197222 }
198223 JobStatus :: Failed => {
199224 let _ = sender. send ( false ) ;
200-
201225 handle. join ( ) . unwrap ( ) ;
202226 let status_response: JobVerificationResponse = status. respose . unwrap ( ) ;
203227 println ! ( "Program {} has not been verified. ❌" , program_id) ;
0 commit comments