Skip to content

Commit 160188b

Browse files
committed
fix: updated Escrow Balance Fetching
1 parent 41eb991 commit 160188b

3 files changed

Lines changed: 7 additions & 63 deletions

File tree

hooks/use-hackathon-rewards.ts

Lines changed: 5 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
import React, { useState, useEffect, useRef, useCallback } from 'react';
22
import 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
94
import {
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
2420
import { toast } from 'sonner';
2521
import { 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-
5823
const 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 () => {

lib/api/hackathons.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1611,7 +1611,7 @@ export const getHackathonEscrow = async (
16111611
hackathonId: string
16121612
): Promise<GetHackathonEscrowResponse> => {
16131613
const res = await api.get(
1614-
`/organizations/${organizationId}/hackathons/${hackathonId}/escrow`
1614+
`/organizations/${organizationId}/hackathons/${hackathonId}/rewards/escrow`
16151615
);
16161616
return res.data;
16171617
};

lib/api/hackathons/rewards.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export const getHackathonEscrow = async (
181181
hackathonId: string
182182
): Promise<GetHackathonEscrowResponse> => {
183183
const res = await api.get(
184-
`/organizations/${organizationId}/hackathons/${hackathonId}/escrow`
184+
`/organizations/${organizationId}/hackathons/${hackathonId}/rewards/escrow`
185185
);
186186
return res.data;
187187
};

0 commit comments

Comments
 (0)