Skip to content

Commit

Permalink
fix: Leave DAO form error (#2383)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xShuk authored Jul 16, 2024
1 parent 660d6b4 commit aca2814
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 27 deletions.
7 changes: 2 additions & 5 deletions components/Members/RevokeMyMembership.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import Modal from '@components/Modal'
import { ExclamationCircleIcon, XCircleIcon } from '@heroicons/react/outline'
import { useMintInfoByPubkeyQuery } from '@hooks/queries/mintInfo'
import { useRealmQuery } from '@hooks/queries/realm'
import useGovernanceForGovernedAddress from '@hooks/useGovernanceForGovernedAddress'
import useProgramVersion from '@hooks/useProgramVersion'
import useWalletOnePointOh from '@hooks/useWalletOnePointOh'
import { createRevokeGoverningTokens } from '@solana/spl-governance'
Expand Down Expand Up @@ -62,9 +61,9 @@ const Form: FC<{ closeModal: () => void }> = ({ closeModal }) => {
: (membershipTypes[selectedMembershipType] as PublicKey | undefined),
[membershipTypes, selectedMembershipType]
)

const { data: mintInfo } = useMintInfoByPubkeyQuery(selectedMint)
const governance = useGovernanceForGovernedAddress(selectedMint)


// erase errors on dirtying
useEffect(() => {
setFormErrors({})
Expand Down Expand Up @@ -94,7 +93,6 @@ const Form: FC<{ closeModal: () => void }> = ({ closeModal }) => {
if (
realm === undefined ||
mintInfo?.result === undefined ||
governance === undefined ||
!wallet?.publicKey
) {
throw new Error('proposal created before necessary data is fetched')
Expand Down Expand Up @@ -134,7 +132,6 @@ const Form: FC<{ closeModal: () => void }> = ({ closeModal }) => {
closeModal,
connection,
form.amount,
governance,
mintInfo?.result,
programVersion,
realm,
Expand Down
27 changes: 5 additions & 22 deletions components/inputs/TokenAmountInput.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { useMintInfoByPubkeyQuery } from '@hooks/queries/mintInfo'
import { PublicKey } from '@solana/web3.js'
import { precision } from '@utils/formatting'
import BigNumber from 'bignumber.js'
import { FC, useMemo } from 'react'
import { FC } from 'react'
import Input, { InputProps } from './Input'

type Props = Omit<
Expand All @@ -26,20 +23,6 @@ const TokenAmountInput: FC<Props> = ({
value,
...props
}) => {
const { data: mintInfo } = useMintInfoByPubkeyQuery(mint)

const mintMinAmount = useMemo(
() =>
mintInfo?.result
? new BigNumber(1).shiftedBy(mintInfo.result.decimals).toNumber()
: 1,
[mintInfo?.result]
)

const currentPrecision = useMemo(() => precision(mintMinAmount), [
mintMinAmount,
])

const validateAmount = () => {
if (value === undefined || value === '') {
if (props.required) {
Expand All @@ -50,24 +33,24 @@ const TokenAmountInput: FC<Props> = ({

setValue(
Math.max(
Number(mintMinAmount),
1,
Math.min(Number(Number.MAX_SAFE_INTEGER), Number(value))
).toFixed(currentPrecision)
).toFixed(0)
)
}

return (
<Input
disabled={props.disabled || mint === undefined}
min={mintMinAmount}
min={1}
label="Amount"
value={value}
type="number"
onChange={(e) => {
setValue(e.target.value)
setError(undefined)
}}
step={mintMinAmount}
step={1}
error={props.error}
onBlur={(e) => {
props.onBlur?.(e)
Expand Down

0 comments on commit aca2814

Please sign in to comment.