Skip to content

Commit c91cc5a

Browse files
[PayEmbed] Only onramp for required transaction amount
1 parent cbb1569 commit c91cc5a

File tree

6 files changed

+13
-5
lines changed

6 files changed

+13
-5
lines changed

.changeset/cyan-kids-hide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Only onramp for the amount required for transaction flows in PayEmbed

packages/thirdweb/src/bridge/Buy.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("Bridge.Buy.quote", () => {
3535
});
3636
});
3737

38-
describe("Bridge.Buy.prepare", () => {
38+
describe.runIf(process.env.TW_SECRET_KEY)("Bridge.Buy.prepare", () => {
3939
it("should get a valid prepared quote", async () => {
4040
const quote = await Buy.prepare({
4141
originChainId: 1,

packages/thirdweb/src/bridge/Sell.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("Bridge.Sell.quote", () => {
3535
});
3636
});
3737

38-
describe("Bridge.Sell.prepare", () => {
38+
describe.runIf(process.env.TW_SECRET_KEY)("Bridge.Sell.prepare", () => {
3939
it("should get a valid prepared quote", async () => {
4040
const quote = await Sell.prepare({
4141
originChainId: 1,

packages/thirdweb/src/pay/buyWithCrypto/getQuote.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ export async function getBuyWithCryptoQuote(
259259
data: data.transactionRequest.data as Hash,
260260
to: data.transactionRequest.to,
261261
value: BigInt(data.transactionRequest.value),
262-
gas: BigInt(data.transactionRequest.gasLimit),
262+
gas: undefined, // ignore gas returned by the quote, we handle it ourselves
263263
gasPrice: undefined, // ignore gas price returned by the quote, we handle it ourselves
264264
},
265265
approvalData,

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ function SelectedTokenInfo(props: {
625625
disabled?: boolean;
626626
}) {
627627
const getWidth = () => {
628-
const amount = formatNumber(Number(props.tokenAmount), 5).toString();
628+
const amount = formatNumber(Number(props.tokenAmount), 6).toString();
629629
let chars = amount.replace(".", "").length;
630630
const hasDot = amount.includes(".");
631631
if (hasDot) {

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/TransactionModeScreen.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,10 @@ export function TransactionModeScreen(props: {
334334
variant="accent"
335335
fullWidth
336336
onClick={() => {
337-
let totalCostWei = transactionCostAndData.transactionValueWei;
337+
let totalCostWei = insufficientFunds
338+
? transactionCostAndData.transactionValueWei -
339+
(balanceQuery.data?.value || 0n)
340+
: transactionCostAndData.transactionValueWei;
338341
if (
339342
transactionCostAndData.token.address === NATIVE_TOKEN_ADDRESS &&
340343
!sponsoredTransactionsEnabled

0 commit comments

Comments
 (0)