Skip to content

Commit 5e1bba1

Browse files
authored
Merge branch 'openbuildxyz:test' into test
2 parents bfc8a9e + 7aabad1 commit 5e1bba1

File tree

8 files changed

+89
-57
lines changed

8 files changed

+89
-57
lines changed

src/app/bounties/[id]/Employers.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ import { Button } from '@/components/Button';
2828
import { CertifiedIcon } from '@/components/Icons';
2929
// WarningIcon
3030
import { ArrowTopRightOnSquareIcon } from '@/components/Icons';
31+
import useListFetcher from '@/hooks/useListFetcher';
3132

3233
import { useAuthGuard } from '#/domain/auth/hooks';
3334
import { isBountyApplied } from '#/domain/bounty/helper';
35+
import { fetchBuilderList } from '#/domain/bounty/repository';
3436
import CompleteProfileDialogWidget from '#/domain/profile/widgets/complete-profile-dialog';
35-
import { useBountyBuildersList } from '#/services/bounties/hooks';
3637
import { useMediaUrl, useUser } from '#/state/application/hooks';
3738

3839
import { revalidatePathAction } from '../../actions';
@@ -72,8 +73,7 @@ export function Employers({ id, list, data, mobile }) {
7273
const [notComplete, setNotComplete] = useState(false);
7374
const mediaUrl = useMediaUrl();
7475
const user = useUser();
75-
//const wrapBountyEnvCheck = useBountyEnvCheck();
76-
const { loading: buildersLoading, list: builderList = [], doFetch } = useBountyBuildersList(id);
76+
const { loading: buildersLoading, response, refetch } = useListFetcher(fetchBuilderList, id);
7777
const { withAuth } = useAuthGuard();
7878

7979
const apply = () => {
@@ -108,10 +108,10 @@ export function Employers({ id, list, data, mobile }) {
108108
}
109109
};
110110

111-
const currentUserApplied = !buildersLoading && builderList.some(({ builder_uid }) => builder_uid === user?.base.user_id);
111+
const currentUserApplied = !buildersLoading && (response?.data?.list || []).some(({ builder_uid }) => builder_uid === user?.base.user_id);
112112
const handleApplyDialogClose = () => {
113113
setOpenModal(false);
114-
doFetch();
114+
refetch();
115115
};
116116

117117
return (

src/app/bounties/[id]/TerminateModal.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { contracts, payTokens } from '@/constants/contract';
2525
import { currentTime } from '@/utils/date';
2626
import { parseTokenUnits, signBounty } from '@/utils/web3';
2727

28-
import { termination } from '#/services/bounties';
28+
import { requestTermination } from '#/domain/bounty/repository';
2929

3030
import { revalidatePathAction } from '../../actions';
3131

@@ -57,20 +57,20 @@ export function TerminateModal({open, close, bounty, type}) {
5757
setLoading(false);
5858
return;
5959
}
60-
const res = await termination(
60+
const res = await requestTermination(
6161
bounty.id,
62-
Number(amount) * 100,
63-
_s,
64-
type,
65-
_deadline
62+
{
63+
amount: Number(amount) * 100,
64+
sig: _s,
65+
close_type: type,
66+
deadline: _deadline,
67+
},
6668
);
6769
setLoading(false);
68-
if (res.code === 200) {
70+
if (res.success) {
6971
toast.success('Termination successful');
7072
close();
7173
revalidatePathAction();
72-
} else {
73-
toast.error(res.message);
7474
}
7575
};
7676

src/app/creator/build/[type]/ManageModal.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ import { currentTime, fromNow } from '@/utils/date';
3131
import { formatTime } from '@/utils/date';
3232
import { parseTokenUnits, signBounty } from '@/utils/web3';
3333

34+
import { requestTermination } from '#/domain/bounty/repository';
3435
import {
3536
getProgressList,
36-
termination,
3737
finishConfirm,
3838
finishDeny,
3939
arbitrate,
@@ -112,20 +112,19 @@ export function ManageModal({
112112
setTerminateLoading(false);
113113
return;
114114
}
115-
const res = await termination(
116-
bounty.id,
117-
Number(amount) * 100,
118-
_s,
119-
closeBounty,
120-
_deadline
115+
const res = await requestTermination(bounty.id,
116+
{
117+
amount: Number(amount) * 100,
118+
sig: _s,
119+
close_type: closeBounty,
120+
deadline: _deadline,
121+
},
121122
);
122123
setTerminateLoading(false);
123-
if (res.code === 200) {
124+
if (res.success) {
124125
toast.success('Termination successful');
125126
successCallback(18);
126127
close();
127-
} else {
128-
toast.error('Termination failed');
129128
}
130129
};
131130

src/domain/bounty/repository.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ async function fetchActivityList(id) {
5151
return httpClient.get(`/build/general/bounties/${id}/events/activities`);
5252
}
5353

54-
async function fetchBuilderList(id, params) {
54+
async function fetchBuilderList(id) {
55+
return httpClient.get(`/build/general/bounties/${id}/builders`);
56+
}
57+
58+
async function fetchBuilderListForCreator(id, params) {
5559
return httpClient.get(`/build/creator/bounties/${id}/builders`, { params });
5660
}
5761

@@ -69,8 +73,13 @@ async function fetchAppliedBountyList(params = {}) {
6973
});
7074
}
7175

76+
async function requestTermination(id, data) {
77+
return httpClient.post(`/build/creator/bounties/${id}/status/termination/propose`, data);
78+
}
79+
7280
export {
7381
fetchList, fetchOne, applyOne,
74-
fetchActivityList, fetchBuilderList,
82+
fetchActivityList, fetchBuilderList, fetchBuilderListForCreator,
7583
fetchPublishedBountyList, fetchAppliedBountyList,
84+
requestTermination,
7685
};

src/domain/bounty/widgets/process-list/AppliedModal.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ import { parseTokenUnits } from '@/utils/web3';
3333
import { approveBuilder } from '#/services/creator';
3434

3535
import { useBountyEnvCheck } from '../../hooks';
36-
import { fetchBuilderList } from '../../repository';
36+
import { fetchBuilderListForCreator } from '../../repository';
3737
import AppliedBuilderListView from '../../views/applied-builder-list';
3838

3939
function AppliedModal({ open, closeModal, bounty, revalidatePathAction }) {
40-
const { data, isLoading, mutate } = useUpToDate(fetchBuilderList, [bounty.id, { skip: 0, take: 25 }]);
40+
const { data, isLoading, mutate } = useUpToDate(fetchBuilderListForCreator, [bounty.id, { skip: 0, take: 25 }]);
4141
const { address } = useAccount();
4242
// const { chain } = useNetwork()
4343
const wrapBountyEnvCheck = useBountyEnvCheck();

src/services/bounties/hooks.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,26 +76,6 @@ export function useDetails(id) {
7676
return { data, loading };
7777
}
7878

79-
export function useBountyBuildersList(id) {
80-
const [list, setList] = useState();
81-
const [loading, setLoading] = useState(true);
82-
const fetch = useCallback(async () => {
83-
if (id) {
84-
setLoading(true);
85-
get(`ts/v1/build/general/bounties/${id}/builders`).then(result => {
86-
setList(result.data?.list || []);
87-
setLoading(false);
88-
});
89-
}
90-
}, [id]);
91-
92-
useEffect(() => {
93-
fetch();
94-
}, [fetch]);
95-
const doFetch = () => fetch();
96-
return { list, loading, doFetch };
97-
}
98-
9979
export function useBountyEvents(id) {
10080
const [list, setList] = useState();
10181
const [loading, setLoading] = useState(true);

src/services/bounties/index.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,6 @@ export async function getProgressList(id, bid) {
3131
return await get(`ts/v1/build/general/bounties/${id}/builders/${bid}/events/progress`);
3232
}
3333

34-
export async function termination(id, amount, sig, close_bounty, deadline) {
35-
return await post(`ts/v1/build/creator/bounties/${id}/status/termination/propose`, {
36-
amount,
37-
sig,
38-
close_type: close_bounty,
39-
deadline,
40-
});
41-
}
42-
4334
export async function finishConfirm(id, hash) {
4435
return await post(`ts/v1/build/creator/bounties/${id}/status/finish/confirm`, { hash });
4536
}

src/shared/hooks/useListFetcher.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* Copyright 2024 OpenBuild
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { useState, useCallback, useEffect } from 'react';
18+
19+
import type { DataValue, ResponseResult } from '../types';
20+
21+
function useListFetcher<T extends DataValue = DataValue>(
22+
request: (...args: DataValue[]) => Promise<ResponseResult<T>>,
23+
params: DataValue,
24+
): {
25+
response?: ResponseResult<T>;
26+
loading: boolean;
27+
refetch: () => Promise<ResponseResult<T>>;
28+
} {
29+
const [response, setResponse] = useState<ResponseResult<T>>();
30+
const [loading, setLoading] = useState<boolean>(false);
31+
32+
const fetchList = useCallback(async () => {
33+
setLoading(true);
34+
35+
return request(...[].concat(params))
36+
.then(res => {
37+
if (res.success) {
38+
setResponse(res);
39+
}
40+
41+
return res;
42+
})
43+
.finally(() => setLoading(false));
44+
}, [request, params]);
45+
46+
useEffect(() => {
47+
fetchList();
48+
}, [fetchList]);
49+
50+
return { response, loading, refetch: fetchList };
51+
}
52+
53+
export default useListFetcher;

0 commit comments

Comments
 (0)