@@ -275,13 +275,10 @@ impl Contract {
275
275
claims_ids. len( )
276
276
) ) ;
277
277
278
- let mut expired_claim_ids = Vec :: new ( ) ;
279
-
280
278
for claim_id in claims_ids. iter ( ) . take ( MAX_CLAIMS_PER_BATCH ) . cloned ( ) {
281
279
if let Some ( claim) = self . claims_by_id . get ( & claim_id) {
282
280
if claim. is_expired ( ) {
283
281
// Track expired claims for removal
284
- expired_claim_ids. push ( claim_id) ;
285
282
// claims_vector.remove(claim);
286
283
continue ;
287
284
}
@@ -353,11 +350,6 @@ impl Contract {
353
350
} ;
354
351
}
355
352
}
356
- if !expired_claim_ids. is_empty ( ) {
357
- for claim_id in expired_claim_ids {
358
- claims_ids. remove ( & claim_id) ;
359
- }
360
- }
361
353
} else {
362
354
env:: log_str ( "No pending claims found for this handle" ) ;
363
355
}
@@ -386,34 +378,24 @@ impl Contract {
386
378
social_handle. handle
387
379
) ) ;
388
380
} else if let Some ( claim) = self . claims_by_id . get_mut ( & claim_id) {
389
- if let Some ( claim_ids) = self . handle_claims . get_mut ( & social_handle. to_string ( ) ) {
390
- claim_ids. remove ( & claim_id) ;
391
- if claim_ids. is_empty ( ) {
392
- self . handle_claims . remove ( & social_handle. to_string ( ) ) ;
393
- env:: log_str ( & format ! (
394
- "All claims processed for {:?}:{:?}" ,
395
- social_handle. platform, social_handle. handle
396
- ) ) ;
397
- }
398
- // TODO: maybe merge this two events into one? since they emit same params?
399
- if reclaim_trf. is_some ( ) {
400
- log_tip_reclaimed_event (
401
- & social_handle. platform ,
402
- & social_handle. handle ,
403
- claim. amount ( ) . into ( ) ,
404
- claim. token_type ( ) ,
405
- claim. tipper ( ) ,
406
- ) ;
407
- } else {
408
- claim. claimed = true ;
409
- log_claim_processed_event (
410
- & social_handle. platform ,
411
- & social_handle. handle ,
412
- claim. amount ( ) . into ( ) ,
413
- & token_type,
414
- & recipient,
415
- ) ;
416
- }
381
+ // TODO: maybe merge this two events into one? since they emit same params?
382
+ if reclaim_trf. is_some ( ) {
383
+ log_tip_reclaimed_event (
384
+ & social_handle. platform ,
385
+ & social_handle. handle ,
386
+ claim. amount ( ) . into ( ) ,
387
+ claim. token_type ( ) ,
388
+ claim. tipper ( ) ,
389
+ ) ;
390
+ } else {
391
+ claim. claimed = true ;
392
+ log_claim_processed_event (
393
+ & social_handle. platform ,
394
+ & social_handle. handle ,
395
+ claim. amount ( ) . into ( ) ,
396
+ & token_type,
397
+ & recipient,
398
+ ) ;
417
399
}
418
400
}
419
401
}
@@ -880,4 +862,38 @@ impl Contract {
880
862
vec ! [ ]
881
863
}
882
864
}
865
+
866
+ pub fn get_all_claims_for_handle (
867
+ & self ,
868
+ platform : String ,
869
+ handle : String ,
870
+ from_index : u64 ,
871
+ limit : u64 ,
872
+ ) -> Vec < ClaimExternal > {
873
+ let social_handle = SocialHandle :: new ( platform, handle) ;
874
+
875
+ if let Some ( claim_ids) = self . handle_claims . get ( & social_handle. to_string ( ) ) {
876
+ // First collect all claim IDs into a Vec
877
+ let claim_id_vec: Vec < ClaimId > = claim_ids. iter ( ) . cloned ( ) . collect ( ) ;
878
+
879
+ // Apply pagination
880
+ let start = from_index as usize ;
881
+ let end = std:: cmp:: min ( start + limit as usize , claim_id_vec. len ( ) ) ;
882
+
883
+ if start < end {
884
+ // Map each claim ID to its corresponding claim
885
+ claim_id_vec[ start..end]
886
+ . iter ( )
887
+ . map ( |claim_id| {
888
+ let claim = self . claims_by_id . get ( claim_id) . unwrap ( ) ; // Unwrap is safe here because we know the claim_id exists
889
+ format_claim ( claim_id, claim)
890
+ } )
891
+ . collect ( )
892
+ } else {
893
+ vec ! [ ]
894
+ }
895
+ } else {
896
+ vec ! [ ]
897
+ }
898
+ }
883
899
}
0 commit comments