Skip to content
Merged
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
24 changes: 24 additions & 0 deletions apps/dashboard/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,30 @@ module.exports = {
'Import "posthog-js" directly only within the analytics helpers ("src/@/analytics/*"). Use the exported helpers from "@/analytics/track" elsewhere.',
name: "posthog-js",
},
{
importNames: ["useSendTransaction"],
message:
'Use `import { useSendAndConfirmTx } from "@/hooks/useSendTx";` instead',
name: "thirdweb/react",
},
{
importNames: ["useSendAndConfirmTransaction"],
message:
'Use `import { useSendAndConfirmTx } from "@/hooks/useSendTx";` instead',
name: "thirdweb/react",
},
{
importNames: ["sendTransaction"],
message:
'Use `import { useSendAndConfirmTx } from "@/hooks/useSendTx";` instead if used in react component',
name: "thirdweb",
},
{
importNames: ["sendAndConfirmTransaction"],
message:
'Use `import { useSendAndConfirmTx } from "@/hooks/useSendTx";` instead if used in react component',
name: "thirdweb",
},
],
patterns: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
toSerializableTransaction,
toWei,
} from "thirdweb";
import { useActiveAccount, useSendAndConfirmTransaction } from "thirdweb/react";
import { useActiveAccount } from "thirdweb/react";
import { parseAbiParams, stringify, toFunctionSelector } from "thirdweb/utils";
import { FormFieldSetup } from "@/components/blocks/FormFieldSetup";
import { SolidityInput } from "@/components/solidity-inputs";
Expand All @@ -34,6 +34,7 @@ import { Input } from "@/components/ui/input";
import { Spinner } from "@/components/ui/Spinner";
import { Skeleton } from "@/components/ui/skeleton";
import { ToolTipLabel } from "@/components/ui/tooltip";
import { useSendAndConfirmTx } from "@/hooks/useSendTx";

function formatResponseData(data: unknown): {
type: "json" | "text";
Expand Down Expand Up @@ -264,7 +265,7 @@ export const InteractiveAbiFunction: React.FC<InteractiveAbiFunctionProps> = (
data: mutationData,
error: mutationError,
isPending: mutationLoading,
} = useSendAndConfirmTransaction();
} = useSendAndConfirmTx();

