Skip to content

Commit 7a99c1d

Browse files
committed
[Experiment] Remove clientId from serverThirdwebClient
1 parent be60100 commit 7a99c1d

File tree

7 files changed

+118
-99
lines changed

7 files changed

+118
-99
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { Input } from "./input";
2+
3+
export function DecimalInput(props: {
4+
value: string;
5+
onChange: (value: string) => void;
6+
maxValue?: number;
7+
id?: string;
8+
className?: string;
9+
}) {
10+
return (
11+
<Input
12+
id={props.id}
13+
type="text"
14+
value={props.value}
15+
className={props.className}
16+
inputMode="decimal"
17+
onChange={(e) => {
18+
const number = Number(e.target.value);
19+
// ignore if string becomes invalid number
20+
if (Number.isNaN(number)) {
21+
return;
22+
}
23+
24+
if (props.maxValue && number > props.maxValue) {
25+
return;
26+
}
27+
28+
// replace leading multiple zeros with single zero
29+
let cleanedValue = e.target.value.replace(/^0+/, "0");
30+
31+
// replace leading zero before decimal point
32+
if (!cleanedValue.includes(".")) {
33+
cleanedValue = cleanedValue.replace(/^0+/, "");
34+
}
35+
36+
props.onChange(cleanedValue || "0");
37+
}}
38+
/>
39+
);
40+
}

apps/dashboard/src/@/constants/thirdweb-client.client.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { NEXT_PUBLIC_DASHBOARD_CLIENT_ID } from "./public-envs";
12
import { getConfiguredThirdwebClient } from "./thirdweb.server";
23

