Skip to content

Commit

Permalink
feat(CovalentContractCallFields): add MinMaxAmount
Browse files Browse the repository at this point in the history
  • Loading branch information
BrickheadJohnny committed Feb 26, 2025
1 parent 3c69e47 commit d673174
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/requirements/WalletActivity/WalletActivityRequirement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { Requirement as RequirementType } from "types"
import formatRelativeTimeFromNow from "utils/formatRelativeTimeFromNow"
import pluralize from "utils/pluralize"
import shortenHex from "utils/shortenHex"
import { CHAIN_CONFIG } from "wagmiConfig/chains"

const requirementIcons: Record<
string,
Expand Down Expand Up @@ -301,6 +302,19 @@ const WalletActivityRequirement = (props: RequirementProps): JSX.Element => {
</>
)}

{(req.data.minAmount || req.data.maxAmount) && (
<>
<span>
{req.data.minAmount && req.data.maxAmount
? ` with ${req.data.minAmount} - ${req.data.maxAmount}`
: req.data.minAmount
? ` with at least ${req.data.minAmount}`
: ` with at most ${req.data.maxAmount}`}
</span>
<span>{` ${CHAIN_CONFIG[req.chain].nativeCurrency.symbol}`}</span>
</>
)}

{req.type === "COVALENT_CONTRACT_CALL_COUNT" ? (
<BeforeAfterDates minTs={minAmount} maxTs={maxAmount} />
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@ import {
} from "@/components/ui/Select"
import { Skeleton } from "@/components/ui/Skeleton"
import { useFormContext, useWatch } from "react-hook-form"
import MinMaxAmount from "requirements/common/MinMaxAmount"
import { RequirementFormProps } from "requirements/types"
import { ADDRESS_REGEX } from "utils/guildCheckout/constants"
import { CHAIN_CONFIG } from "wagmiConfig/chains"
import { useCovalentContractAbiMethods } from "../hooks/useCovalentContractAbiMethods"
import { CovalentContractCallCountChain } from "../types"
import { abiItemToFunctionSignature } from "../utils"
import { ContractMethodInputsFieldArray } from "./ContractMethodInputsFieldArray"
import TxCountFormControl from "./TxCountFormControl"

export const CovalentContractCallFields = ({
field,
baseFieldPath,
}: RequirementFormProps) => {
const { control, resetField, getValues } = useFormContext()
Expand Down Expand Up @@ -139,6 +142,15 @@ export const CovalentContractCallFields = ({
baseFieldPath={baseFieldPath}
formLabel="Number of contract calls"
/>

<MinMaxAmount
label={
chain ? `${CHAIN_CONFIG[chain].nativeCurrency.symbol} amount` : "TX value"
}
field={field}
baseFieldPath={baseFieldPath}
format="FLOAT"
/>
</>
)
}
4 changes: 2 additions & 2 deletions src/requirements/common/MinMaxAmount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import parseFromObject from "utils/parseFromObject"

type Props = {
baseFieldPath: string
field: Requirement
field?: Requirement
label?: string
format?: "INT" | "FLOAT"
hideSetMaxButton?: boolean
Expand Down Expand Up @@ -53,7 +53,7 @@ const MinMaxAmount = ({
const handleChange = (newValue, onChange) => {
if (/^[0-9]*\.0*$/i.test(newValue)) return onChange(newValue)
const parsedValue = format === "INT" ? parseInt(newValue) : parseFloat(newValue)
return onChange(isNaN(parsedValue) ? null : parsedValue)
return onChange(isNaN(parsedValue) ? undefined : parsedValue)
}

return (
Expand Down

0 comments on commit d673174

Please sign in to comment.