const {
mutate: readFn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { forwardRef, useCallback, useRef, useState } from "react";
import { toast } from "sonner";
import {
prepareTransaction,
// eslint-disable-next-line no-restricted-imports
sendTransaction,
type ThirdwebClient,
toWei,
Expand Down
19 changes: 19 additions & 0 deletions apps/dashboard/src/@/hooks/useSendTx.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { useTheme } from "next-themes";
import {
type SendTransactionConfig,
// eslint-disable-next-line no-restricted-imports
useSendAndConfirmTransaction,
} from "thirdweb/react";
import { getSDKTheme } from "@/utils/sdk-component-theme";

export function useSendAndConfirmTx(config?: SendTransactionConfig) {
const { theme } = useTheme();
const sendAndConfirmTransaction = useSendAndConfirmTransaction({
payModal: {
theme: getSDKTheme(theme === "light" ? "light" : "dark"),
},
...config,
});

return sendAndConfirmTransaction;
}
8 changes: 3 additions & 5 deletions apps/dashboard/src/@/hooks/useSplit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
type Chain,
getAddress,
NATIVE_TOKEN_ADDRESS,
sendAndConfirmTransaction,
type ThirdwebClient,
type ThirdwebContract,
} from "thirdweb";
Expand All @@ -21,6 +20,7 @@ import { getWalletBalance } from "thirdweb/wallets";
import invariant from "tiny-invariant";
import { parseError } from "../utils/errorParser";
import { tryCatch } from "../utils/try-catch";
import { useSendAndConfirmTx } from "./useSendTx";

function getTokenBalancesQuery(params: {
ownerAddress: string;
Expand Down Expand Up @@ -79,6 +79,7 @@ export function useOwnedTokenBalances(params: {
export function useSplitDistributeFunds(contract: ThirdwebContract) {
const account = useActiveAccount();
const queryClient = useQueryClient();
const sendAndConfirmTx = useSendAndConfirmTx();

const params = {
ownerAddress: contract.address, // because we want to fetch the balance of split contract
Expand Down Expand Up @@ -106,10 +107,7 @@ export function useSplitDistributeFunds(contract: ThirdwebContract) {
contract,
tokenAddress: currency.tokenAddress,
});
const promise = sendAndConfirmTransaction({
account,
transaction,
});
const promise = sendAndConfirmTx.mutateAsync(transaction);

toast.promise(promise, {
error: (err) => ({
Expand Down
6 changes: 3 additions & 3 deletions apps/dashboard/src/@/hooks/useVote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {
} from "thirdweb";
import * as ERC20Ext from "thirdweb/extensions/erc20";
import * as VoteExt from "thirdweb/extensions/vote";
import { useSendAndConfirmTransaction } from "thirdweb/react";
import type { Account } from "thirdweb/wallets";
import invariant from "tiny-invariant";
import { useSendAndConfirmTx } from "@/hooks/useSendTx";

export async function tokensDelegated(
options: BaseTransactionOptions<{ account: Account | undefined }>,
Expand Down Expand Up @@ -81,7 +81,7 @@ export async function votingTokenDecimals(options: BaseTransactionOptions) {
}

export function useDelegateMutation() {
const { mutateAsync } = useSendAndConfirmTransaction();
const sendAndConfirmTx = useSendAndConfirmTx();

return useMutation({
mutationFn: async (contract: ThirdwebContract) => {
Expand All @@ -97,7 +97,7 @@ export function useDelegateMutation() {
contract: tokenContract,
delegatee: contract.address,
});
return await mutateAsync(transaction);
return await sendAndConfirmTx.mutateAsync(transaction);
},
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import type { Chain, ChainMetadata } from "thirdweb/chains";
import {
useActiveAccount,
useActiveWalletChain,
useSendTransaction,
useSwitchActiveWalletChain,
useWalletBalance,
} from "thirdweb/react";
Expand Down Expand Up @@ -48,6 +47,7 @@ import {
NEXT_PUBLIC_THIRDWEB_ENGINE_FAUCET_WALLET,
NEXT_PUBLIC_TURNSTILE_SITE_KEY,
} from "@/constants/public-envs";
import { useSendAndConfirmTx } from "@/hooks/useSendTx";
import { parseError } from "@/utils/errorParser";
import { mapV4ChainToV5Chain } from "@/utils/map-chains";

Expand Down Expand Up @@ -310,7 +310,7 @@ function SendFundsToFaucetModalContent(props: {
const account = useActiveAccount();
const activeChain = useActiveWalletChain();
const switchActiveWalletChain = useSwitchActiveWalletChain();
const sendTxMutation = useSendTransaction({
const sendAndConfirmTx = useSendAndConfirmTx({
payModal: false,
});
const switchChainMutation = useMutation({
Expand All @@ -334,7 +334,7 @@ function SendFundsToFaucetModalContent(props: {
value: toWei(values.amount.toString()),
});

const promise = sendTxMutation.mutateAsync(sendNativeTokenTx);
const promise = sendAndConfirmTx.mutateAsync(sendNativeTokenTx);

toast.promise(promise, {
error: `Failed to send ${values.amount} ${props.chainMeta.nativeCurrency.symbol} to faucet`,
Expand Down Expand Up @@ -404,11 +404,11 @@ function SendFundsToFaucetModalContent(props: {
{activeChain.id === props.chain.id ? (
<Button
className="mt-4 w-full gap-2"
disabled={sendTxMutation.isPending}
disabled={sendAndConfirmTx.isPending}
key="submit"
type="submit"
>
{sendTxMutation.isPending && <Spinner className="size-4" />}
{sendAndConfirmTx.isPending && <Spinner className="size-4" />}
Send funds to faucet
</Button>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import { toast } from "sonner";
import type { ThirdwebContract } from "thirdweb";
import { cancelAuction, cancelListing } from "thirdweb/extensions/marketplace";
import { useSendAndConfirmTransaction } from "thirdweb/react";
import { TransactionButton } from "@/components/tx-button";
import { useSendAndConfirmTx } from "@/hooks/useSendTx";

interface CancelTabProps {
id: string;
Expand All @@ -21,15 +21,15 @@ export const CancelTab: React.FC<CancelTabProps> = ({
const transaction = isAuction
? cancelAuction({ auctionId: BigInt(id), contract })
: cancelListing({ contract, listingId: BigInt(id) });
const cancelQuery = useSendAndConfirmTransaction();
const sendAndConfirmTx = useSendAndConfirmTx();
return (
<TransactionButton
className="self-end"
client={contract.client}
isLoggedIn={isLoggedIn}
isPending={cancelQuery.isPending}
isPending={sendAndConfirmTx.isPending}
onClick={() => {
const promise = cancelQuery.mutateAsync(transaction, {
const promise = sendAndConfirmTx.mutateAsync(transaction, {
onError: (error) => {
console.error(error);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import type {
CreateListingParams,
} from "thirdweb/extensions/marketplace";
import { createAuction, createListing } from "thirdweb/extensions/marketplace";
import { useActiveAccount, useSendAndConfirmTransaction } from "thirdweb/react";
import { useActiveAccount } from "thirdweb/react";
import { shortenAddress } from "thirdweb/utils";
import { CurrencySelector } from "@/components/blocks/CurrencySelector";
import { NFTMediaWithEmptyState } from "@/components/blocks/nft-media";
Expand All @@ -54,6 +54,7 @@ import {
import { Skeleton } from "@/components/ui/skeleton";
import { ToolTipLabel } from "@/components/ui/tooltip";
import { useDashboardOwnedNFTs } from "@/hooks/useDashboardOwnedNFTs";
import { useSendAndConfirmTx } from "@/hooks/useSendTx";
import { useTxNotifications } from "@/hooks/useTxNotifications";
import { useOwnedNFTsInsight } from "@/hooks/useWalletNFTs";
import { cn } from "@/lib/utils";
Expand Down Expand Up @@ -122,7 +123,7 @@ export const CreateListingsForm: React.FC<CreateListingsFormProps> = ({
chain: contract.chain,
});

const sendAndConfirmTx = useSendAndConfirmTransaction();
const sendAndConfirmTx = useSendAndConfirmTx();
const listingNotifications = useTxNotifications(
"NFT listed Successfully",
"Failed to list NFT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ import {
ZERO_ADDRESS,
} from "thirdweb";
import { decimals } from "thirdweb/extensions/erc20";
import {
useActiveAccount,
useReadContract,
useSendAndConfirmTransaction,
} from "thirdweb/react";
import { useActiveAccount, useReadContract } from "thirdweb/react";
import invariant from "tiny-invariant";
import * as z from "zod";
import { ZodError } from "zod";
Expand All @@ -49,6 +45,7 @@ import { Form } from "@/components/ui/form";
import { Spinner } from "@/components/ui/Spinner";
import { ToolTipLabel } from "@/components/ui/tooltip";
import { useIsAdmin } from "@/hooks/useContractRoles";
import { useSendAndConfirmTx } from "@/hooks/useSendTx";
import { useTxNotifications } from "@/hooks/useTxNotifications";
import {
type ClaimConditionInput,
Expand Down Expand Up @@ -222,7 +219,7 @@ export const ClaimConditionsForm: React.FC<ClaimConditionsFormProps> = ({
Record<number, SnapshotEntry[] | undefined>
>({});

const sendTx = useSendAndConfirmTransaction();
const sendAndConfirmTx = useSendAndConfirmTx();

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

const isFetchingData =
claimConditionsQuery.isFetching ||
sendTx.isPending ||
sendAndConfirmTx.isPending ||
// Need to make sure the tokenDecimals.data is present when interacting with ERC20 claim conditions
(isErc20 && tokenDecimals.isLoading);

Expand Down Expand Up @@ -428,7 +425,7 @@ export const ClaimConditionsForm: React.FC<ClaimConditionsFormProps> = ({
},
phasesWithSnapshots,
);
await sendTx.mutateAsync(tx);
await sendAndConfirmTx.mutateAsync(tx);

saveClaimPhaseNotification.onSuccess();
} catch (error) {
Expand Down Expand Up @@ -559,7 +556,7 @@ export const ClaimConditionsForm: React.FC<ClaimConditionsFormProps> = ({
>
<ClaimConditionsPhase
contract={contract}
isPending={sendTx.isPending}
isPending={sendAndConfirmTx.isPending}
onRemove={() => {
formFields.remove(index);
// Clean up snapshot when phase is removed
Expand Down Expand Up @@ -594,7 +591,8 @@ export const ClaimConditionsForm: React.FC<ClaimConditionsFormProps> = ({
<DropdownMenuTrigger asChild>
<Button
disabled={
sendTx.isPending || (!isMultiPhase && phases?.length > 0)
sendAndConfirmTx.isPending ||
(!isMultiPhase && phases?.length > 0)
}
size="sm"
variant="outline"
Expand Down Expand Up @@ -649,7 +647,7 @@ export const ClaimConditionsForm: React.FC<ClaimConditionsFormProps> = ({
client={contract.client}
disabled={claimConditionsQuery.isPending}
isLoggedIn={isLoggedIn}
isPending={sendTx.isPending}
isPending={sendAndConfirmTx.isPending}
transactionCount={undefined}
txChainID={contract.chain.id}
type="submit"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import type { ThirdwebContract } from "thirdweb";
import * as ERC20Ext from "thirdweb/extensions/erc20";
import * as ERC721Ext from "thirdweb/extensions/erc721";
import * as ERC1155Ext from "thirdweb/extensions/erc1155";
import { useSendAndConfirmTransaction } from "thirdweb/react";
import { TransactionButton } from "@/components/tx-button";
import { ToolTipLabel } from "@/components/ui/tooltip";
import { useSendAndConfirmTx } from "@/hooks/useSendTx";
import { useTxNotifications } from "@/hooks/useTxNotifications";

export function ResetClaimEligibility({
Expand All @@ -23,7 +23,7 @@ export function ResetClaimEligibility({
isLoggedIn: boolean;
isMultiphase: boolean;
}) {
const sendTxMutation = useSendAndConfirmTransaction();
const sendAndConfirmTx = useSendAndConfirmTx();

const txNotification = useTxNotifications(
"Successfully reset claim eligibility",
Expand Down Expand Up @@ -52,7 +52,7 @@ export function ResetClaimEligibility({
}
})();

sendTxMutation.mutate(tx, {
sendAndConfirmTx.mutate(tx, {
onError: (error) => {
txNotification.onError(error);
},
Expand All @@ -70,7 +70,7 @@ export function ResetClaimEligibility({
<TransactionButton
client={contract.client}
isLoggedIn={isLoggedIn}
isPending={sendTxMutation.isPending}
isPending={sendAndConfirmTx.isPending}
onClick={handleResetClaimEligibility}
size="sm"
variant="outline"
Expand All @@ -79,7 +79,7 @@ export function ResetClaimEligibility({
type="button"
className="text-destructive-text bg-card"
>
{sendTxMutation.isPending ? (
{sendAndConfirmTx.isPending ? (
"Resetting Eligibility"
) : (
<div className="flex items-center gap-2">
Expand Down
Loading
Loading