@@ -4,9 +4,25 @@ import { useCallback } from "react";
4
4
import { useQuery } from "react-query" ;
5
5
import useAuthentication from "./useAuthentication" ;
6
6
7
+ const solcURL = "https://solc-bin.ethereum.org/bin/" ;
8
+
9
+ interface VersionList {
10
+ builds : {
11
+ path : string ;
12
+ version : string ;
13
+ longVersion : string ;
14
+ build : string ;
15
+ } [ ] ;
16
+ }
17
+
7
18
export function useContract ( { page } : { page : number } ) {
8
19
const { accessToken } = useAuthentication ( ) ;
9
20
21
+ const solidityVersions = useQuery ( [ "solidity" , "versions" ] , async ( ) => {
22
+ const { data } = await axios . get < VersionList > ( solcURL + "list.json" ) ;
23
+ return data ;
24
+ } ) ;
25
+
10
26
const result = useQuery ( [ "contracts" , page ] , async ( ) => {
11
27
const analyticsService = new ContractService ( {
12
28
client : axios ,
@@ -55,20 +71,42 @@ export function useContract({ page }: { page: number }) {
55
71
56
72
const getContract = useCallback (
57
73
async ( address : string ) => {
58
- const analyticsService = new ContractService ( {
74
+ const contractService = new ContractService ( {
59
75
client : axios ,
60
76
baseUrl : process . env . NEXT_PUBLIC_CONTRACT_API_ENDPOINT ! ,
61
77
} ) ;
62
- const response = await analyticsService . getContract ( address ) ;
78
+ const response = await contractService . getContract ( address ) ;
63
79
return response ;
64
80
} ,
65
81
[ accessToken ]
66
82
) ;
67
83
84
+ const compile = useCallback (
85
+ async (
86
+ source : string ,
87
+ compiler : string | undefined ,
88
+ contractName : string
89
+ ) => {
90
+ const contractService = new ContractService ( {
91
+ client : axios ,
92
+ baseUrl : process . env . NEXT_PUBLIC_CONTRACT_API_ENDPOINT ! ,
93
+ } ) ;
94
+ const response = await contractService . compile (
95
+ source ,
96
+ compiler ,
97
+ contractName
98
+ ) ;
99
+ return response ;
100
+ } ,
101
+ [ ]
102
+ ) ;
103
+
68
104
return {
69
105
contracts : result ,
106
+ solidityVersions,
70
107
search,
71
108
update,
72
109
getContract,
110
+ compile,
73
111
} ;
74
112
}
0 commit comments