Skip to content

Commit 724f8fd

Browse files
committed
refactor: address comments
1 parent 2f4e58d commit 724f8fd

File tree

3 files changed

+9
-96
lines changed

3 files changed

+9
-96
lines changed

governance/xc_admin/packages/xc_admin_common/src/programs/program_registry.ts

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ import {
88
ProgramConfig,
99
GetConfigParams,
1010
LazerConfigParams,
11-
} from "./types";
12-
import {
13-
ProgramFunctions,
1411
ValidationResult,
15-
GenerateInstructionsFn,
1612
} from "./types";
1713

1814
// Import functions from each program implementation
@@ -92,29 +88,6 @@ export const validateUploadedConfig: Record<
9288
* Function to generate the necessary instructions to apply configuration changes
9389
*/
9490
export const generateInstructions = {
95-
[ProgramType.PYTH_CORE]:
96-
pythCore.generateInstructions as GenerateInstructionsFn<ProgramType.PYTH_CORE>,
97-
[ProgramType.PYTH_LAZER]:
98-
pythLazer.generateInstructions as GenerateInstructionsFn<ProgramType.PYTH_LAZER>,
91+
[ProgramType.PYTH_CORE]: pythCore.generateInstructions,
92+
[ProgramType.PYTH_LAZER]: pythLazer.generateInstructions,
9993
};
100-
101-
/**
102-
* Get the complete set of functions for a specific program type
103-
*
104-
* @param type The program type to get functions for
105-
* @returns All functions for the specified program type
106-
*/
107-
export function getProgramFunctions<T extends ProgramType>(
108-
type: T,
109-
): ProgramFunctions<T> {
110-
return {
111-
getProgramAddress: getProgramAddress[type],
112-
isAvailableOnCluster: isAvailableOnCluster[type],
113-
getConfig: getConfig[type],
114-
getDownloadableConfig: getDownloadableConfig[type],
115-
validateUploadedConfig: validateUploadedConfig[type],
116-
generateInstructions: generateInstructions[
117-
type
118-
] as GenerateInstructionsFn<T>,
119-
};
120-
}

governance/xc_admin/packages/xc_admin_common/src/programs/types.ts

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,6 @@ export type GetConfigParams =
107107
} & CoreConfigParams)
108108
| ({ programType: ProgramType.PYTH_LAZER } & LazerConfigParams);
109109

110-
/**
111-
* Function to get configuration data
112-
*/
113-
export type GetConfigFn = (params: GetConfigParams) => ProgramConfig;
114-
115110
/**
116111
* Lazer feed configuration
117112
* TODO: Change to actual Lazer feed type
@@ -145,9 +140,7 @@ export type DownloadableProduct = {
145140
/**
146141
* Type for downloadable configuration
147142
*/
148-
export type DownloadableConfig = {
149-
[symbol: string]: DownloadableProduct;
150-
};
143+
export type DownloadableConfig = Record<string, DownloadableProduct>;
151144

152145
/**
153146
* Type for configuration that can be either RawConfig for Pyth Core or LazerConfig for Lazer
@@ -191,23 +184,6 @@ export type InstructionAccountsTypeMap = {
191184
[ProgramType.PYTH_LAZER]: LazerInstructionAccounts;
192185
};
193186

194-
/**
195-
* Function to get the program address for the given cluster and program type
196-
*/
197-
export type GetProgramAddressFn = (cluster: PythCluster) => PublicKey;
198-
199-
/**
200-
* Function to check if a program is available on a specific cluster
201-
*/
202-
export type IsAvailableOnClusterFn = (cluster: PythCluster) => boolean;
203-
204-
/**
205-
* Function to format the configuration for downloading as a JSON file
206-
*/
207-
export type GetDownloadableConfigFn = (
208-
config: ProgramConfig,
209-
) => DownloadableConfig;
210-
211187
/**
212188
* Result of validating an uploaded configuration
213189
*/
@@ -216,39 +192,3 @@ export interface ValidationResult {
216192
error?: string;
217193
changes?: any;
218194
}
219-
220-
/**
221-
* Function to validate an uploaded configuration against the current configuration
222-
*/
223-
export type ValidateUploadedConfigFn = (
224-
existingConfig: DownloadableConfig,
225-
uploadedConfig: unknown,
226-
cluster: PythCluster,
227-
) => ValidationResult;
228-
229-
/**
230-
* Generic type for generate instructions functions for a specific program type
231-
*/
232-
export type GenerateInstructionsFn<T extends ProgramType = ProgramType> = (
233-
changes: Record<
234-
string,
235-
{
236-
prev?: Partial<DownloadableProduct>;
237-
new?: Partial<DownloadableProduct>;
238-
}
239-
>,
240-
cluster: PythCluster,
241-
accounts: InstructionAccountsTypeMap[T],
242-
) => Promise<TransactionInstruction[]>;
243-
244-
/**
245-
* Collection of functions for each program type
246-
*/
247-
export interface ProgramFunctions<T extends ProgramType = ProgramType> {
248-
getProgramAddress: GetProgramAddressFn;
249-
isAvailableOnCluster: IsAvailableOnClusterFn;
250-
getConfig: GetConfigFn;
251-
getDownloadableConfig: GetDownloadableConfigFn;
252-
validateUploadedConfig: ValidateUploadedConfigFn;
253-
generateInstructions: GenerateInstructionsFn<T>;
254-
}

governance/xc_admin/packages/xc_admin_frontend/components/ProgramSwitch.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ const ProgramSwitch = ({ light = false }: { light?: boolean }) => {
3030
const { programType, setProgramType } = useProgramContext()
3131

3232
// Convert enum to array of options
33-
const programOptions = Object.values(ProgramType)
34-
.filter((value): value is ProgramType => typeof value === 'number') // Filter out reverse mappings
35-
.map((value) => ({
36-
value,
37-
label: PROGRAM_TYPE_NAMES[value],
38-
}))
33+
const programOptions = Object.entries(PROGRAM_TYPE_NAMES).map(
34+
([value, label]) => ({
35+
value: Number(value) as ProgramType,
36+
label,
37+
})
38+
)
3939

4040
return (
4141
<Menu as="div" className="relative z-[5] block w-[180px] text-left">

0 commit comments

Comments
 (0)