11import React , { useState , useEffect , useRef , useCallback } from 'react' ;
22import pLimit from 'p-limit' ;
3- import { useGetEscrowFromIndexerByContractIds } from '@trustless-work/escrow/hooks' ;
4- import type {
5- GetEscrowFromIndexerByContractIdsParams ,
6- MultiReleaseEscrow ,
7- } from '@trustless-work/escrow' ;
83// Import Hackathon types
94import {
105 getJudgingSubmissions ,
116 getHackathon ,
7+ getHackathonEscrow ,
128 type Hackathon ,
139 type HackathonEscrowData ,
1410} from '@/lib/api/hackathons' ;
@@ -24,37 +20,6 @@ import { PrizeTier } from '@/components/organization/hackathons/new/tabs/schemas
2420import { toast } from 'sonner' ;
2521import { reportError } from '@/lib/error-reporting' ;
2622
27- const mapEscrowToHackathonEscrowData = (
28- escrowData : MultiReleaseEscrow
29- ) : HackathonEscrowData => {
30- const isFunded = ( escrowData . balance || 0 ) > 0 ;
31- const canUpdate = isFunded ;
32-
33- return {
34- contractId : escrowData . contractId || '' ,
35- escrowAddress : escrowData . contractId || '' ,
36- balance : escrowData . balance || 0 ,
37- milestones :
38- escrowData . milestones ?. map ( milestone => ( {
39- description : milestone . description || '' ,
40- amount : milestone . amount || 0 ,
41- receiver : milestone . receiver || '' ,
42- status : milestone . status || 'pending' ,
43- evidence : milestone . evidence || '' ,
44- flags : milestone . flags
45- ? {
46- approved : milestone . flags . approved || false ,
47- disputed : milestone . flags . disputed || false ,
48- released : milestone . flags . released || false ,
49- resolved : milestone . flags . resolved || false ,
50- }
51- : undefined ,
52- } ) ) || [ ] ,
53- isFunded,
54- canUpdate,
55- } ;
56- } ;
57-
5823const getOrdinalSuffix = ( i : number ) => {
5924 const j = i % 10 ,
6025 k = i % 100 ;
@@ -117,8 +82,6 @@ export const useHackathonRewards = (
11782 organizationId : string ,
11883 hackathonId : string
11984) : UseHackathonRewardsReturn => {
120- const { getEscrowByContractIds } = useGetEscrowFromIndexerByContractIds ( ) ;
121-
12285 const [ submissions , setSubmissions ] = useState < Submission [ ] > ( [ ] ) ;
12386 const [ escrow , setEscrow ] = useState < HackathonEscrowData | null > ( null ) ;
12487 const [ prizeTiers , setPrizeTiers ] = useState < PrizeTier [ ] > ( [ ] ) ;
@@ -146,29 +109,10 @@ export const useHackathonRewards = (
146109 setIsLoadingEscrow ( true ) ;
147110
148111 try {
149- const params : GetEscrowFromIndexerByContractIdsParams = {
150- contractIds : [ contractIdToFetch ] ,
151- } ;
152-
153- const response = await getEscrowByContractIds ( params ) ;
154-
155- let escrows : MultiReleaseEscrow [ ] = [ ] ;
156-
157- if ( Array . isArray ( response ) ) {
158- escrows = response as MultiReleaseEscrow [ ] ;
159- } else if (
160- response &&
161- typeof response === 'object' &&
162- 'escrows' in response
163- ) {
164- escrows =
165- ( response as { escrows : MultiReleaseEscrow [ ] } ) . escrows || [ ] ;
166- }
112+ const response = await getHackathonEscrow ( organizationId , hackathonId ) ;
167113
168- if ( escrows . length > 0 ) {
169- const escrowData = escrows [ 0 ] as MultiReleaseEscrow ;
170- const mappedEscrow = mapEscrowToHackathonEscrowData ( escrowData ) ;
171- setEscrow ( mappedEscrow ) ;
114+ if ( response . success && response . data ) {
115+ setEscrow ( response . data ) ;
172116 } else {
173117 setEscrow ( null ) ;
174118 }
@@ -180,7 +124,7 @@ export const useHackathonRewards = (
180124 isFetchingEscrowRef . current = false ;
181125 }
182126 } ,
183- [ getEscrowByContractIds ]
127+ [ organizationId , hackathonId ]
184128 ) ;
185129
186130 const refreshEscrow = useCallback ( async ( ) => {
0 commit comments