Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: jumper requirements #1595

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"noArguments": "error",
"noVar": "error",
"useConst": "error",
"noDefaultExport": "info"
"noDefaultExport": "off"
},
"suspicious": {
"noExplicitAny": "info",
Expand Down
1,303 changes: 562 additions & 741 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"next-themes": "^0.3.0",
"nextjs-toploader": "^1.6.12",
"papaparse": "^5.4.1",
"posthog-js": "^1.139.3",
"posthog-js": "1.205.0",
"qrcode.react": "^3.1.0",
"randombytes": "^2.1.0",
"react": "^18.2.0",
Expand Down
12 changes: 12 additions & 0 deletions public/requirementLogos/jumper.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
96 changes: 96 additions & 0 deletions src/requirements/Jumper/JumperForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { FormControl, FormField, FormItem, FormLabel } from "@/components/ui/Form"
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/Select"
import { Separator } from "@/components/ui/Separator"
import { ComponentType } from "react"
import { useFormContext, useWatch } from "react-hook-form"
import { RequirementFormProps } from "requirements/types"
import { JumperLevelForm } from "./components/JumperLevelForm"
import { JumperTraitForm } from "./components/JumperTraitForm"
import { JumperTypeForm } from "./components/JumperTypeForm"
import { JumperRequirementType } from "./types"

const jumperRequirementTypes = [
{
label: "Have at least level x",
value: "JUMPER_LEVEL",
JumperRequirement: JumperLevelForm,
},
{
label: "Have an achievement of a certain type",
value: "JUMPER_TYPE",
JumperRequirement: JumperTypeForm,
},
{
label: "Have a trait",
value: "JUMPER_TRAITS",
JumperRequirement: JumperTraitForm,
},
] satisfies {
label: string
value: JumperRequirementType
JumperRequirement: ComponentType<RequirementFormProps>
}[]

const JumperForm = ({ baseFieldPath, field }: RequirementFormProps) => {
const { control, resetField } = useFormContext()

const type = useWatch({ name: `${baseFieldPath}.type` })
const selected = jumperRequirementTypes.find((reqType) => reqType.value === type)

const resetForm = () => {
resetField(`${baseFieldPath}.data.minAmount`, { defaultValue: undefined })
resetField(`${baseFieldPath}.data.rewardType`, { defaultValue: "" })
resetField(`${baseFieldPath}.data.category`, { defaultValue: "" })
resetField(`${baseFieldPath}.data.name`, { defaultValue: "" })
}

return (
<div className="flex flex-col items-start gap-4">
<FormField
control={control}
name={`${baseFieldPath}.type`}
render={({ field }) => (
<FormItem className="w-full">
<FormLabel>Type</FormLabel>
<Select
onValueChange={(e) => {
resetForm()
field.onChange(e)
}}
defaultValue={field.value}
value={field.value}
>
<FormControl>
<SelectTrigger>
<SelectValue placeholder="Select one..." />
</SelectTrigger>
</FormControl>
<SelectContent>
{jumperRequirementTypes.map(({ value, label }) => (
<SelectItem key={value} value={value}>
{label}
</SelectItem>
))}
</SelectContent>
</Select>
</FormItem>
)}
/>

{selected?.JumperRequirement && (
<>
<Separator />
<selected.JumperRequirement baseFieldPath={baseFieldPath} field={field} />
</>
)}
</div>
)
}

export default JumperForm
50 changes: 50 additions & 0 deletions src/requirements/Jumper/JumperRequirement.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {
Requirement,
RequirementProps,
} from "components/[guild]/Requirements/components/Requirement"
import { useRequirementContext } from "components/[guild]/Requirements/components/RequirementContext"
import { ComponentType } from "react"
import REQUIREMENTS from "requirements"
import { JumperRequirementType } from "./types"

const JumperLevelDisplay = () => {
const { data } = useRequirementContext<"JUMPER_LEVEL">()

return `Wallet level ${data.minAmount} or above`
}

const JumperTypeDisplay = () => {
const { data } = useRequirementContext<"JUMPER_TYPE">()

return `Get an achievement with type ${data.rewardType}`
}

const JumperTraitsDisplay = () => {
const { data } = useRequirementContext<"JUMPER_TRAITS">()

if ("category" in data && "name" in data)
return `Get a trait in the ${data.category} category with title ${data.name}`

if ("category" in data) return `Get a trait in the ${data.category} category`

return `Get a trait with title ${data.name}`
}

const DisplayComponents = {
JUMPER_LEVEL: JumperLevelDisplay,
JUMPER_TYPE: JumperTypeDisplay,
JUMPER_TRAITS: JumperTraitsDisplay,
} satisfies Record<JumperRequirementType, ComponentType>

const JumperRequirement = (props: RequirementProps) => {
const { type } = useRequirementContext<JumperRequirementType>()
const DisplayComponent = DisplayComponents[type]

return (
<Requirement image={REQUIREMENTS.JUMPER_LEVEL.icon as string}>
<DisplayComponent />
</Requirement>
)
}

export default JumperRequirement
48 changes: 48 additions & 0 deletions src/requirements/Jumper/components/JumperLevelForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {
FormErrorMessage,
FormField,
FormItem,
FormLabel,
} from "@/components/ui/Form"
import { Input } from "@/components/ui/Input"
import { useFormContext } from "react-hook-form"
import { RequirementFormProps } from "requirements/types"

export const JumperLevelForm = ({ baseFieldPath }: RequirementFormProps) => {
const { control } = useFormContext()

return (
<FormField
control={control}
name={`${baseFieldPath}.data.minAmount`}
rules={{
required: true,
min: 1,
}}
render={({ field }) => (
<FormItem className="w-full">
<FormLabel>Level</FormLabel>
<Input
type="number"
{...field}
onChange={(e) => {
const newValue = e.target.value

// We need this to allow typing in a decimal point
if (/^[0-9]*\.[0-9]*0*$/i.test(newValue)) {
field.onChange?.(newValue, Number(newValue))
return field.onChange(newValue)
}

const parsedValue = parseInt(newValue)
const returnedValue = isNaN(parsedValue) ? "" : parsedValue

return field.onChange(returnedValue)
}}
/>
<FormErrorMessage />
</FormItem>
)}
/>
)
}
40 changes: 40 additions & 0 deletions src/requirements/Jumper/components/JumperTraitForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {
FormErrorMessage,
FormField,
FormItem,
FormLabel,
} from "@/components/ui/Form"
import { Input } from "@/components/ui/Input"
import { useFormContext } from "react-hook-form"
import { RequirementFormProps } from "requirements/types"

export const JumperTraitForm = ({ baseFieldPath }: RequirementFormProps) => {
const { control } = useFormContext()

return (
<>
<FormField
control={control}
name={`${baseFieldPath}.data.category`}
render={({ field }) => (
<FormItem className="w-full">
<FormLabel>Category</FormLabel>
<Input {...field} />
<FormErrorMessage />
</FormItem>
)}
/>
<FormField
control={control}
name={`${baseFieldPath}.data.name`}
render={({ field }) => (
<FormItem className="w-full">
<FormLabel>Name</FormLabel>
<Input {...field} />
<FormErrorMessage />
</FormItem>
)}
/>
</>
)
}
31 changes: 31 additions & 0 deletions src/requirements/Jumper/components/JumperTypeForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {
FormErrorMessage,
FormField,
FormItem,
FormLabel,
} from "@/components/ui/Form"
import { Input } from "@/components/ui/Input"
import { useFormContext } from "react-hook-form"
import { RequirementFormProps } from "requirements/types"

export const JumperTypeForm = ({ baseFieldPath }: RequirementFormProps) => {
const { control } = useFormContext()

return (
<FormField
control={control}
name={`${baseFieldPath}.data.rewardType`}
rules={{
required: true,
minLength: 1,
}}
render={({ field }) => (
<FormItem className="w-full">
<FormLabel>Achievement type</FormLabel>
<Input {...field} />
<FormErrorMessage />
</FormItem>
)}
/>
)
}
3 changes: 3 additions & 0 deletions src/requirements/Jumper/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { RequirementType } from "requirements/types"

export type JumperRequirementType = Extract<RequirementType, `JUMPER_${string}`>
9 changes: 9 additions & 0 deletions src/requirements/requirementDisplayComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,13 @@ export const REQUIREMENT_DISPLAY_COMPONENTS = {
LINEA_POH: dynamic<RequirementProps>(
() => import("requirements/LineaPOH/LineaPOHRequirement")
),
JUMPER_LEVEL: dynamic<RequirementProps>(
() => import("requirements/Jumper/JumperRequirement")
),
JUMPER_TYPE: dynamic<RequirementProps>(
() => import("requirements/Jumper/JumperRequirement")
),
JUMPER_TRAITS: dynamic<RequirementProps>(
() => import("requirements/Jumper/JumperRequirement")
),
} as const satisfies Record<RequirementType, ComponentType<RequirementProps>>
9 changes: 9 additions & 0 deletions src/requirements/requirementFormComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,15 @@ export const REQUIREMENT_FORM_COMPONENTS = {
LINEA_POH: dynamic<RequirementFormProps>(
() => import("requirements/LineaPOH/LineaPOHForm")
),
JUMPER_LEVEL: dynamic<RequirementFormProps>(
() => import("requirements/Jumper/JumperForm")
),
JUMPER_TYPE: dynamic<RequirementFormProps>(
() => import("requirements/Jumper/JumperForm")
),
JUMPER_TRAITS: dynamic<RequirementFormProps>(
() => import("requirements/Jumper/JumperForm")
),
} as const satisfies Record<
RequirementType,
ReturnType<typeof dynamic<RequirementFormProps>> | null
Expand Down
6 changes: 6 additions & 0 deletions src/requirements/requirements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@ export const REQUIREMENTS_DATA = [
types: ["LINEA_POH"],
isNegatable: true,
},
{
icon: "/requirementLogos/jumper.svg",
name: "Jumper",
types: ["JUMPER_LEVEL", "JUMPER_TYPE", "JUMPER_TRAITS"],
isNegatable: true,
},
{
icon: "/requirementLogos/web3inbox.png",
name: "Web3Inbox",
Expand Down
3 changes: 0 additions & 3 deletions src/requirements/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import { Requirement } from "types"

export type RequirementType = Exclude<
Schemas["Requirement"]["type"],
| "JUMPER_LEVEL"
| "JUMPER_TYPE"
| "JUMPER_TRAITS"
| "COVALENT_TX_VALUE"
| "COVALENT_TX_VALUE_RELATIVE"
| "FORM_APPROVAL"
Expand Down
Loading