diff --git a/frontend/src/components/VestingTable.tsx b/frontend/src/components/VestingTable.tsx index cc634a58..552dd9c4 100644 --- a/frontend/src/components/VestingTable.tsx +++ b/frontend/src/components/VestingTable.tsx @@ -1,9 +1,10 @@ import React, { useState } from 'react'; import { CONTRACT_ADDR } from '../lib/config'; import axios from 'axios'; -import { useAccount } from '@starknet-react/core'; +import { useAccount, useContractWrite } from '@starknet-react/core'; import { useQuery } from '@tanstack/react-query'; import { BASE_API_URL } from "../lib/config"; +import { toast } from 'react-hot-toast'; interface VestingEvent { amount: number; @@ -12,11 +13,35 @@ interface VestingEvent { is_claimed: boolean; } -const ITEMS_PER_PAGE = 10; // Items per page +const ITEMS_PER_PAGE = 10; const VestingTable: React.FC = () => { const { address } = useAccount(); - const [currentPage, setCurrentPage] = useState(1); // Track the current page + const [currentPage, setCurrentPage] = useState(1); + + const { writeAsync } = useContractWrite({ calls: [] }); + + const handleClaim = async (vestedTimestamp: number) => { + if (!address) { + toast.error('Please connect your wallet'); + return; + } + + const calls = [{ + contractAddress: CONTRACT_ADDR, + entrypoint: 'vest', + calldata: [address, vestedTimestamp.toString()], + }]; + + try { + await writeAsync({ calls }); + toast.success('Vesting claimed successfully'); + // Optionally, refetch the vesting events here + } catch (error) { + toast.error('Failed to claim vesting'); + console.error(error); + } + }; const { data: events = [], isLoading, error } = useQuery({ queryKey: ['vesting-events', address], @@ -63,30 +88,38 @@ const VestingTable: React.FC = () => { return (
- {/* Title */}

Vesting Milestones

- - {/* Table */} - - - - - - + + + + + - {paginatedEvents.map((event: VestingEvent, index: number) => ( - - - - - - - ))} + {paginatedEvents.map((event: VestingEvent, index: number) => ( + + + + + + ))}
AmountClaimable AtIs ClaimableIs Claimed
AmountClaimable AtStatus
{event.amount} - {event.claimable_at ? new Date(event.claimable_at * 1000).toLocaleString() : 'N/A'} - {event.is_claimable ? 'Yes' : 'No'}{event.is_claimed ? 'Yes' : 'No'}
{event.amount} + {event.claimable_at ? new Date(event.claimable_at * 1000).toLocaleString() : 'N/A'} + + {event.is_claimed ? ( + 'Claimed' + ) : event.is_claimable ? ( + + ) : ( + 'Not Claimable' + )} +
@@ -102,8 +135,8 @@ const VestingTable: React.FC = () => { - Page {currentPage} of {totalPages} - + Page {currentPage} of {totalPages} +