Skip to content

Commit

Permalink
remove IsVestingMilestones if it is vested
Browse files Browse the repository at this point in the history
  • Loading branch information
djeck1432 committed Sep 23, 2024
1 parent 2a46b2e commit d57651f
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions backend/src/starknet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const getVestingEvents = async (contract: string, address: string): Promi
const vesting_milestone_add_selector = hash.getSelectorFromName('VestingMilestoneAdded');
const vested_selector = hash.getSelectorFromName('Vested');

const rawEvents = await getRawVestingEvents(contract, provider, START_BLOCK)
const rawEvents = await getRawVestingEvents(contract, provider, START_BLOCK);

try {
const events = rawEvents.reduce((acc: VestingEvent[], event: any) => {
Expand Down Expand Up @@ -63,18 +63,30 @@ export const getVestingEvents = async (contract: string, address: string): Promi
acc.push({
amount: amount,
is_claimable: false,
claimable_at: null,
claimable_at: timestamp,
is_claimed: true,
});
}
}

} catch (error) {
console.error('Error processing event, skipping this event:', error);
}

return acc;
}, []);

return events;
// 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;
});

return filteredEvents;

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

Expand All @@ -86,6 +98,7 @@ export const getVestingEvents = async (contract: string, address: string): Promi
}
};


export const getStarknetId = async (
address: string
): Promise<string | null> => {
Expand Down

0 comments on commit d57651f

Please sign in to comment.