-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a
/test-utils
page for updating arena state on a local network;…
… add shadcn for prototyping components
- Loading branch information
Showing
13 changed files
with
375 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { SetMeleeDurationForm } from "@/components/pages/test-utils/SetNewMeleeDuration"; | ||
import { Network } from "@aptos-labs/ts-sdk"; | ||
import { APTOS_NETWORK } from "@sdk/const"; | ||
|
||
export const dynamic = "force-static"; | ||
|
||
export default function TestUtilsPage() { | ||
return ( | ||
<> | ||
{APTOS_NETWORK === Network.LOCAL && ( | ||
<div className="w-full h-full flex flex-col"> | ||
<SetMeleeDurationForm className="" /> | ||
</div> | ||
)} | ||
</> | ||
); | ||
} |
77 changes: 77 additions & 0 deletions
77
src/typescript/frontend/src/components/pages/test-utils/SetNewMeleeDuration.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
"use client"; | ||
|
||
import { Button } from "@/components/ui/Button"; | ||
import { Input } from "@/components/ui/Input"; | ||
import { cn } from "lib/utils/class-name"; | ||
import { useState } from "react"; | ||
import { Ed25519PrivateKey, Hex, Account, Network } from "@aptos-labs/ts-sdk"; | ||
import { EmojicoinArena } from "@/contract-apis"; | ||
import { useAptos } from "context/wallet-context/AptosContextProvider"; | ||
import { isNumberInConstruction } from "@sdk/utils"; | ||
import { Label } from "@/components/ui/Label"; | ||
import { successfulTransactionToast } from "@/components/wallet/toasts"; | ||
import { toast } from "react-toastify"; | ||
|
||
const publisher = (() => { | ||
// This is the publisher private key used in test. | ||
const privateKeyString = | ||
process.env.PUBLISHER_PRIVATE_KEY ?? | ||
"eaa964d1353b075ac63b0c5a0c1e92aa93355be1402f6077581e37e2a846105e"; | ||
const privateKey = new Ed25519PrivateKey(Hex.fromHexString(privateKeyString).toUint8Array()); | ||
return Account.fromPrivateKey({ privateKey }); | ||
})(); | ||
|
||
const MICROSECONDS_PER_MINUTE = 60 * 1000 * 1000; | ||
|
||
export const SetMeleeDurationForm = ({ className }: React.HTMLAttributes<HTMLDivElement>) => { | ||
const [duration, setDuration] = useState(""); | ||
const { aptos } = useAptos(); | ||
|
||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => setDuration(e.target.value); | ||
|
||
const handleClick = () => { | ||
const dur = Number.parseFloat(duration); | ||
const asMicroseconds = dur * MICROSECONDS_PER_MINUTE; | ||
const floored = Math.floor(asMicroseconds); | ||
const durationAsMicroseconds = BigInt(floored); | ||
EmojicoinArena.SetNextMeleeDuration.submit({ | ||
aptosConfig: aptos.config, | ||
emojicoinArena: publisher, | ||
duration: durationAsMicroseconds, | ||
}).then((res) => { | ||
if (res.success) { | ||
successfulTransactionToast(res, { name: Network.LOCAL }); | ||
} else { | ||
toast.error("Fail."); | ||
} | ||
}); | ||
}; | ||
|
||
return ( | ||
<div | ||
className={cn("flex flex-col w-full max-w-48 m-auto space-x-2 gap-1 font-forma", className)} | ||
> | ||
<div className="grid w-full max-w-sm items-center gap-1.5"> | ||
<Label className="text-white font-forma" htmlFor="duration"> | ||
{"Duration (minutes)"} | ||
</Label> | ||
<Input | ||
id="duration" | ||
value={duration} | ||
className="text-lighter-gray" | ||
type="text" | ||
placeholder="in minutes" | ||
onChange={handleChange} | ||
/> | ||
</div> | ||
<Button | ||
className="m-auto" | ||
disabled={!isNumberInConstruction(duration)} | ||
onClick={handleClick} | ||
type="submit" | ||
> | ||
{"set next melee duration"} | ||
</Button> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import * as React from "react"; | ||
import { Slot } from "@radix-ui/react-slot"; | ||
import { cva, type VariantProps } from "class-variance-authority"; | ||
import { cn } from "lib/utils/class-name"; | ||
|
||
const buttonVariants = cva( | ||
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0", | ||
{ | ||
variants: { | ||
variant: { | ||
default: "bg-primary text-primary-foreground shadow hover:bg-primary/90", | ||
destructive: "bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90", | ||
outline: | ||
"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground", | ||
secondary: "bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80", | ||
ghost: "hover:bg-accent hover:text-accent-foreground", | ||
link: "text-primary underline-offset-4 hover:underline", | ||
}, | ||
size: { | ||
default: "h-9 px-4 py-2", | ||
sm: "h-8 rounded-md px-3 text-xs", | ||
lg: "h-10 rounded-md px-8", | ||
icon: "h-9 w-9", | ||
}, | ||
}, | ||
defaultVariants: { | ||
variant: "default", | ||
size: "default", | ||
}, | ||
} | ||
); | ||
|
||
export interface ButtonProps | ||
extends React.ButtonHTMLAttributes<HTMLButtonElement>, | ||
VariantProps<typeof buttonVariants> { | ||
asChild?: boolean; | ||
} | ||
|
||
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>( | ||
({ className, variant, size, asChild = false, ...props }, ref) => { | ||
const Comp = asChild ? Slot : "button"; | ||
return ( | ||
<Comp className={cn(buttonVariants({ variant, size, className }))} ref={ref} {...props} /> | ||
); | ||
} | ||
); | ||
Button.displayName = "Button"; | ||
|
||
export { Button, buttonVariants }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { cn } from "lib/utils/class-name"; | ||
import * as React from "react"; | ||
|
||
const Input = React.forwardRef<HTMLInputElement, React.ComponentProps<"input">>( | ||
({ className, type, ...props }, ref) => { | ||
return ( | ||
<input | ||
type={type} | ||
className={cn( | ||
"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm", | ||
className | ||
)} | ||
ref={ref} | ||
{...props} | ||
/> | ||
); | ||
} | ||
); | ||
Input.displayName = "Input"; | ||
|
||
export { Input }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
"use client"; | ||
|
||
import * as React from "react"; | ||
import * as LabelPrimitive from "@radix-ui/react-label"; | ||
import { cva, type VariantProps } from "class-variance-authority"; | ||
import { cn } from "lib/utils/class-name"; | ||
|
||
const labelVariants = cva( | ||
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70" | ||
); | ||
|
||
const Label = React.forwardRef< | ||
React.ElementRef<typeof LabelPrimitive.Root>, | ||
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> & VariantProps<typeof labelVariants> | ||
>(({ className, ...props }, ref) => ( | ||
<LabelPrimitive.Root ref={ref} className={cn(labelVariants(), className)} {...props} /> | ||
)); | ||
Label.displayName = LabelPrimitive.Root.displayName; | ||
|
||
export { Label }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.