Skip to content

Commit 1366058

Browse files
committed
update creation UI
1 parent 2951738 commit 1366058

File tree

3 files changed

+51
-21
lines changed

3 files changed

+51
-21
lines changed

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/tokens/create/token/create-token-page.client.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export function CreateTokenAssetPageUI(props: {
4949

5050
const tokenInfoForm = useForm<TokenInfoFormValues>({
5151
defaultValues: {
52-
chain: activeChain?.id.toString() || "1",
52+
chain: activeChain?.id.toString() || "8453",
5353
description: "",
5454
image: undefined,
5555
name: "",
@@ -75,12 +75,12 @@ export function CreateTokenAssetPageUI(props: {
7575
// airdrop
7676
airdropEnabled: false,
7777
pool: {
78-
startingPricePerToken: "0.01",
78+
startingPricePerToken: "0.000000001", // 1gwei per token
7979
},
8080
// sale fieldset
81-
saleAllocationPercentage: "0",
82-
saleMode: "disabled",
83-
supply: "1000000",
81+
saleAllocationPercentage: "100",
82+
saleMode: "pool",
83+
supply: "1000000000", // 1 billion
8484
},
8585
mode: "onChange",
8686
resolver: zodResolver(tokenDistributionFormSchema),

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/tokens/create/token/distribution/token-distribution.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ import type {
1717
import { TokenAirdropSection } from "./token-airdrop";
1818
import { TokenSaleSection } from "./token-sale";
1919

20+
const compactNumberFormatter = new Intl.NumberFormat("en-US", {
21+
maximumFractionDigits: 10,
22+
notation: "compact",
23+
});
24+
2025
export function TokenDistributionFieldset(props: {
2126
accountAddress: string;
2227
onNext: () => void;
@@ -49,6 +54,7 @@ export function TokenDistributionFieldset(props: {
4954
<FormFieldSetup
5055
errorMessage={form.formState.errors.supply?.message}
5156
htmlFor={supplyId}
57+
helperText={`${compactNumberFormatter.format(Number(form.watch("supply")))} tokens`}
5258
isRequired
5359
label="Total Supply"
5460
>
@@ -73,12 +79,13 @@ export function TokenDistributionFieldset(props: {
7379
</div>
7480
</div>
7581

76-
<TokenAirdropSection client={props.client} form={form} />
7782
<TokenSaleSection
7883
chainId={props.chainId}
7984
client={props.client}
8085
form={form}
8186
/>
87+
88+
<TokenAirdropSection client={props.client} form={form} />
8289
</div>
8390
</StepCard>
8491
</form>

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/tokens/create/token/distribution/token-sale.tsx

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
import { useQuery } from "@tanstack/react-query";
44
import { XIcon } from "lucide-react";
5-
import { useEffect } from "react";
5+
import { useEffect, useState } from "react";
66
import type { ThirdwebClient } from "thirdweb";
77
import { defineChain } from "thirdweb";
88
import { isRouterEnabled } from "thirdweb/assets";
99
import { FormFieldSetup } from "@/components/blocks/FormFieldSetup";
1010
import { DynamicHeight } from "@/components/ui/DynamicHeight";
1111
import { DecimalInput } from "@/components/ui/decimal-input";
12-
import { Skeleton } from "@/components/ui/skeleton";
12+
import { Spinner } from "@/components/ui/Spinner/Spinner";
1313
import { Switch } from "@/components/ui/switch";
1414
import { useAllChainsData } from "@/hooks/chains/allChains";
1515
import type { TokenDistributionForm } from "../_common/form";
@@ -22,27 +22,48 @@ export function TokenSaleSection(props: {
2222
const saleMode = props.form.watch("saleMode");
2323
const { idToChain } = useAllChainsData();
2424
const chainMeta = idToChain.get(Number(props.chainId));
25+
const [hasUserUpdatedSaleMode, setHasUserUpdatedSaleMode] = useState(false);
2526

2627
const isRouterEnabledQuery = useQuery({
27-
queryFn: () =>
28-
isRouterEnabled({
29-
// eslint-disable-next-line no-restricted-syntax
30-
chain: defineChain(Number(props.chainId)),
31-
client: props.client,
32-
}),
28+
queryFn: async () => {
29+
try {
30+
return await isRouterEnabled({
31+
// eslint-disable-next-line no-restricted-syntax
32+
chain: defineChain(Number(props.chainId)),
33+
client: props.client,
34+
});
35+
} catch {
36+
return false;
37+
}
38+
},
3339
queryKey: ["isRouterEnabled", props.chainId],
3440
});
3541

42+
const isRouterEnabledValue = isRouterEnabledQuery.data === true;
43+
3644
const isSaleEnabled = saleMode !== "disabled";
3745

3846
// eslint-disable-next-line no-restricted-syntax
3947
useEffect(() => {
40-
if (isRouterEnabledQuery.data === false && isSaleEnabled) {
48+
if (isRouterEnabledValue === false && isSaleEnabled) {
4149
props.form.setValue("saleMode", "disabled", {
4250
shouldValidate: true,
4351
});
4452
}
45-
}, [isRouterEnabledQuery.data, isSaleEnabled, props.form]);
53+
}, [isRouterEnabledValue, isSaleEnabled, props.form]);
54+
55+
// eslint-disable-next-line no-restricted-syntax
56+
useEffect(() => {
57+
if (
58+
isRouterEnabledValue === true &&
59+
!hasUserUpdatedSaleMode &&
60+
!isSaleEnabled
61+
) {
62+
props.form.setValue("saleMode", "pool", {
63+
shouldValidate: true,
64+
});
65+
}
66+
}, [isRouterEnabledValue, props.form, hasUserUpdatedSaleMode, isSaleEnabled]);
4667

4768
return (
4869
<DynamicHeight>
@@ -52,23 +73,25 @@ export function TokenSaleSection(props: {
5273
<div>
5374
<h2 className="font-semibold text-lg">Sale</h2>
5475
<p className="text-muted-foreground text-sm">
55-
List and add liquidity for your coin on a decentralized exchange
56-
for purchase at fluctuating market price
76+
List your coin on a decentralized exchange and earn rewards on
77+
every trade
5778
</p>
5879
</div>
5980

6081
<div className="flex items-center gap-2">
6182
{isRouterEnabledQuery.isPending ? (
62-
<Skeleton className="h-[24px] w-[44px] rounded-full border" />
83+
<Spinner className="size-5" />
6384
) : (
6485
<Switch
6586
checked={isSaleEnabled}
66-
disabled={isRouterEnabledQuery.data !== true}
87+
disabled={!isRouterEnabledValue}
6788
onCheckedChange={(checked) => {
68-
if (isRouterEnabledQuery.data !== true) {
89+
if (!isRouterEnabledValue) {
6990
return;
7091
}
7192

93+
setHasUserUpdatedSaleMode(true);
94+
7295
props.form.setValue(
7396
"saleMode",
7497
checked ? "pool" : "disabled",

0 commit comments

Comments
 (0)