Merge pull request #52 from SebastianBor/fix-validate-new-governance-public-key-inputs

Proposals: Validate new governance public key inputs
This commit is contained in:
Jordan Prince 2021-04-08 09:04:46 -05:00 committed by GitHub
commit 24001d634c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 2 deletions

View File

@ -163,6 +163,14 @@ export function fromLamports(
return (amount / precision) * rate; 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']; var SI_SYMBOL = ['', 'k', 'M', 'G', 'T', 'P', 'E'];
const abbreviateNumber = (number: number, precision: number) => { const abbreviateNumber = (number: number, precision: number) => {

View File

@ -127,8 +127,16 @@ export const LABELS = {
SLOT_MUST_BE_NUMERIC: 'Slot can only be numeric', SLOT_MUST_BE_NUMERIC: 'Slot can only be numeric',
SLOT_MUST_BE_GREATER_THAN: 'Slot must be greater than or equal to ', SLOT_MUST_BE_GREATER_THAN: 'Slot must be greater than or equal to ',
DELAY: 'Slot Delay', DELAY: 'Slot Delay',
MIN_SLOT_MUST_BE_NUMERIC: 'Minimum Slot Waiting Period can only be numeric', MIN_SLOT_MUST_BE_NUMERIC: 'Minimum Slot Waiting Period can only be numeric',
TIME_LIMIT_MUST_BE_NUMERIC: 'Time Limit 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', TIME_LIMIT: 'Voting Time Limit',
THIS_CONFIG_LACKS_COUNCIL: 'This program does not have a council.', THIS_CONFIG_LACKS_COUNCIL: 'This program does not have a council.',
GIT_CONTENT_EXCEEDED: GIT_CONTENT_EXCEEDED:

View File

@ -10,9 +10,8 @@ import {
VotingEntryRule, VotingEntryRule,
ZERO_KEY, ZERO_KEY,
} from '../../models/timelock'; } from '../../models/timelock';
import { Link } from 'react-router-dom';
import { LABELS } from '../../constants'; import { LABELS } from '../../constants';
import { contexts, utils } from '@oyster/common'; import { contexts, utils, tryParseKey } from '@oyster/common';
import { registerProgramGovernance } from '../../actions/registerProgramGovernance'; import { registerProgramGovernance } from '../../actions/registerProgramGovernance';
import { Redirect } from 'react-router'; import { Redirect } from 'react-router';
import BN from 'bn.js'; import BN from 'bn.js';
@ -96,6 +95,32 @@ export function NewForm({
}); });
return; 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 = { const uninitializedConfig = {
timelockType: values.timelockType, timelockType: values.timelockType,
executionType: values.executionType, executionType: values.executionType,