14
14
* limitations under the License.
15
15
*/
16
16
17
+ import { waitForTransaction } from '@wagmi/core' ;
18
+
17
19
import { PAGE_SIZE } from '@/constants/config' ;
20
+ import { contracts , payTokens } from '@/constants/contract' ;
18
21
import { isInteger , merge } from '@/utils' ;
22
+ import { createContractActions } from '@/utils/contract' ;
19
23
import httpClient from '@/utils/http' ;
24
+ import { parseTokenUnits } from '@/utils/web3' ;
25
+
26
+ import bountyAbi from './helper/abi' ;
27
+
28
+ const { writeActions : { createTask, withdraw : withdrawFromAbi } } = createContractActions ( bountyAbi ) ;
20
29
21
30
function resolveSkipped ( page , size = PAGE_SIZE ) {
22
31
let resolved = Number ( page ) ;
@@ -28,7 +37,7 @@ function resolveSkipped(page, size = PAGE_SIZE) {
28
37
return ( resolved - 1 ) * size ;
29
38
}
30
39
31
- async function fetchList ( params = { } ) {
40
+ async function fetchList ( params = { } as any ) {
32
41
const { page = 1 , sort, ...others } = params ;
33
42
34
43
return httpClient . get ( '/build/general/bounties' , {
@@ -59,13 +68,13 @@ async function fetchBuilderListForCreator(id, params) {
59
68
return httpClient . get ( `/build/creator/bounties/${ id } /builders` , { params } ) ;
60
69
}
61
70
62
- async function fetchPublishedBountyList ( params = { } ) {
71
+ async function fetchPublishedBountyList ( params = { } as any ) {
63
72
const { userId, ...others } = params ;
64
73
65
74
return fetchList ( { ...others , team_uid : userId } ) ;
66
75
}
67
76
68
- async function fetchAppliedBountyList ( params = { } ) {
77
+ async function fetchAppliedBountyList ( params = { } as any ) {
69
78
const { userId, sort, ...others } = params ;
70
79
71
80
return httpClient . get ( `/build/dashboard/bounties/public/${ userId } ` , {
@@ -77,9 +86,25 @@ async function requestTermination(id, data) {
77
86
return httpClient . post ( `/build/creator/bounties/${ id } /status/termination/propose` , data ) ;
78
87
}
79
88
89
+ async function withdraw ( walletClient , chainId , taskId , amount , deadline , signature ) {
90
+ try {
91
+ const { hash } = await withdrawFromAbi ( contracts [ chainId ] . bounty , [
92
+ taskId ,
93
+ parseTokenUnits ( amount . toString ( ) , payTokens [ chainId ] . usdt . decimals ) . toBigInt ( ) ,
94
+ deadline ,
95
+ signature ,
96
+ ] ) ;
97
+ const wait = await waitForTransaction ( { hash } ) ;
98
+ return { hash, wait } ;
99
+ } catch {
100
+ return { hash : 'error' , wait : null } ;
101
+ }
102
+ }
103
+
80
104
export {
81
105
fetchList , fetchOne , applyOne ,
82
106
fetchActivityList , fetchBuilderList , fetchBuilderListForCreator ,
83
107
fetchPublishedBountyList , fetchAppliedBountyList ,
84
108
requestTermination ,
109
+ createTask , withdraw ,
85
110
} ;
0 commit comments