Skip to content

[SDK] Handle sponsored gas on TransactionWidget #7437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2025
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
5 changes: 5 additions & 0 deletions .changeset/rude-bags-say.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Handle sponsored gas on TransactionWidget
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import { getTransactionGasCost } from "../../../transaction/utils.js";
import { resolvePromisedValue } from "../../../utils/promise/resolve-promised-value.js";
import { toTokens } from "../../../utils/units.js";
import type { Wallet } from "../../../wallets/interfaces/wallet.js";
import { hasSponsoredTransactionsEnabled } from "../../../wallets/smart/is-smart-wallet.js";
import {
formatCurrencyAmount,
formatTokenAmount,
Expand All @@ -40,6 +42,7 @@
interface UseTransactionDetailsOptions {
transaction: PreparedTransaction;
client: ThirdwebClient;
wallet: Wallet | undefined;
}

/**
Expand All @@ -49,8 +52,10 @@
export function useTransactionDetails({
transaction,
client,
wallet,

Check warning on line 55 in packages/thirdweb/src/react/core/hooks/useTransactionDetails.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/core/hooks/useTransactionDetails.ts#L55

Added line #L55 was not covered by tests
}: UseTransactionDetailsOptions) {
const chainMetadata = useChainMetadata(transaction.chain);
const hasSponsoredTransactions = hasSponsoredTransactionsEnabled(wallet);

Check warning on line 58 in packages/thirdweb/src/react/core/hooks/useTransactionDetails.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/core/hooks/useTransactionDetails.ts#L58

Added line #L58 was not covered by tests

return useQuery({
enabled: !!transaction.to && !!chainMetadata.data,
Expand All @@ -76,7 +81,9 @@
erc20Value ? erc20Value.tokenAddress : NATIVE_TOKEN_ADDRESS,
transaction.chain.id,
).catch(() => null),
getTransactionGasCost(transaction).catch(() => null),
hasSponsoredTransactions
? 0n
: getTransactionGasCost(transaction).catch(() => null),

Check warning on line 86 in packages/thirdweb/src/react/core/hooks/useTransactionDetails.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/core/hooks/useTransactionDetails.ts#L84-L86

Added lines #L84 - L86 were not covered by tests
]);

// Process function info from ABI if available
Expand Down Expand Up @@ -172,6 +179,7 @@
transaction.to,
transaction.chain.id,
transaction.erc20Value?.toString(),
hasSponsoredTransactions,

Check warning on line 182 in packages/thirdweb/src/react/core/hooks/useTransactionDetails.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/core/hooks/useTransactionDetails.ts#L182

Added line #L182 was not covered by tests
],
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import { useChainMetadata } from "../../../core/hooks/others/useChainQuery.js";
import { useTransactionDetails } from "../../../core/hooks/useTransactionDetails.js";
import { useActiveAccount } from "../../../core/hooks/wallets/useActiveAccount.js";
import { useActiveWallet } from "../../../core/hooks/wallets/useActiveWallet.js";
import { ConnectButton } from "../ConnectWallet/ConnectButton.js";
import { PoweredByThirdweb } from "../ConnectWallet/PoweredByTW.js";
import { Container, Line } from "../components/basic.js";
Expand Down Expand Up @@ -57,6 +58,7 @@
}: TransactionPaymentProps) {
const theme = useCustomTheme();
const activeAccount = useActiveAccount();
const wallet = useActiveWallet();

Check warning on line 61 in packages/thirdweb/src/react/web/ui/Bridge/TransactionPayment.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/Bridge/TransactionPayment.tsx#L61

Added line #L61 was not covered by tests

// Get chain metadata for native currency symbol
const chainMetadata = useChainMetadata(uiOptions.transaction.chain);
Expand All @@ -65,6 +67,7 @@
const transactionDataQuery = useTransactionDetails({
client,
transaction: uiOptions.transaction,
wallet,

Check warning on line 70 in packages/thirdweb/src/react/web/ui/Bridge/TransactionPayment.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/Bridge/TransactionPayment.tsx#L70

Added line #L70 was not covered by tests
});

const contractName =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
{props.uiOptions.mode === "transaction" && (
<TransactionOverViewCompact
client={props.client}
paymentMethod={props.paymentMethod}

Check warning on line 191 in packages/thirdweb/src/react/web/ui/Bridge/payment-details/PaymentOverview.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/Bridge/payment-details/PaymentOverview.tsx#L191

Added line #L191 was not covered by tests
uiOptions={props.uiOptions}
/>
)}
Expand All @@ -198,12 +199,14 @@

const TransactionOverViewCompact = (props: {
uiOptions: Extract<UIOptions, { mode: "transaction" }>;
paymentMethod: PaymentMethod;
client: ThirdwebClient;
}) => {
const theme = useCustomTheme();
const txInfo = useTransactionDetails({
client: props.client,
transaction: props.uiOptions.transaction,
wallet: props.paymentMethod.payerWallet,

Check warning on line 209 in packages/thirdweb/src/react/web/ui/Bridge/payment-details/PaymentOverview.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/Bridge/payment-details/PaymentOverview.tsx#L209

Added line #L209 was not covered by tests
});

if (!txInfo.data) {
Expand Down
Loading