File tree Expand file tree Collapse file tree 1 file changed +15
-16
lines changed
governance/xc_admin/packages/xc_admin_common/src/programs Expand file tree Collapse file tree 1 file changed +15
-16
lines changed Original file line number Diff line number Diff line change @@ -50,23 +50,22 @@ export const getConfig: Record<
50
50
51
51
/**
52
52
* Function to format the configuration for downloading as a JSON file
53
+ * Uses type narrowing to determine the correct implementation based on the config shape
53
54
*/
54
- export const getDownloadableConfig : Record <
55
- ProgramType ,
56
- ( config : ProgramConfig ) => DownloadableConfig
57
- > = {
58
- [ ProgramType . PYTH_CORE ] : ( config : ProgramConfig ) => {
59
- if ( "mappingAccounts" in config ) {
60
- return pythCore . getDownloadableConfig ( config as RawConfig ) ;
61
- }
62
- throw new Error ( "Invalid config type for Pyth Core" ) ;
63
- } ,
64
- [ ProgramType . PYTH_LAZER ] : ( config : ProgramConfig ) => {
65
- if ( "feeds" in config && config . programType === ProgramType . PYTH_LAZER ) {
66
- return pythLazer . getDownloadableConfig ( config as LazerConfig ) ;
67
- }
68
- throw new Error ( "Invalid config type for Pyth Lazer" ) ;
69
- } ,
55
+ export const getDownloadableConfig = (
56
+ config : ProgramConfig ,
57
+ ) : DownloadableConfig => {
58
+ if ( "mappingAccounts" in config ) {
59
+ return pythCore . getDownloadableConfig ( config ) ;
60
+ } else if (
61
+ "feeds" in config &&
62
+ config . programType === ProgramType . PYTH_LAZER
63
+ ) {
64
+ return pythLazer . getDownloadableConfig ( config ) ;
65
+ }
66
+ throw new Error (
67
+ "Invalid config type - could not determine program type from config structure" ,
68
+ ) ;
70
69
} ;
71
70
72
71
/**
You can’t perform that action at this time.
0 commit comments