Skip to content

Commit

Permalink
fix distrubtion mango instructions (#1890)
Browse files Browse the repository at this point in the history
  • Loading branch information
abrzezinski94 authored Oct 25, 2023
1 parent 753dd51 commit ed65b23
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { useContext, useEffect, useState } from 'react'
import { useCallback, useContext, useEffect, useMemo, useState } from 'react'
import * as yup from 'yup'
import { isFormValid } from '@utils/formValidation'
import { UiInstruction } from '@utils/uiTypes/proposalCreationTypes'
import useGovernanceAssets from '@hooks/useGovernanceAssets'
import {
Expand Down Expand Up @@ -30,6 +28,7 @@ import {
TOKEN_PROGRAM_ID,
Token,
} from '@solana/spl-token'
import { validateInstruction } from '@utils/instructionTools'

interface CloseVaultsForm {
governedAccount: AssetAccount | null
Expand Down Expand Up @@ -64,13 +63,18 @@ const CloseVaults = ({
const [vaults, setVaults] = useState<{ [pubkey: string]: Vault }>()
const [formErrors, setFormErrors] = useState({})
const { handleSetInstructions } = useContext(NewProposalContext)
const validateInstruction = async (): Promise<boolean> => {
const { isValid, validationErrors } = await isFormValid(schema, form)
setFormErrors(validationErrors)
return isValid
}
async function getInstruction(): Promise<UiInstruction> {
const isValid = await validateInstruction()
const schema = useMemo(
() =>
yup.object().shape({
governedAccount: yup
.object()
.nullable()
.required('Program governed account is required'),
}),
[]
)
const getInstruction = useCallback(async () => {
const isValid = await validateInstruction({ schema, form, setFormErrors })
let serializedInstruction = ''
const mintsOfCurrentlyPushedAtaInstructions: string[] = []
const additionalSerializedInstructions: string[] = []
Expand Down Expand Up @@ -135,10 +139,17 @@ const CloseVaults = ({
serializedInstruction: serializedInstruction,
isValid,
governance: form.governedAccount?.governance,
customHoldUpTime: form.distributionNumber,
}
return obj
}
}, [
client?.program.methods,
connection,
distribution?.publicKey,
form,
schema,
vaults,
wallet?.publicKey,
])
const handleSelectDistribution = async (number: number) => {
const distribution = await client?.loadDistribution(number)
setDistribution(distribution)
Expand Down Expand Up @@ -189,14 +200,8 @@ const CloseVaults = ({
{ governedAccount: form.governedAccount?.governance, getInstruction },
index
)
// eslint-disable-next-line react-hooks/exhaustive-deps -- TODO please fix, it can cause difficult bugs. You might wanna check out https://bobbyhadz.com/blog/react-hooks-exhaustive-deps for info. -@asktree
}, [form])
const schema = yup.object().shape({
governedAccount: yup
.object()
.nullable()
.required('Program governed account is required'),
})
}, [form, getInstruction, handleSetInstructions, index, vaults])

const inputs: InstructionInput[] = [
{
label: 'Governance',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { useContext, useEffect, useState } from 'react'
import { useCallback, useContext, useEffect, useMemo, useState } from 'react'
import * as yup from 'yup'
import { isFormValid } from '@utils/formValidation'
import { UiInstruction } from '@utils/uiTypes/proposalCreationTypes'
import useGovernanceAssets from '@hooks/useGovernanceAssets'
import {
Expand All @@ -27,6 +25,7 @@ import Button from '@components/Button'
import { TOKEN_PROGRAM_ID, Token, u64 } from '@solana/spl-token'
import Input from '@components/inputs/Input'
import { parseMintNaturalAmountFromDecimal } from '@tools/sdk/units'
import { validateInstruction } from '@utils/instructionTools'

interface FillVaultsForm {
governedAccount: AssetAccount | null
Expand Down Expand Up @@ -70,16 +69,24 @@ const FillVaults = ({
const [vaults, setVaults] = useState<{ [pubkey: string]: Vault }>()
const [formErrors, setFormErrors] = useState({})
const { handleSetInstructions } = useContext(NewProposalContext)
const validateInstruction = async (): Promise<boolean> => {
const { isValid, validationErrors } = await isFormValid(schema, form)
setFormErrors(validationErrors)
return isValid
}
async function getInstruction(): Promise<UiInstruction> {
const isValid = await validateInstruction()

const schema = useMemo(
() =>
yup.object().shape({
governedAccount: yup
.object()
.nullable()
.required('Program governed account is required'),
}),
[]
)

const getInstruction = useCallback(async () => {
const isValid = await validateInstruction({ schema, form, setFormErrors })
let serializedInstruction = ''
const additionalSerializedInstructions: string[] = []
const prerequisiteInstructions: TransactionInstruction[] = []

if (
isValid &&
form.governedAccount?.governance?.account &&
Expand Down Expand Up @@ -111,10 +118,10 @@ const FillVaults = ({
serializedInstruction: serializedInstruction,
isValid,
governance: form.governedAccount?.governance,
customHoldUpTime: form.distributionNumber,
}

return obj
}
}, [form, schema, transfers, vaults, wallet?.publicKey])
const handleSelectDistribution = async (number: number) => {
const distribution = await client?.loadDistribution(number)
setDistribution(distribution)
Expand Down Expand Up @@ -193,14 +200,8 @@ const FillVaults = ({
{ governedAccount: form.governedAccount?.governance, getInstruction },
index
)
// eslint-disable-next-line react-hooks/exhaustive-deps -- TODO please fix, it can cause difficult bugs. You might wanna check out https://bobbyhadz.com/blog/react-hooks-exhaustive-deps for info. -@asktree
}, [form])
const schema = yup.object().shape({
governedAccount: yup
.object()
.nullable()
.required('Program governed account is required'),
})
}, [form, getInstruction, handleSetInstructions, index, vaults])

const inputs: InstructionInput[] = [
{
label: 'Governance',
Expand Down

1 comment on commit ed65b23

@vercel
Copy link

@vercel vercel bot commented on ed65b23 Oct 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

governance-ui – ./

governance-ui-git-main-solana-labs.vercel.app
governance-ui-solana-labs.vercel.app
app.realms.today

Please sign in to comment.