@@ -5,26 +5,13 @@ import { PublicKey } from '@solana/web3.js'
55import { BN } from "@coral-xyz/anchor"
66import { ExternalLink } from 'lucide-react'
77import useTokenDecimals from '../../hooks/useTokenDecimals' ;
8+ import { AllocationCardParamsT } from '@/types' ;
89import { formatDate , compressPublicKey } from '@/app/lib/utils' ;
910import { progressPercentageCalc } from '@/app/lib/utils' ;
1011import { useWallet } from '@solana/wallet-adapter-react' ;
1112
12- interface AllocationCardParamsT {
13- ownerOfVestingAccountForGivenEmployee : string ,
14- start_time : BN ,
15- end_time : BN ,
16- cliff : number ,
17- total_allocation_amount : BN ,
18- withdrawn_amount : BN ,
19- actualTotalAllocationAmount : number ,
20- actualWithdrawnAmount : number ,
21- beneficiary : string ,
22- companyName : string ,
23- token_mint : string
24- }
25-
2613export function AllocationList ( ) {
27- const { getProgramAccount, employeeAccounts , employeeAccountsWithMetadata } = useVestingProgram ( ) ;
14+ const { getProgramAccount, employeeAccountsWithMetadata } = useVestingProgram ( ) ;
2815 const wallet = useWallet ( ) ;
2916
3017 if ( getProgramAccount . isLoading ) {
@@ -92,159 +79,6 @@ export function AllocationList(){
9279 </ div >
9380 )
9481 }
95-
96- // export function CompanyList(){
97- // const { getProgramAccount, vestingAccounts } = useVestingProgram()
98- // const [selectedCompany, setSelectedCompany] = useState<{account: string, companyName: string} | null>(null);
99-
100-
101- // // Get unique companies
102- // const uniqueCompanies = useMemo(() => {
103- // const companyMap = new Map<string, {account: string, companyName: string}>();
104- // vestingAccounts.data?.forEach((vestingAccount) => {
105- // const companyName = vestingAccount.account.companyName ?? "Unknown Company";
106- // if (!companyMap.has(companyName)) {
107- // companyMap.set(companyName, {
108- // account: vestingAccount.publicKey.toBase58(),
109- // companyName: companyName
110- // });
111- // }
112- // });
113- // return Array.from(companyMap.values());
114- // }, [vestingAccounts.data]);
115-
116- // if (getProgramAccount.isLoading) {
117- // return (
118- // <div className="flex justify-center items-center h-24">
119- // <span className="loading loading-spinner loading-lg" />
120- // </div>
121- // );
122- // }
123-
124- // if (!getProgramAccount.data?.value) {
125- // return (
126- // <div className="flex justify-center p-2">
127- // <div className="bg-blue-50 text-black px-4 py-2 rounded-lg max-w-2xl">
128- // <span>Program account not found. Make sure you have deployed the program and are on the correct cluster.</span>
129- // </div>
130- // </div>
131- // );
132- // }
133-
134- // return(
135- // <>
136- // <div className="px-4 -mt-4">
137- // <div className="max-w-7xl mx-auto rounded-xl shadow-sm p-4">
138- // <div className='flex flex-col space-y-4'>
139- // {uniqueCompanies.map((company) => (
140- // <div
141- // key={company.companyName}
142- // className="w-full bg-gray-800 hover:bg-gray-700 transition-colors duration-200 rounded-lg cursor-pointer"
143- // onClick={() => setSelectedCompany(company)}
144- // >
145- // <div className="px-6 py-4 text-white text-lg font-semibold">
146- // {company.companyName}
147- // </div>
148- // </div>
149- // ))}
150-
151- // {selectedCompany && (
152- // <div className="mt-6">
153- // <EmployeeAllocationsListForGivenCompany
154- // account={selectedCompany.account}
155- // company_name={selectedCompany.companyName}
156- // />
157- // </div>
158- // )}
159- // </div>
160- // </div>
161- // </div>
162- // </>
163- // )
164- // }
165-
166- // export function CompanyList(){
167- // const { vestingAccounts } = useVestingProgram()
168-
169- // return(
170- // <>
171- // <div className='flex-flex col'>
172- // {/* a company bars list(horizontally full screen width bars listed in vertical order showing company name ) */}
173- // {vestingAccounts.data?.map((vestingAccount) => {
174- // const company = vestingAccount.account.companyName ?? "Unknown Company";
175- // return(
176- // <>
177- // {/* company bar(on click should change open the EmployeeAllocationsListForGivenCompany component) */}
178- // </>)
179- // }) }
180- // </div>
181- // </>
182- // )
183- // }
184-
185- // export function EmployeeAllocationsListForGivenCompany({account, company_name} : {account: string, company_name: string}) {
186- // const { employeeAccounts } = useVestingProgram();
187- // const provider = useAnchorProvider()
188- // const clusterNetwork = "devnet";
189- // const program = getVestingProgram(provider)
190-
191- // // Explicitly type the state with the correct type
192- // const [filteredEmployeeAccounts, setFilteredEmployeeAccounts] = useState<ProgramAccount<{
193- // beneficiary: PublicKey;
194- // tokenAllocationAmount: BN;
195- // withdrawnAmount: BN;
196- // vestingAccount: PublicKey;
197- // startTime: BN;
198- // endTime: BN;
199- // cliff: BN;
200- // bump: number;
201- // }>[]>([]);
202-
203- // useEffect(() => {
204- // const filterEmployeeAccounts = async () => {
205- // if (!employeeAccounts.data) return;
206-
207- // const filtered = await Promise.all(
208- // employeeAccounts.data.map(async (employeeAccount) => {
209- // try {
210- // const getVestingAccountStateQuery = await program.account.vestingAccount.fetch(
211- // employeeAccount.account.vestingAccount,
212- // "confirmed"
213- // );
214-
215- // return getVestingAccountStateQuery.companyName === company_name
216- // ? employeeAccount
217- // : null;
218- // } catch (error) {
219- // console.error("Error fetching vesting account:", error);
220- // return null;
221- // }
222- // })
223- // );
224-
225- // // Remove null values and set the state
226- // setFilteredEmployeeAccounts(
227- // filtered.filter((acc) => acc !== null)
228- // );
229- // };
230-
231- // filterEmployeeAccounts();
232- // }, [company_name, employeeAccounts.data, program.account.vestingAccount]);
233-
234- // return (
235- // <div className='flex flex-col'>
236- // {filteredEmployeeAccounts.map((acc) => (
237- // <div
238- // key={acc.publicKey.toString()}
239- // className="transform transition-all duration-200 hover:scale-[1.02]"
240- // >
241- // <AllocationCard account={acc.publicKey.toBase58()} />
242- // </div>
243- // )
244- // )}
245- // </div>
246- // );
247- // }
24882
24983export function AllocationCard ( { employeeAccount, allocationCardParams} : { employeeAccount : string , allocationCardParams : AllocationCardParamsT } ) {
25084 const employee = new PublicKey ( employeeAccount ) ;
@@ -259,22 +93,10 @@ export function AllocationCard({employeeAccount, allocationCardParams} : { emplo
25993 const token_mint = allocationCardParams . token_mint ;
26094 const total_allocation_amount = allocationCardParams . total_allocation_amount ;
26195 const withdrawn_amount = allocationCardParams . withdrawn_amount ;
262- // const decimals = useTokenDecimals(tokenMint.toString())
263-
264- const actualTotalAllocationAmount = allocationCardParams . actualTotalAllocationAmount ;
265- // const actualTotalAllocationAmount = Math.floor(total_allocation_amount?.toNumber() /(10**decimals));
266- // const actualWithdrawnAmount = Math.floor(withdrawn_amount?.toNumber() /(10**decimals));
267- const actualWithdrawnAmount = allocationCardParams . actualWithdrawnAmount ;
268- const beneficiary = allocationCardParams . beneficiary ;
26996
270- // withdrawn amount progress bar
271- // const progressPercentage = useMemo(() => {
272- // const totalAllocation = parseFloat(total_allocation_amount.toString());
273- // const withdrawn = parseFloat(withdrawn_amount.toString());
274- // return totalAllocation > 0
275- // ? Math.min((withdrawn / totalAllocation) * 100, 100)
276- // : 0;
277- // }, [total_allocation_amount, withdrawn_amount]);
97+ const actualTotalAllocationAmount = allocationCardParams . actualTotalAllocationAmount ;
98+ const actualWithdrawnAmount = allocationCardParams . actualWithdrawnAmount ;
99+ const beneficiary = allocationCardParams . beneficiary ;
278100 const progressPercentage = progressPercentageCalc ( total_allocation_amount , withdrawn_amount )
279101
280102 const isClaimExpired = ( Date . now ( ) / 1000 ) > endTime . toNumber ( ) ;
@@ -290,7 +112,7 @@ export function AllocationCard({employeeAccount, allocationCardParams} : { emplo
290112 Token allocation for{ ' ' }
291113 < span className = 'ml-2 text-medium text-teal-400 z-40' > { compressPublicKey ( beneficiary || 'yoben....' ) } </ span >
292114 < a
293- href = { beneficiary ? `https://solscan.io/address/${ beneficiary } ?cluster=devnet ` : '#' }
115+ href = { beneficiary ? `https://solscan.io/address/${ beneficiary } ` : '#' }
294116 target = "_blank"
295117 rel = "noopener noreferrer"
296118 className = "ml-2 z-40"
@@ -343,7 +165,7 @@ export function AllocationCard({employeeAccount, allocationCardParams} : { emplo
343165 { compressPublicKey ( token_mint ) }
344166 </ p >
345167 < a
346- href = { `https://solscan.io/token/${ token_mint } ?cluster=devnet ` }
168+ href = { `https://solscan.io/token/${ token_mint } ` }
347169 target = "_blank"
348170 rel = "noopener noreferrer"
349171 className = "text-blue-500 hover:text-blue-700 z-20"
0 commit comments