Skip to content

Commit

Permalink
chore: revert format
Browse files Browse the repository at this point in the history
  • Loading branch information
MjCage committed Sep 25, 2023
1 parent 3e58de6 commit 5e9d9c0
Showing 1 changed file with 78 additions and 85 deletions.
163 changes: 78 additions & 85 deletions utils/validations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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({
Expand All @@ -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'),
Expand All @@ -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
Expand All @@ -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({
Expand All @@ -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'),
Expand All @@ -741,24 +736,24 @@ 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')
.test(
'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({
Expand All @@ -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'),
Expand Down Expand Up @@ -1326,4 +1319,4 @@ export const getUpdateTokenMetadataSchema = () => {
uri: yup.string().required('URI is required'),
mintAccount: yup.object().nullable().required('Mint is required'),
})
}
}

0 comments on commit 5e9d9c0

Please sign in to comment.