Skip to content

[SDK] Always show pay modal even on non-supported UB chains #7092

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 61 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
efc4687
[SDK] Feature: Switch buyWithCrypto to Universal Bridge service
gregfromstl May 15, 2025
6744d0a
[SDK] Feature: Add Bridge.Transfer module
gregfromstl May 15, 2025
77ad035
changeset
gregfromstl May 15, 2025
2c33488
Merge branch 'main' into greg/tool-4362-switch-payembed-to-ub-service
gregfromstl May 15, 2025
02b1c4a
[SDK] Update Routes endpoint for transaction pay modal
gregfromstl May 15, 2025
8112650
changeset
gregfromstl May 15, 2025
dfe29f0
lint
gregfromstl May 15, 2025
421d959
chore: use configured bridge domain
gregfromstl May 15, 2025
cdaf130
max limit, domains
joaquim-verges May 16, 2025
91de2cc
add icon, duration
joaquim-verges May 16, 2025
727d0e9
fix approval, minimal status adapter
joaquim-verges May 16, 2025
abd77ec
refactor: update import for Transfer module in getTransfer.ts
gregfromstl May 16, 2025
1b00833
Merge branch 'greg/tool-4506-update-routes-endpoint' of https://githu…
gregfromstl May 16, 2025
6eff0e0
[Docs] Stylus dev workflow (#7060)
kumaryash90 May 15, 2025
ea05f7d
[SDK] Export prepareUserOp and add support for new wallets (#7061)
joaquim-verges May 15, 2025
57ecf61
[Vault] default to engine-cloud vault proxy (#7058)
d4mr May 15, 2025
05516bd
[Docs] Engine (#7057)
saminacodes May 16, 2025
267feda
[DOCS] fix link in contributing.md (#7063)
gap-editor May 16, 2025
c4a9fac
[Engine] Add FAILED status to execution result and update error handl…
joaquim-verges May 16, 2025
a7c1257
[Engine] Add all testnets to test transaction options (#7066)
joaquim-verges May 16, 2025
378993b
[Docs] Engine Update (#7052)
saminacodes May 16, 2025
e701530
[SDK] Fix buyWithCrypto false not respected when returning from quote…
joaquim-verges May 16, 2025
4bc4caf
[Dashboard] Add pagination to server wallets page (#7070)
joaquim-verges May 16, 2025
b953056
Version Packages (#7042)
joaquim-verges May 16, 2025
72bc53b
[SDK] Update package READMEs with correct naming and documentation li…
joaquim-verges May 16, 2025
c6af295
Prioritize JWT over service API keys in authentication (#7020)
jnsdls May 16, 2025
58ca5f7
chore: Update Accelerate features list (#7053)
arcoraven May 17, 2025
b128358
Version Packages (#7073)
joaquim-verges May 17, 2025
6d8d185
[Dashboard] Remove taint for THIRDWEB_ENGINE_URL (#7074)
joaquim-verges May 17, 2025
197d85b
update status endpoint
joaquim-verges May 17, 2025
8aa198b
fix 0 balance issue
joaquim-verges May 17, 2025
638dddc
lint
joaquim-verges May 17, 2025
2e6ad54
Merge remote-tracking branch 'origin' into greg/tool-4506-update-rout…
joaquim-verges May 17, 2025
4eeca27
fix
joaquim-verges May 17, 2025
8bcecf5
fix test
joaquim-verges May 17, 2025
f989121
remove tx history, show 0 fees for now
joaquim-verges May 18, 2025
a2a8723
onramp endpoint wrapper
joaquim-verges May 19, 2025
c2bbb0d
status
joaquim-verges May 19, 2025
cec95b0
export
joaquim-verges May 19, 2025
e89ff31
adapt buyWithFiat legacy function
joaquim-verges May 19, 2025
7da5372
Merge remote-tracking branch 'origin/main' into joaquim/onramp
joaquim-verges May 19, 2025
2b2b6cc
remove kado, fixes
joaquim-verges May 19, 2025
a1f5b91
state cleanup
joaquim-verges May 19, 2025
1c64203
update status legacy function
joaquim-verges May 19, 2025
388eeb9
changeset
joaquim-verges May 19, 2025
751746c
lint
joaquim-verges May 19, 2025
df465f1
remove test
joaquim-verges May 19, 2025
696bff4
fix exports
joaquim-verges May 19, 2025
f3cb4a0
export type
joaquim-verges May 19, 2025
3d912bd
more export
joaquim-verges May 19, 2025
de79cf9
comments
joaquim-verges May 19, 2025
87a01f4
init new deposit modal flow
joaquim-verges May 19, 2025
6fea818
UI polish + auto refresh
joaquim-verges May 20, 2025
d7c31f6
Merge remote-tracking branch 'origin/main' into joaquim/always-show-m…
joaquim-verges May 20, 2025
d956b92
changeset
joaquim-verges May 20, 2025
ea02e6c
comments
joaquim-verges May 20, 2025
0bb8138
add utm
joaquim-verges May 20, 2025
c516ec5
Merge branch 'main' into joaquim/always-show-modal
jnsdls May 20, 2025
51f10c4
add playground example
joaquim-verges May 20, 2025
1a60000
improvements
joaquim-verges May 20, 2025
60eef9a
build
joaquim-verges May 20, 2025
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/sharp-symbols-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Show deposit modal for tokens that don't have any UB routes
25 changes: 24 additions & 1 deletion apps/playground-web/src/components/pay/transaction-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import { useTheme } from "next-themes";
import { getContract } from "thirdweb";
import { base, polygon } from "thirdweb/chains";
import { prepareTransaction } from "thirdweb";
import { base, baseSepolia, polygon } from "thirdweb/chains";
import { transfer } from "thirdweb/extensions/erc20";
import { claimTo, getNFT } from "thirdweb/extensions/erc1155";
import {
Expand All @@ -12,6 +13,7 @@ import {
useActiveAccount,
useReadContract,
} from "thirdweb/react";
import { toWei } from "thirdweb/utils";
import { THIRDWEB_CLIENT } from "../../lib/client";
import { StyledConnectButton } from "../styled-connect-button";

Expand Down Expand Up @@ -99,6 +101,27 @@ export function PayTransactionButtonPreview() {
>
Buy VIP Pass
</TransactionButton>
<div className="h-10" />
<div className="flex items-center gap-2">Price: 0.1 ETH</div>
<TransactionButton
transaction={() => {
if (!account) throw new Error("No active account");
return prepareTransaction({
chain: baseSepolia,
client: THIRDWEB_CLIENT,
to: account.address,
value: toWei("0.1"),
});
}}
onError={(e) => {
console.error(e);
}}
payModal={{
theme: theme === "light" ? "light" : "dark",
}}
>
Send 0.1 ETH
</TransactionButton>
</div>
)}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ The `quote` object contains detailed transaction information including the estim

</Step>
<Step title='Check for a Buy With Crypto Step'>
The `quote` object contains `quote.onRampToken` and `quote.toToken` objects containing intermediate and detination token information.
The `quote` object contains `quote.onRampToken` and `quote.toToken` objects containing intermediate and destination token information.

If `quote.onRampToken` is not the same as `quote.toToken`, then your users will need to onramp to intermediary token before arriving at their destination token.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
};

export type ShowModalData = {
mode: "buy" | "deposit";
tx: PreparedTransaction;
sendTx: () => void;
rejectTx: (reason: Error) => void;
Expand Down Expand Up @@ -184,47 +185,6 @@
resolvePromisedValue(tx.erc20Value),
]);

const supportedDestinations = await Bridge.routes({
client: tx.client,
destinationChainId: tx.chain.id,
destinationTokenAddress: _erc20Value?.tokenAddress,
}).catch((err) => {
trackPayEvent({
client: tx.client,
walletAddress: account.address,
walletType: wallet?.id,
toChainId: tx.chain.id,
event: "pay_transaction_modal_pay_api_error",
error: err?.message,
});
return null;
});

if (!supportedDestinations) {
// could not fetch supported destinations, just send the tx
sendTx();
return;
}

if (supportedDestinations.length === 0) {
trackPayEvent({
client: tx.client,
walletAddress: account.address,
walletType: wallet?.id,
toChainId: tx.chain.id,
toToken: _erc20Value?.tokenAddress || undefined,
event: "pay_transaction_modal_chain_token_not_supported",
error: JSON.stringify({
chain: tx.chain.id,
token: _erc20Value?.tokenAddress,
message: "chain/token not supported",
}),
});
// chain/token not supported, just send the tx
sendTx();
return;
}

const nativeValue = _nativeValue || 0n;
const erc20Value = _erc20Value?.amountWei || 0n;

Expand Down Expand Up @@ -256,7 +216,54 @@
(nativeCost > 0n && nativeBalance.value < nativeCost);

if (shouldShowModal) {
const supportedDestinations = await Bridge.routes({
client: tx.client,
destinationChainId: tx.chain.id,
destinationTokenAddress: _erc20Value?.tokenAddress,
}).catch((err) => {
trackPayEvent({
client: tx.client,
walletAddress: account.address,
walletType: wallet?.id,
toChainId: tx.chain.id,
event: "pay_transaction_modal_pay_api_error",
error: err?.message,
});
return null;
});

Check warning on line 233 in packages/thirdweb/src/react/core/hooks/transaction/useSendTransaction.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/core/hooks/transaction/useSendTransaction.ts#L219-L233

Added lines #L219 - L233 were not covered by tests

if (
!supportedDestinations ||
supportedDestinations.length === 0
) {

Check warning on line 238 in packages/thirdweb/src/react/core/hooks/transaction/useSendTransaction.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/core/hooks/transaction/useSendTransaction.ts#L235-L238

Added lines #L235 - L238 were not covered by tests
// not a supported destination -> show deposit screen
trackPayEvent({
client: tx.client,
walletAddress: account.address,
walletType: wallet?.id,
toChainId: tx.chain.id,
toToken: _erc20Value?.tokenAddress || undefined,
event: "pay_transaction_modal_chain_token_not_supported",
error: JSON.stringify({
chain: tx.chain.id,
token: _erc20Value?.tokenAddress,
message: "chain/token not supported",
}),
});

Check warning on line 252 in packages/thirdweb/src/react/core/hooks/transaction/useSendTransaction.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/core/hooks/transaction/useSendTransaction.ts#L240-L252

Added lines #L240 - L252 were not covered by tests

showPayModal({
mode: "deposit",
tx,
sendTx,
rejectTx: reject,
resolveTx: resolve,
});
return;
}

Check warning on line 262 in packages/thirdweb/src/react/core/hooks/transaction/useSendTransaction.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/core/hooks/transaction/useSendTransaction.ts#L254-L262

Added lines #L254 - L262 were not covered by tests

// chain is supported, show buy mode
showPayModal({
mode: "buy",

Check warning on line 266 in packages/thirdweb/src/react/core/hooks/transaction/useSendTransaction.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/core/hooks/transaction/useSendTransaction.ts#L266

Added line #L266 was not covered by tests
tx,
sendTx,
rejectTx: reject,
Expand Down
15 changes: 15 additions & 0 deletions packages/thirdweb/src/react/core/utils/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,21 @@
sponsoredTransactionsEnabled = smartOptions.gasless;
}
}
if (options?.executionMode) {
const execMode = options.executionMode;
if (execMode.mode === "EIP4337") {
const smartOptions = execMode.smartAccount;
if (smartOptions && "sponsorGas" in smartOptions) {
sponsoredTransactionsEnabled = smartOptions.sponsorGas;
}
if (smartOptions && "gasless" in smartOptions) {
sponsoredTransactionsEnabled = smartOptions.gasless;
}
}
if (execMode.mode === "EIP7702") {
sponsoredTransactionsEnabled = execMode.sponsorGas || false;
}
}

Check warning on line 261 in packages/thirdweb/src/react/core/utils/wallet.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/core/utils/wallet.ts#L248-L261

Added lines #L248 - L261 were not covered by tests
}
return sponsoredTransactionsEnabled;
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
localeId={payModal?.locale || "en_US"}
supportedTokens={payModal?.supportedTokens}
theme={payModal?.theme || "dark"}
modalMode={data.mode}

Check warning on line 124 in packages/thirdweb/src/react/web/hooks/transaction/useSendTransaction.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/hooks/transaction/useSendTransaction.tsx#L124

Added line #L124 was not covered by tests
payOptions={{
buyWithCrypto: payModal?.buyWithCrypto,
buyWithFiat: payModal?.buyWithFiat,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const connectLocaleEn: ConnectLocale = {
},
receiveFundsScreen: {
title: "Receive Funds",
instruction: "Copy the wallet address to send funds to this wallet",
instruction: "Copy the address to send funds to this wallet",
},
sendFundsScreen: {
title: "Send Funds",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ChainMetadata } from "../../../../../../../chains/types.js";
import type { BuyWithCryptoQuote } from "../../../../../../../pay/buyWithCrypto/getQuote.js";
import type { BuyWithFiatQuote } from "../../../../../../../pay/buyWithFiat/getQuote.js";
import type { GetWalletBalanceResult } from "../../../../../../../wallets/utils/getWalletBalance.js";
Expand All @@ -9,6 +10,7 @@ export type TransactionCostAndData = {
walletBalance: GetWalletBalanceResult;
transactionValueWei: bigint;
gasCostWei: bigint;
chainMetadata: ChainMetadata;
};

export type SelectedScreen =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
transaction: PreparedTransaction;
account: Account | undefined;
supportedDestinations: SupportedChainAndTokens;
refetchIntervalMs?: number;
}) {
const { transaction, account, supportedDestinations } = args;
// Compute query key of the transaction first
Expand Down Expand Up @@ -62,22 +63,24 @@

const erc20Value = await resolvePromisedValue(transaction.erc20Value);
if (erc20Value) {
const [tokenBalance, tokenMeta, gasCostWei] = await Promise.all([
getWalletBalance({
address: account.address,
chain: transaction.chain,
client: transaction.client,
tokenAddress: erc20Value.tokenAddress,
}),
getCurrencyMetadata({
contract: getContract({
address: erc20Value.tokenAddress,
const [tokenBalance, tokenMeta, gasCostWei, chainMetadata] =
await Promise.all([
getWalletBalance({
address: account.address,

Check warning on line 69 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.ts#L66-L69

Added lines #L66 - L69 were not covered by tests
chain: transaction.chain,
client: transaction.client,
tokenAddress: erc20Value.tokenAddress,

Check warning on line 72 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.ts#L72

Added line #L72 was not covered by tests
}),
}),
getTransactionGasCost(transaction, account?.address),
]);
getCurrencyMetadata({
contract: getContract({
address: erc20Value.tokenAddress,
chain: transaction.chain,
client: transaction.client,
}),
}),
getTransactionGasCost(transaction, account?.address),
getChainMetadata(transaction.chain),
]);

Check warning on line 83 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.ts#L74-L83

Added lines #L74 - L83 were not covered by tests
const transactionValueWei = erc20Value.amountWei;
const walletBalance = tokenBalance;
const currency = {
Expand All @@ -95,6 +98,7 @@
return {
token: currency,
decimals: tokenMeta.decimals,
chainMetadata,

Check warning on line 101 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.ts#L101

Added line #L101 was not covered by tests
walletBalance,
gasCostWei,
transactionValueWei,
Expand All @@ -121,19 +125,14 @@
symbol: chainMetadata.nativeCurrency.symbol,
icon: chainMetadata.icon?.url,
},
chainMetadata,

Check warning on line 128 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.ts#L128

Added line #L128 was not covered by tests
decimals: 18,
walletBalance,
gasCostWei,
transactionValueWei,
} satisfies TransactionCostAndData;
},
enabled: !!transaction && !!txQueryKey,
refetchInterval: () => {
if (transaction.erc20Value) {
// if erc20 value is set, we don't need to poll
return undefined;
}
return 30_000;
},
refetchInterval: args.refetchIntervalMs || 30_000,

Check warning on line 136 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.ts#L136

Added line #L136 was not covered by tests
});
}
Loading
Loading