@@ -12,10 +12,6 @@ const ApiChainConfigSchema = z.object({
12
12
default_fee : z . number ( ) ,
13
13
} ) ;
14
14
15
- type ApiChainConfig = z . infer < typeof ApiChainConfigSchema > ;
16
-
17
- const entropyDeploymentsSchema = z . array ( ApiChainConfigSchema ) ;
18
-
19
15
export type EntropyDeployment = {
20
16
address : string ;
21
17
delay : string ;
@@ -26,13 +22,11 @@ export type EntropyDeployment = {
26
22
nativeCurrency ?: string ;
27
23
} ;
28
24
29
- const getChainData = ( network_id : number ) => {
25
+ function getChainData ( network_id : number ) {
30
26
return Object . values ( chains ) . find ( ( chain ) => chain . id === network_id ) ;
31
- } ;
27
+ }
32
28
33
- const transformChainData = (
34
- chain : ApiChainConfig ,
35
- ) : [ string , EntropyDeployment ] => {
29
+ const apiChainConfigToEntrySchema = ApiChainConfigSchema . transform ( ( chain ) => {
36
30
const viemChainData = getChainData ( chain . network_id ) ;
37
31
38
32
const configOverride = EntropyDeploymentsConfig [ chain . network_id ] ;
@@ -55,18 +49,15 @@ const transformChainData = (
55
49
...( nativeCurrency ? { nativeCurrency } : { } ) ,
56
50
} ;
57
51
58
- return [ chain . name , deployment ] ;
59
- } ;
52
+ return [ chain . name , deployment ] as const ;
53
+ } ) ;
60
54
61
- export const fetchEntropyDeployments = async (
62
- url : string ,
63
- ) : Promise < Record < string , EntropyDeployment > > => {
64
- try {
65
- const response = await fetch ( url ) ;
66
- const apiData = entropyDeploymentsSchema . parse ( await response . json ( ) ) ;
55
+ const entropyDeploymentsSchema = z . array ( apiChainConfigToEntrySchema ) ;
67
56
68
- return Object . fromEntries ( apiData . map ( ( item ) => transformChainData ( item ) ) ) ;
69
- } catch ( error_ ) {
70
- throw new Error ( String ( error_ ) ) ;
71
- }
72
- } ;
57
+ export async function fetchEntropyDeployments (
58
+ url : string ,
59
+ ) : Promise < Record < string , EntropyDeployment > > {
60
+ const response = await fetch ( url ) ;
61
+ const entries = entropyDeploymentsSchema . parse ( await response . json ( ) ) ;
62
+ return Object . fromEntries ( entries ) ;
63
+ }
0 commit comments