diff --git a/frontend/src/components/staking/StakeList.tsx b/frontend/src/components/staking/StakeList.tsx index a56af8ad..dcb45183 100644 --- a/frontend/src/components/staking/StakeList.tsx +++ b/frontend/src/components/staking/StakeList.tsx @@ -1,6 +1,10 @@ import React from 'react'; import { useStakes } from '../../lib/staking/useStakes'; +import { useAccount, useContract } from '@starknet-react/core'; import { formatBalance } from "../../lib/erc20"; +import { CONTRACT_ADDR } from '../../lib/config'; +import toast from 'react-hot-toast'; +import { abi } from "../../lib/abi"; interface StakeListProps { address: string | undefined; @@ -9,22 +13,52 @@ interface StakeListProps { const StakeList: React.FC = ({ address }) => { const { stakes, isLoading, error } = useStakes(address); + const { contract } = useContract({ + address: CONTRACT_ADDR, + abi, + }); + + const { account } = useAccount(); + + + + if (isLoading) return
Loading stakes...
; if (error) return
Error: {error.message}
; if (!stakes.length) return
No stakes found.
; - const formatExpirationStatus = (startDate: bigint, length: bigint) => { - const startTimestamp = Number(startDate) * 1000; // Convert to milliseconds + const formatExpirationStatus = (startDate: bigint, length: bigint, stakeId: number) => { + const startTimestamp = Number(startDate) * 1000; const expirationTimestamp = startTimestamp + (Number(length) * 1000); const now = Date.now(); if (now > expirationTimestamp) { - return `Expired on ${new Date(expirationTimestamp).toLocaleDateString()}`; + return ( +
+ Expired on {new Date(expirationTimestamp).toLocaleDateString()} + +
+ ); } else { return `Expires on ${new Date(expirationTimestamp).toLocaleDateString()}`; } }; + const handleUnstake = async (stakeId: number) => { + try { + await account.execute([{ contractAddress: contract.address, entrypoint: 'unstake', calldata: [stakeId] }], [abi]) + toast.success('Unstake successful'); + } catch (error) { + console.error('Unstake error:', error); + toast.error('Failed to unstake'); + } + }; + return (

Your Stakes

@@ -43,7 +77,7 @@ const StakeList: React.FC = ({ address }) => { {stake.id} {formatBalance(stake.amount_staked)} KONOHA {formatBalance(stake.amount_voting_token)} veKONOHA - {formatExpirationStatus(stake.start_date, stake.length)} + {formatExpirationStatus(stake.start_date, stake.length, stake.id)} ))}