Skip to content

Commit 4df17cd

Browse files
committed
[MNY-129] Dashboard: Use useSendAndConfirmTx everywhere, Replace createToken with prepareCreateToken
1 parent ec2ece0 commit 4df17cd

File tree

55 files changed

+338
-387
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+338
-387
lines changed

apps/dashboard/.eslintrc.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,30 @@ module.exports = {
9595
'Import "posthog-js" directly only within the analytics helpers ("src/@/analytics/*"). Use the exported helpers from "@/analytics/track" elsewhere.',
9696
name: "posthog-js",
9797
},
98+
{
99+
importNames: ["useSendTransaction"],
100+
message:
101+
'Use `import { useSendTx } from "@/hooks/useSendTx";` instead',
102+
name: "thirdweb/react",
103+
},
104+
{
105+
importNames: ["useSendAndConfirmTransaction"],
106+
message:
107+
'Use `import { useSendAndConfirmTx } from "@/hooks/useSendTx";` instead',
108+
name: "thirdweb/react",
109+
},
110+
{
111+
importNames: ["sendTransaction"],
112+
message:
113+
'Use `import { useSendTx } from "@/hooks/useSendTx";` instead if used in react component',
114+
name: "thirdweb",
115+
},
116+
{
117+
importNames: ["sendAndConfirmTransaction"],
118+
message:
119+
'Use `import { useSendAndConfirmTx } from "@/hooks/useSendTx";` instead if used in react component',
120+
name: "thirdweb",
121+
},
98122
],
99123
patterns: [
100124
{

apps/dashboard/src/@/components/contracts/functions/interactive-abi-function.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
toSerializableTransaction,
2121
toWei,
2222
} from "thirdweb";
23-
import { useActiveAccount, useSendAndConfirmTransaction } from "thirdweb/react";
23+
import { useActiveAccount } from "thirdweb/react";
2424
import { parseAbiParams, stringify, toFunctionSelector } from "thirdweb/utils";
2525
import { FormFieldSetup } from "@/components/blocks/FormFieldSetup";
2626
import { SolidityInput } from "@/components/solidity-inputs";
@@ -34,6 +34,7 @@ import { Input } from "@/components/ui/input";
3434
import { Spinner } from "@/components/ui/Spinner";
3535
import { Skeleton } from "@/components/ui/skeleton";
3636
import { ToolTipLabel } from "@/components/ui/tooltip";
37+
import { useSendAndConfirmTx } from "@/hooks/useSendTx";
3738

3839
function formatResponseData(data: unknown): {
3940
type: "json" | "text";
@@ -264,7 +265,7 @@ export const InteractiveAbiFunction: React.FC<InteractiveAbiFunctionProps> = (
264265
data: mutationData,
265266
error: mutationError,
266267
isPending: mutationLoading,
267-
} = useSendAndConfirmTransaction();
268+
} = useSendAndConfirmTx();
268269

269270
const {
270271
mutate: readFn,

apps/dashboard/src/@/components/tx-button/MismatchButton.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { forwardRef, useCallback, useRef, useState } from "react";
1212
import { toast } from "sonner";
1313
import {
1414
prepareTransaction,
15+
// eslint-disable-next-line no-restricted-imports
1516
sendTransaction,
1617
type ThirdwebClient,
1718
toWei,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { useTheme } from "next-themes";
2+
import {
3+
type SendTransactionConfig,
4+
// eslint-disable-next-line no-restricted-imports
5+
useSendAndConfirmTransaction,
6+
} from "thirdweb/react";
7+
import { getSDKTheme } from "@/utils/sdk-component-theme";
8+
9+
export function useSendAndConfirmTx(config?: SendTransactionConfig) {
10+
const { theme } = useTheme();
11+
const sendAndConfirmTransaction = useSendAndConfirmTransaction({
12+
payModal: {
13+
theme: getSDKTheme(theme === "light" ? "light" : "dark"),
14+
},
15+
...config,
16+
});
17+
18+
return sendAndConfirmTransaction;
19+
}

apps/dashboard/src/@/hooks/useSplit.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
type Chain,
1010
getAddress,
1111
NATIVE_TOKEN_ADDRESS,
12-
sendAndConfirmTransaction,
1312
type ThirdwebClient,
1413
type ThirdwebContract,
1514
} from "thirdweb";
@@ -21,6 +20,7 @@ import { getWalletBalance } from "thirdweb/wallets";
2120
import invariant from "tiny-invariant";
2221
import { parseError } from "../utils/errorParser";
2322
import { tryCatch } from "../utils/try-catch";
23+
import { useSendAndConfirmTx } from "./useSendTx";
2424

2525
function getTokenBalancesQuery(params: {
2626
ownerAddress: string;
@@ -79,6 +79,7 @@ export function useOwnedTokenBalances(params: {
7979
export function useSplitDistributeFunds(contract: ThirdwebContract) {
8080
const account = useActiveAccount();
8181
const queryClient = useQueryClient();
82+
const sendAndConfirmTx = useSendAndConfirmTx();
8283

8384
const params = {
8485
ownerAddress: contract.address, // because we want to fetch the balance of split contract
@@ -106,10 +107,7 @@ export function useSplitDistributeFunds(contract: ThirdwebContract) {
106107
contract,
107108
tokenAddress: currency.tokenAddress,
108109
});
109-
const promise = sendAndConfirmTransaction({
110-
account,
111-
transaction,
112-
});
110+
const promise = sendAndConfirmTx.mutateAsync(transaction);
113111

114112
toast.promise(promise, {
115113
error: (err) => ({

apps/dashboard/src/@/hooks/useVote.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import {
88
} from "thirdweb";
99
import * as ERC20Ext from "thirdweb/extensions/erc20";
1010
import * as VoteExt from "thirdweb/extensions/vote";
11-
import { useSendAndConfirmTransaction } from "thirdweb/react";
1211
import type { Account } from "thirdweb/wallets";
1312
import invariant from "tiny-invariant";
13+
import { useSendAndConfirmTx } from "@/hooks/useSendTx";
1414

1515
export async function tokensDelegated(
1616
options: BaseTransactionOptions<{ account: Account | undefined }>,
@@ -81,7 +81,7 @@ export async function votingTokenDecimals(options: BaseTransactionOptions) {
8181
}
8282

8383
export function useDelegateMutation() {
84-
const { mutateAsync } = useSendAndConfirmTransaction();
84+
const sendAndConfirmTx = useSendAndConfirmTx();
8585

8686
return useMutation({
8787
mutationFn: async (contract: ThirdwebContract) => {
@@ -97,7 +97,7 @@ export function useDelegateMutation() {
9797
contract: tokenContract,
9898
delegatee: contract.address,
9999
});
100-
return await mutateAsync(transaction);
100+
return await sendAndConfirmTx.mutateAsync(transaction);
101101
},
102102
});
103103
}

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/components/client/FaucetButton.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import type { Chain, ChainMetadata } from "thirdweb/chains";
1717
import {
1818
useActiveAccount,
1919
useActiveWalletChain,
20-
useSendTransaction,
2120
useSwitchActiveWalletChain,
2221
useWalletBalance,
2322
} from "thirdweb/react";
@@ -48,6 +47,7 @@ import {
4847
NEXT_PUBLIC_THIRDWEB_ENGINE_FAUCET_WALLET,
4948
NEXT_PUBLIC_TURNSTILE_SITE_KEY,
5049
} from "@/constants/public-envs";
50+
import { useSendAndConfirmTx } from "@/hooks/useSendTx";
5151
import { parseError } from "@/utils/errorParser";
5252
import { mapV4ChainToV5Chain } from "@/utils/map-chains";
5353

@@ -310,7 +310,7 @@ function SendFundsToFaucetModalContent(props: {
310310
const account = useActiveAccount();
311311
const activeChain = useActiveWalletChain();
312312
const switchActiveWalletChain = useSwitchActiveWalletChain();
313-
const sendTxMutation = useSendTransaction({
313+
const sendAndConfirmTx = useSendAndConfirmTx({
314314
payModal: false,
315315
});
316316
const switchChainMutation = useMutation({
@@ -334,7 +334,7 @@ function SendFundsToFaucetModalContent(props: {
334334
value: toWei(values.amount.toString()),
335335
});
336336

337-
const promise = sendTxMutation.mutateAsync(sendNativeTokenTx);
337+
const promise = sendAndConfirmTx.mutateAsync(sendNativeTokenTx);
338338

339339
toast.promise(promise, {
340340
error: `Failed to send ${values.amount} ${props.chainMeta.nativeCurrency.symbol} to faucet`,
@@ -404,11 +404,11 @@ function SendFundsToFaucetModalContent(props: {
404404
{activeChain.id === props.chain.id ? (
405405
<Button
406406
className="mt-4 w-full gap-2"
407-
disabled={sendTxMutation.isPending}
407+
disabled={sendAndConfirmTx.isPending}
408408
key="submit"
409409
type="submit"
410410
>
411-
{sendTxMutation.isPending && <Spinner className="size-4" />}
411+
{sendAndConfirmTx.isPending && <Spinner className="size-4" />}
412412
Send funds to faucet
413413
</Button>
414414
) : (

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/(marketplace)/components/cancel-tab.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import { toast } from "sonner";
33
import type { ThirdwebContract } from "thirdweb";
44
import { cancelAuction, cancelListing } from "thirdweb/extensions/marketplace";
5-
import { useSendAndConfirmTransaction } from "thirdweb/react";
65
import { TransactionButton } from "@/components/tx-button";
6+
import { useSendAndConfirmTx } from "@/hooks/useSendTx";
77

88
interface CancelTabProps {
99
id: string;
@@ -21,15 +21,15 @@ export const CancelTab: React.FC<CancelTabProps> = ({
2121
const transaction = isAuction
2222
? cancelAuction({ auctionId: BigInt(id), contract })
2323
: cancelListing({ contract, listingId: BigInt(id) });
24-
const cancelQuery = useSendAndConfirmTransaction();
24+
const sendAndConfirmTx = useSendAndConfirmTx();
2525
return (
2626
<TransactionButton
2727
className="self-end"
2828
client={contract.client}
2929
isLoggedIn={isLoggedIn}
30-
isPending={cancelQuery.isPending}
30+
isPending={sendAndConfirmTx.isPending}
3131
onClick={() => {
32-
const promise = cancelQuery.mutateAsync(transaction, {
32+
const promise = sendAndConfirmTx.mutateAsync(transaction, {
3333
onError: (error) => {
3434
console.error(error);
3535
},

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/(marketplace)/components/list-form.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import type {
2828
CreateListingParams,
2929
} from "thirdweb/extensions/marketplace";
3030
import { createAuction, createListing } from "thirdweb/extensions/marketplace";
31-
import { useActiveAccount, useSendAndConfirmTransaction } from "thirdweb/react";
31+
import { useActiveAccount } from "thirdweb/react";
3232
import { shortenAddress } from "thirdweb/utils";
3333
import { CurrencySelector } from "@/components/blocks/CurrencySelector";
3434
import { NFTMediaWithEmptyState } from "@/components/blocks/nft-media";
@@ -54,6 +54,7 @@ import {
5454
import { Skeleton } from "@/components/ui/skeleton";
5555
import { ToolTipLabel } from "@/components/ui/tooltip";
5656
import { useDashboardOwnedNFTs } from "@/hooks/useDashboardOwnedNFTs";
57+
import { useSendAndConfirmTx } from "@/hooks/useSendTx";
5758
import { useTxNotifications } from "@/hooks/useTxNotifications";
5859
import { useOwnedNFTsInsight } from "@/hooks/useWalletNFTs";
5960
import { cn } from "@/lib/utils";
@@ -122,7 +123,7 @@ export const CreateListingsForm: React.FC<CreateListingsFormProps> = ({
122123
chain: contract.chain,
123124
});
124125

125-
const sendAndConfirmTx = useSendAndConfirmTransaction();
126+
const sendAndConfirmTx = useSendAndConfirmTx();
126127
const listingNotifications = useTxNotifications(
127128
"NFT listed Successfully",
128129
"Failed to list NFT",

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/_components/claim-conditions/claim-conditions-form/index.tsx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ import {
2828
ZERO_ADDRESS,
2929
} from "thirdweb";
3030
import { decimals } from "thirdweb/extensions/erc20";
31-
import {
32-
useActiveAccount,
33-
useReadContract,
34-
useSendAndConfirmTransaction,
35-
} from "thirdweb/react";
31+
import { useActiveAccount, useReadContract } from "thirdweb/react";
3632
import invariant from "tiny-invariant";
3733
import * as z from "zod";
3834
import { ZodError } from "zod";
@@ -49,6 +45,7 @@ import { Form } from "@/components/ui/form";
4945
import { Spinner } from "@/components/ui/Spinner";
5046
import { ToolTipLabel } from "@/components/ui/tooltip";
5147
import { useIsAdmin } from "@/hooks/useContractRoles";
48+
import { useSendAndConfirmTx } from "@/hooks/useSendTx";
5249
import { useTxNotifications } from "@/hooks/useTxNotifications";
5350
import {
5451
type ClaimConditionInput,
@@ -222,7 +219,7 @@ export const ClaimConditionsForm: React.FC<ClaimConditionsFormProps> = ({
222219
Record<number, SnapshotEntry[] | undefined>
223220
>({});
224221

225-
const sendTx = useSendAndConfirmTransaction();
222+
const sendAndConfirmTx = useSendAndConfirmTx();
226223

227224
const tokenDecimals = useReadContract(decimals, {
228225
contract,
@@ -305,7 +302,7 @@ export const ClaimConditionsForm: React.FC<ClaimConditionsFormProps> = ({
305302

306303
const isFetchingData =
307304
claimConditionsQuery.isFetching ||
308-
sendTx.isPending ||
305+
sendAndConfirmTx.isPending ||
309306
// Need to make sure the tokenDecimals.data is present when interacting with ERC20 claim conditions
310307
(isErc20 && tokenDecimals.isLoading);
311308

@@ -428,7 +425,7 @@ export const ClaimConditionsForm: React.FC<ClaimConditionsFormProps> = ({
428425
},
429426
phasesWithSnapshots,
430427
);
431-
await sendTx.mutateAsync(tx);
428+
await sendAndConfirmTx.mutateAsync(tx);
432429

433430
saveClaimPhaseNotification.onSuccess();
434431
} catch (error) {
@@ -559,7 +556,7 @@ export const ClaimConditionsForm: React.FC<ClaimConditionsFormProps> = ({
559556
>
560557
<ClaimConditionsPhase
561558
contract={contract}
562-
isPending={sendTx.isPending}
559+
isPending={sendAndConfirmTx.isPending}
563560
onRemove={() => {
564561
formFields.remove(index);
565562
// Clean up snapshot when phase is removed
@@ -594,7 +591,8 @@ export const ClaimConditionsForm: React.FC<ClaimConditionsFormProps> = ({
594591
<DropdownMenuTrigger asChild>
595592
<Button
596593
disabled={
597-
sendTx.isPending || (!isMultiPhase && phases?.length > 0)
594+
sendAndConfirmTx.isPending ||
595+
(!isMultiPhase && phases?.length > 0)
598596
}
599597
size="sm"
600598
variant="outline"
@@ -649,7 +647,7 @@ export const ClaimConditionsForm: React.FC<ClaimConditionsFormProps> = ({
649647
client={contract.client}
650648
disabled={claimConditionsQuery.isPending}
651649
isLoggedIn={isLoggedIn}
652-
isPending={sendTx.isPending}
650+
isPending={sendAndConfirmTx.isPending}
653651
transactionCount={undefined}
654652
txChainID={contract.chain.id}
655653
type="submit"

0 commit comments

Comments
 (0)