Skip to content

Commit

Permalink
refactoring getVestingEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
djeck1432 committed Sep 23, 2024
1 parent d57651f commit f409902
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions backend/src/starknet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ export const getVestingEvents = async (contract: string, address: string): Promi
} else if (isVested) {
acc.push({
amount: amount,
is_claimable: false,
claimable_at: timestamp,
is_claimable: false,
is_claimed: true,
});
}
Expand All @@ -76,16 +76,20 @@ export const getVestingEvents = async (contract: string, address: string): Promi
return acc;
}, []);

// Filter out isVestingMilestone if it has a corresponding isVested event with the same claimable_at timestamp
const filteredEvents = events.filter((event, index, self) => {
if (event.is_claimable) {
const matchingVested = self.find(e => e.is_claimed && e.claimable_at === event.claimable_at);
return !matchingVested;
}
return true;
});
// Create a set of claimable_at values from vested events
const vestedClaimableAts = new Set(
events.filter(e => e.is_claimed).map(e => e.claimable_at)
);

// Filter events, removing is_claimable if there's a matching vested event with the same claimable_at
const filteredEvents = events.filter(event =>
!event.is_claimable || !vestedClaimableAts.has(event.claimable_at)
);

// Sort the filtered events by claimable_at in ascending order
const sortedEvents = filteredEvents.sort((a, b) => (a.claimable_at || 0) - (b.claimable_at || 0));

return filteredEvents;
return sortedEvents;

} catch (error) {
console.error('Error in getVestingEvents:', error);
Expand Down

0 comments on commit f409902

Please sign in to comment.