Skip to content

Commit

Permalink
add new logic
Browse files Browse the repository at this point in the history
  • Loading branch information
djeck1432 committed Sep 12, 2024
1 parent 01eabb6 commit 9c0840d
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions backend/src/starknet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const starknetIdNavigator = new StarknetIdNavigator(
const cache = new Map<string, any>();

export const getVestingEvents = async (address: string) => {
const vesting_milestone_add_selector = hash.getSelectorFromName('VestingMilestoneAdded')
const vested_selector = hash.getSelectorFromName('Vested')

// Check if the result is already cached
if (cache.has(address)) {
Expand All @@ -34,7 +36,7 @@ export const getVestingEvents = async (address: string) => {
from_block: { block_number: START_BLOCK },
chunk_size: 100,
address: address,
keys: [[hash.getSelectorFromName('Vesting')]],
keys: [[hash.getSelectorFromName('VestingEvent')]],
};

const events = await provider.getEvents(eventFilter);
Expand All @@ -50,17 +52,23 @@ export const getVestingEvents = async (address: string) => {
const timestamp = parseInt(event.data[1]); // Timestamp (index 1)
const amount = parseInt(event.data[2]); // Amount (index 2)

if (timestamp < now && amount) {
if (timestamp < now && event.keys.includes(vesting_milestone_add_selector)) {
acc.push({
amount: amount,
timestamp: timestamp,
is_claimable: true,
is_claimed: false,
});
} else if (event.keys.includes(vested_selector)) {
acc.push({
amount: amount,
is_claimable: false,
is_claimed: true,
});
} else {
acc.push({
timestamp: timestamp,
amount: amount,
is_claimable: false,
is_claimed: false,
});
}
} catch (error) {
Expand Down

0 comments on commit 9c0840d

Please sign in to comment.