diff --git a/utils/validations.tsx b/utils/validations.tsx index d5dad4279c..fb5d3c600f 100644 --- a/utils/validations.tsx +++ b/utils/validations.tsx @@ -530,7 +530,11 @@ export const getDualFinanceGovernanceAirdropSchema = ({ }) } -export const getDualFinanceMerkleAirdropSchema = ({ form }: { form: any }) => { +export const getDualFinanceMerkleAirdropSchema = ({ + form, +}: { + form: any +}) => { return yup.object().shape({ root: yup .string() @@ -617,7 +621,7 @@ export const getDualFinanceLiquidityStakingOptionSchema = ({ 'expiration', 'Expiration must be a future unix seconds timestamp', function (val: number) { - const nowUnixMs = Date.now() / 1_000 + const nowUnixMs = Date.now() / 1_000; // Primary goal is to catch users inputting ms instead of sec. if (val > nowUnixMs * 10) { return this.createError({ @@ -632,25 +636,23 @@ export const getDualFinanceLiquidityStakingOptionSchema = ({ return true } ), - numTokens: yup - .number() - .typeError('Num tokens is required') - .test('amount', 'amount', async function (val: number) { - if (!form.baseTreasury) { - return this.createError({ - message: `Please select a treasury`, - }) - } - const numAtomsInTreasury = new BN( - form.baseTreasury.extensions.token.account.amount - ).toNumber() - if (numAtomsInTreasury < val) { - return this.createError({ - message: `Not enough tokens`, - }) - } - return true - }), + numTokens: yup.number().typeError('Num tokens is required') + .test('amount', 'amount', async function (val: number) { + if (!form.baseTreasury) { + return this.createError({ + message: `Please select a treasury`, + }) + } + const numAtomsInTreasury = new BN( + form.baseTreasury.extensions.token.account.amount + ).toNumber() + if (numAtomsInTreasury < val) { + return this.createError({ + message: `Not enough tokens`, + }) + } + return true + }), lotSize: yup.number().typeError('lotSize is required'), baseTreasury: yup.object().typeError('baseTreasury is required'), quoteTreasury: yup.object().typeError('quoteTreasury is required'), @@ -662,34 +664,29 @@ export const getDualFinanceStakingOptionSchema = ({ form, connection, }: { - form: any + form: any, connection: any }) => { return yup.object().shape({ - soName: yup - .string() - .required('Staking option name is required') - .test( - 'is-not-too-long', - 'soName too long', - (value) => value !== undefined && value.length < 32 - ), + soName: yup.string().required('Staking option name is required') + .test('is-not-too-long', 'soName too long', (value) => + value !== undefined && value.length < 32 + ), userPk: yup .string() .test( - 'is-valid-address1', - 'Please enter a valid PublicKey', + 'is-valid-address1', 'Please enter a valid PublicKey', async function (userPk: string) { if (!userPk || !validatePubkey(userPk)) { - return false + return false; } const pubKey = getValidatedPublickKey(userPk) const account = await getValidateAccount(connection.current, pubKey) if (!account) { - return false + return false; } - return true + return true; } ), optionExpirationUnixSeconds: yup @@ -699,7 +696,7 @@ export const getDualFinanceStakingOptionSchema = ({ 'expiration', 'Expiration must be a future unix seconds timestamp', function (val: number) { - const nowUnixMs = Date.now() / 1_000 + const nowUnixMs = Date.now() / 1_000; // Primary goal is to catch users inputting ms instead of sec. if (val > nowUnixMs * 10) { return this.createError({ @@ -714,25 +711,23 @@ export const getDualFinanceStakingOptionSchema = ({ return true } ), - numTokens: yup - .number() - .typeError('Num tokens is required') - .test('amount', 'amount', async function (val: number) { - if (!form.baseTreasury) { - return this.createError({ - message: `Please select a treasury`, - }) - } - const numAtomsInTreasury = new BN( - form.baseTreasury.extensions.token.account.amount - ).toNumber() - if (numAtomsInTreasury < val) { - return this.createError({ - message: `Not enough tokens`, - }) - } - return true - }), + numTokens: yup.number().typeError('Num tokens is required') + .test('amount', 'amount', async function (val: number) { + if (!form.baseTreasury) { + return this.createError({ + message: `Please select a treasury`, + }) + } + const numAtomsInTreasury = new BN( + form.baseTreasury.extensions.token.account.amount + ).toNumber() + if (numAtomsInTreasury < val) { + return this.createError({ + message: `Not enough tokens`, + }) + } + return true + }), strike: yup.number().typeError('Strike is required'), lotSize: yup.number().typeError('lotSize is required'), baseTreasury: yup.object().typeError('baseTreasury is required'), @@ -741,16 +736,16 @@ export const getDualFinanceStakingOptionSchema = ({ }) } -export const getDualFinanceGsoSchema = ({ form }: { form: any }) => { +export const getDualFinanceGsoSchema = ({ + form, +}: { + form: any +}) => { return yup.object().shape({ - soName: yup - .string() - .required('Staking option name is required') - .test( - 'is-not-too-long', - 'soName too long', - (value) => value !== undefined && value.length < 32 - ), + soName: yup.string().required('Staking option name is required') + .test('is-not-too-long', 'soName too long', (value) => + value !== undefined && value.length < 32 + ), optionExpirationUnixSeconds: yup .number() .typeError('Expiration is required') @@ -758,7 +753,7 @@ export const getDualFinanceGsoSchema = ({ form }: { form: any }) => { 'expiration', 'Expiration must be a future unix seconds timestamp', function (val: number) { - const nowUnixMs = Date.now() / 1_000 + const nowUnixMs = Date.now() / 1_000; // Primary goal is to catch users inputting ms instead of sec. if (val > nowUnixMs * 10) { return this.createError({ @@ -773,25 +768,23 @@ export const getDualFinanceGsoSchema = ({ form }: { form: any }) => { return true } ), - numTokens: yup - .number() - .typeError('Num tokens is required') - .test('amount', 'amount', async function (val: number) { - if (!form.baseTreasury) { - return this.createError({ - message: `Please select a treasury`, - }) - } - const numAtomsInTreasury = new BN( - form.baseTreasury.extensions.token.account.amount - ).toNumber() - if (numAtomsInTreasury < val) { - return this.createError({ - message: `Not enough tokens`, - }) - } - return true - }), + numTokens: yup.number().typeError('Num tokens is required') + .test('amount', 'amount', async function (val: number) { + if (!form.baseTreasury) { + return this.createError({ + message: `Please select a treasury`, + }) + } + const numAtomsInTreasury = new BN( + form.baseTreasury.extensions.token.account.amount + ).toNumber() + if (numAtomsInTreasury < val) { + return this.createError({ + message: `Not enough tokens`, + }) + } + return true + }), strike: yup.number().typeError('strike is required'), lotSize: yup.number().typeError('lotSize is required'), baseTreasury: yup.object().typeError('baseTreasury is required'), @@ -1326,4 +1319,4 @@ export const getUpdateTokenMetadataSchema = () => { uri: yup.string().required('URI is required'), mintAccount: yup.object().nullable().required('Mint is required'), }) -} +} \ No newline at end of file