mirror of https://github.com/certusone/oyster.git
fix: validate new governance public key inputs
This commit is contained in:
parent
be911a89f7
commit
501829d9fc
|
@ -163,6 +163,14 @@ export function fromLamports(
|
|||
return (amount / precision) * rate;
|
||||
}
|
||||
|
||||
export const tryParseKey = (key: string): PublicKey | null => {
|
||||
try {
|
||||
return new PublicKey(key);
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
var SI_SYMBOL = ['', 'k', 'M', 'G', 'T', 'P', 'E'];
|
||||
|
||||
const abbreviateNumber = (number: number, precision: number) => {
|
||||
|
|
|
@ -127,8 +127,16 @@ export const LABELS = {
|
|||
SLOT_MUST_BE_NUMERIC: 'Slot can only be numeric',
|
||||
SLOT_MUST_BE_GREATER_THAN: 'Slot must be greater than or equal to ',
|
||||
DELAY: 'Slot Delay',
|
||||
|
||||
MIN_SLOT_MUST_BE_NUMERIC: 'Minimum Slot Waiting Period can only be numeric',
|
||||
TIME_LIMIT_MUST_BE_NUMERIC: 'Time Limit can only be numeric',
|
||||
PROGRAM_ID_IS_NOT_A_VALID_PUBLIC_KEY: (programId: string) =>
|
||||
`Program ID: '${programId}' is not a valid public key`,
|
||||
GOVERNANCE_MINT_IS_NOT_A_VALID_PUBLIC_KEY: (programId: string) =>
|
||||
`Governance Mint ID: '${programId}' is not a valid public key`,
|
||||
COUNCIL_MINT_IS_NOT_A_VALID_PUBLIC_KEY: (programId: string) =>
|
||||
`Council Mint ID: '${programId}' is not a valid public key`,
|
||||
|
||||
TIME_LIMIT: 'Voting Time Limit',
|
||||
THIS_CONFIG_LACKS_COUNCIL: 'This program does not have a council.',
|
||||
GIT_CONTENT_EXCEEDED:
|
||||
|
|
|
@ -10,9 +10,8 @@ import {
|
|||
VotingEntryRule,
|
||||
ZERO_KEY,
|
||||
} from '../../models/timelock';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { LABELS } from '../../constants';
|
||||
import { contexts, utils } from '@oyster/common';
|
||||
import { contexts, utils, tryParseKey } from '@oyster/common';
|
||||
import { registerProgramGovernance } from '../../actions/registerProgramGovernance';
|
||||
import { Redirect } from 'react-router';
|
||||
import BN from 'bn.js';
|
||||
|
@ -96,6 +95,32 @@ export function NewForm({
|
|||
});
|
||||
return;
|
||||
}
|
||||
if (!tryParseKey(values.program)) {
|
||||
notify({
|
||||
message: LABELS.PROGRAM_ID_IS_NOT_A_VALID_PUBLIC_KEY(values.program),
|
||||
type: 'error',
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (values.governanceMint && !tryParseKey(values.governanceMint)) {
|
||||
notify({
|
||||
message: LABELS.GOVERNANCE_MINT_IS_NOT_A_VALID_PUBLIC_KEY(
|
||||
values.governanceMint,
|
||||
),
|
||||
type: 'error',
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (values.councilMint && !tryParseKey(values.councilMint)) {
|
||||
notify({
|
||||
message: LABELS.COUNCIL_MINT_IS_NOT_A_VALID_PUBLIC_KEY(
|
||||
values.councilMint,
|
||||
),
|
||||
type: 'error',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const uninitializedConfig = {
|
||||
timelockType: values.timelockType,
|
||||
executionType: values.executionType,
|
||||
|
|
Loading…
Reference in New Issue