@@ -360,11 +360,47 @@ impl GatewayServer {
360360
361361 let formatted_time_left = get_time_left_day_formatted ( ) ;
362362
363- HttpResponse :: Ok ( ) . json ( AppResponse :: new_sucessfull ( serde_json:: json!( {
364- "proofs_submitted" : daily_tasks_by_address,
365- "quota_limit" : state. config. max_daily_proofs_per_user,
366- "quota_remaining" : ( state. config. max_daily_proofs_per_user - daily_tasks_by_address) ,
367- "quota_resets_in" : formatted_time_left. as_str( )
368- } ) ) )
363+ let now_epoch = match SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) {
364+ Ok ( duration) => duration. as_secs ( ) ,
365+ Err ( _) => {
366+ return HttpResponse :: InternalServerError ( )
367+ . json ( AppResponse :: new_unsucessfull ( "Internal server error" , 500 ) ) ;
368+ }
369+ } ;
370+
371+ let has_payment = match state
372+ . db
373+ . has_active_payment_event (
374+ & address,
375+ // safe unwrap the number comes from a valid u64 primitive
376+ BigDecimal :: from_str ( & now_epoch. to_string ( ) ) . unwrap ( ) ,
377+ )
378+ . await
379+ {
380+ Ok ( result) => result,
381+ Err ( _) => {
382+ return HttpResponse :: InternalServerError ( )
383+ . json ( AppResponse :: new_unsucessfull ( "Internal server error" , 500 ) ) ;
384+ }
385+ } ;
386+
387+ if has_payment {
388+ HttpResponse :: Ok ( ) . json ( AppResponse :: new_sucessfull ( serde_json:: json!( {
389+ "proofs_submitted" : daily_tasks_by_address,
390+ "quota_limit" : state. config. max_daily_proofs_per_user,
391+ "quota_remaining" : ( state. config. max_daily_proofs_per_user - daily_tasks_by_address) ,
392+ "quota_resets_in" : formatted_time_left. as_str( )
393+ } ) ) )
394+ } else {
395+ HttpResponse :: Ok ( ) . json ( AppResponse :: new_sucessfull_with_message (
396+ serde_json:: json!( {
397+ "proofs_submitted" : 0 ,
398+ "quota_limit" : 0 ,
399+ "quota_remaining" : 0 ,
400+ "quota_resets_in" : formatted_time_left. as_str( )
401+ } ) ,
402+ "You have to pay before submitting a proof" . to_string ( ) ,
403+ ) )
404+ }
369405 }
370406}
0 commit comments