34
export function getClientThirdwebClient(params?: {
@@ -7,5 +8,7 @@ export function getClientThirdwebClient(params?: {
78
return getConfiguredThirdwebClient({
89
secretKey: params?.jwt ?? undefined,
910
teamId: params?.teamId ?? undefined,
11+
type: "client",
12+
clientId: NEXT_PUBLIC_DASHBOARD_CLIENT_ID,
1013
});
1114
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import "server-only";
22

3+
import { NEXT_PUBLIC_DASHBOARD_CLIENT_ID } from "./public-envs";
34
import { DASHBOARD_THIRDWEB_SECRET_KEY } from "./server-envs";
45
import { getConfiguredThirdwebClient } from "./thirdweb.server";
56

67
export const serverThirdwebClient = getConfiguredThirdwebClient({
78
teamId: undefined,
89
secretKey: DASHBOARD_THIRDWEB_SECRET_KEY,
10+
clientId: NEXT_PUBLIC_DASHBOARD_CLIENT_ID,
11+
type: "server",
912
});

apps/dashboard/src/@/constants/thirdweb.server.ts

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import {
2-
NEXT_PUBLIC_DASHBOARD_CLIENT_ID,
3-
NEXT_PUBLIC_IPFS_GATEWAY_URL,
4-
} from "@/constants/public-envs";
1+
import { NEXT_PUBLIC_IPFS_GATEWAY_URL } from "@/constants/public-envs";
52
import {
63
THIRDWEB_BRIDGE_URL,
74
THIRDWEB_BUNDLER_DOMAIN,
@@ -22,10 +19,21 @@ import {
2219
import { getZkPaymasterData } from "thirdweb/wallets/smart";
2320
import { getVercelEnv } from "../../lib/vercel-utils";
2421

25-
export function getConfiguredThirdwebClient(options: {
26-
secretKey: string | undefined;
27-
teamId: string | undefined;
28-
}): ThirdwebClient {
22+
export function getConfiguredThirdwebClient(
23+
options:
24+
| {
25+
type: "server";
26+
secretKey: string;
27+
clientId: string | undefined;
28+
teamId: string | undefined;
29+
}
30+
| {
31+
type: "client";
32+
clientId: string;
33+
secretKey: string | undefined;
34+
teamId: string | undefined;
35+
},
36+
): ThirdwebClient {
2937
if (getVercelEnv() !== "production") {
3038
// if not on production: run this when creating a client to set the domains
3139
setThirdwebDomains({
@@ -73,16 +81,30 @@ export function getConfiguredThirdwebClient(options: {
7381
});
7482
}
7583

76-
return createThirdwebClient({
77-
teamId: options.teamId,
78-
secretKey: options.secretKey,
79-
clientId: NEXT_PUBLIC_DASHBOARD_CLIENT_ID,
80-
config: {
81-
storage: {
82-
gatewayUrl: NEXT_PUBLIC_IPFS_GATEWAY_URL,
83-
},
84-
},
85-
});
84+
return createThirdwebClient(
85+
// this ternary is purely for making typescript happy - both are same object
86+
options.type === "server"
87+
? {
88+
teamId: options.teamId,
89+
secretKey: options.secretKey,
90+
clientId: options.clientId,
91+
config: {
92+
storage: {
93+
gatewayUrl: NEXT_PUBLIC_IPFS_GATEWAY_URL,
94+
},
95+
},
96+
}
97+
: {
98+
teamId: options.teamId,
99+
secretKey: options.secretKey,
100+
clientId: options.clientId,
101+
config: {
102+
storage: {
103+
gatewayUrl: NEXT_PUBLIC_IPFS_GATEWAY_URL,
104+
},
105+
},
106+
},
107+
);
86108
}
87109

88110
/**

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/erc20/_components/RecentTransfers.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
ChevronRightIcon,
1919
ExternalLinkIcon,
2020
} from "lucide-react";
21-
import { useState } from "react";
21+
import { useEffect, useState } from "react";
2222
import { type ThirdwebContract, toTokens } from "thirdweb";
2323
import type { ChainMetadata } from "thirdweb/chains";
2424
import {
@@ -199,6 +199,7 @@ export function RecentTransfers(props: {
199199
}) {
200200
const rowsPerPage = 10;
201201
const [page, setPage] = useState(0);
202+
const [hasFetchedOnce, setHasFetchedOnce] = useState(false);
202203

203204
const tokenQuery = useTokenTransfers({
204205
chainId: props.clientContract.chain.id,
@@ -207,11 +208,18 @@ export function RecentTransfers(props: {
207208
limit: rowsPerPage,
208209
});
209210

211+
// eslint-disable-next-line no-restricted-syntax
212+
useEffect(() => {
213+
if (!tokenQuery.isPending) {
214+
setHasFetchedOnce(true);
215+
}
216+
}, [tokenQuery.isPending]);
217+
210218
return (
211219
<div>
212220
<RecentTransfersUI
213221
data={tokenQuery.data ?? []}
214-
isPending={tokenQuery.isPending}
222+
isPending={tokenQuery.isPending && !hasFetchedOnce}
215223
rowsPerPage={rowsPerPage}
216224
tokenMetadata={{
217225
decimals: props.decimals,

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/erc20/_components/claim-tokens/claim-tokens-ui.tsx

Lines changed: 21 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
"use client";
22
import { Spinner } from "@/components/ui/Spinner/Spinner";
3-
import { Button } from "@/components/ui/button";
4-
import { Input } from "@/components/ui/input";
53
import { Label } from "@/components/ui/label";
64
import { SkeletonContainer } from "@/components/ui/skeleton";
75
import { cn } from "@/lib/utils";
86
import { useMutation, useQuery } from "@tanstack/react-query";
97
import { TransactionButton } from "components/buttons/TransactionButton";
10-
import {
11-
CheckIcon,
12-
CircleIcon,
13-
MinusIcon,
14-
PlusIcon,
15-
XIcon,
16-
} from "lucide-react";
8+
import { CheckIcon, CircleIcon, XIcon } from "lucide-react";
179
import { useTheme } from "next-themes";
1810
import { useState } from "react";
1911
import { toast } from "sonner";
@@ -33,6 +25,7 @@ import {
3325
import { useActiveAccount, useSendTransaction } from "thirdweb/react";
3426
import { getClaimParams } from "thirdweb/utils";
3527
import { tryCatch } from "utils/try-catch";
28+
import { DecimalInput } from "../../../../../../../../../../@/components/ui/decimal-input";
3629
import { getSDKTheme } from "../../../../../../../../components/sdk-component-theme";
3730
import { PublicPageConnectButton } from "../../../_components/PublicPageConnectButton";
3831
import { getCurrencyMeta } from "../../_utils/getCurrencyMeta";
@@ -53,7 +46,7 @@ export function ClaimTokenCardUI(props: {
5346
symbol: string;
5447
};
5548
}) {
56-
const [quantity, setQuantity] = useState(1);
49+
const [quantity, setQuantity] = useState("1");
5750
const account = useActiveAccount();
5851
const { theme } = useTheme();
5952
const sendClaimTx = useSendTransaction({
@@ -216,6 +209,7 @@ export function ClaimTokenCardUI(props: {
216209
quantity={quantity}
217210
setQuantity={setQuantity}
218211
id="token-amount"
212+
symbol={props.symbol}
219213
/>
220214
{/* <p className="text-xs text-muted-foreground">Maximum purchasable: {tokenData.maxPurchasable} tokens</p> */}
221215
</div>
@@ -246,9 +240,7 @@ export function ClaimTokenCardUI(props: {
246240
{/* Quantity */}
247241
<div className="flex justify-between font-medium text-sm">
248242
<span>Quantity</span>
249-
<span>
250-
{quantity} Token{quantity > 1 ? "s" : ""}
251-
</span>
243+
<span>{quantity}</span>
252244
</div>
253245

254246
{/* Total Price */}
@@ -265,7 +257,7 @@ export function ClaimTokenCardUI(props: {
265257
claimParamsData.pricePerTokenWei,
266258
claimParamsData.decimals,
267259
),
268-
) * quantity
260+
) * Number(quantity)
269261
} ${claimParamsData.symbol}`
270262
: undefined
271263
}
@@ -293,7 +285,7 @@ export function ClaimTokenCardUI(props: {
293285
txChainID={props.contract.chain.id}
294286
disabled={approveAndClaim.isPending || !claimParamsData}
295287
>
296-
Buy Token{quantity > 1 ? "s" : ""}
288+
Buy
297289
</TransactionButton>
298290
) : (
299291
<PublicPageConnectButton connectButtonClassName="!w-full" />
@@ -350,39 +342,25 @@ function StepUI(props: {
350342
}
351343

352344
function PriceInput(props: {
353-
quantity: number;
354-
setQuantity: (quantity: number) => void;
345+
quantity: string;
346+
setQuantity: (quantity: string) => void;
355347
id: string;
348+
symbol: string;
356349
}) {
357350
return (
358-
<div className="flex items-center">
359-
<Input
351+
<div className="relative">
352+
<DecimalInput
360353
id={props.id}
361-
type="number"
362-
value={props.quantity}
363-
onChange={(e) =>
364-
props.setQuantity(Math.max(1, Number(e.target.value) || 1))
365-
}
366-
min="1"
367-
className="!text-xl h-12 rounded-r-none border-r-0 font-semibold "
354+
value={String(props.quantity)}
355+
onChange={(value) => {
356+
console.log("value", value);
357+
props.setQuantity(value);
358+
}}
359+
className="!text-2xl h-auto truncate bg-muted/50 pr-14 font-bold"
368360
/>
369-
370-
<Button
371-
variant="outline"
372-
className="h-12 w-16 rounded-none border-r-0 bg-background p-0 disabled:opacity-100"
373-
onClick={() => props.setQuantity(props.quantity - 1)}
374-
disabled={props.quantity <= 1}
375-
>
376-
<MinusIcon className="size-4" />
377-
</Button>
378-
379-
<Button
380-
className="h-12 w-16 rounded-l-none bg-background p-0 disabled:opacity-100"
381-
variant="outline"
382-
onClick={() => props.setQuantity(props.quantity + 1)}
383-
>
384-
<PlusIcon className="size-4" />
385-
</Button>
361+
<div className="-translate-y-1/2 absolute top-1/2 right-4 text-base text-muted-foreground">
362+
{props.symbol}
363+
</div>
386364
</div>
387365
);
388366
}

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

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { FormFieldSetup } from "@/components/blocks/FormFieldSetup";
44
import { TokenSelector } from "@/components/blocks/TokenSelector";
55
import { DynamicHeight } from "@/components/ui/DynamicHeight";
6-
import { Input } from "@/components/ui/input";
6+
import { DecimalInput } from "@/components/ui/decimal-input";
77
import { Switch } from "@/components/ui/switch";
88
import type { ThirdwebClient } from "thirdweb";
99
import type { TokenDistributionForm } from "../form";
@@ -112,38 +112,3 @@ export function TokenSaleSection(props: {
112112
</DynamicHeight>
113113
);
114114
}
115-
116-
function DecimalInput(props: {
117-
value: string;
118-
onChange: (value: string) => void;
119-
maxValue?: number;
120-
}) {
121-
return (
122-
<Input
123-
type="text"
124-
value={props.value}
125-
inputMode="decimal"
126-
onChange={(e) => {
127-
const number = Number(e.target.value);
128-
// ignore if string becomes invalid number
129-
if (Number.isNaN(number)) {
130-
return;
131-
}
132-
133-
if (props.maxValue && number > props.maxValue) {
134-
return;
135-
}
136-
137-
// replace leading multiple zeros with single zero
138-
let cleanedValue = e.target.value.replace(/^0+/, "0");
139-
140-
// replace leading zero before decimal point
141-
if (!cleanedValue.includes(".")) {
142-
cleanedValue = cleanedValue.replace(/^0+/, "");
143-
}
144-
145-
props.onChange(cleanedValue || "0");
146-
}}
147-
/>
148-
);
149-
}

0 commit comments

Comments
 (0)