Skip to content

Commit bfa0a42

Browse files
[SDK] Fix TransactionWidget when wallet has enough currency (#7656)
1 parent 426bb8b commit bfa0a42

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

.changeset/lucky-ravens-hope.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+
Fix TransactionWidget when wallet has enough currency for the transaction

apps/playground-web/src/components/pay/transaction-button.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export function PayTransactionPreview() {
4141

4242
return (
4343
<TransactionWidget
44-
amount={"0.001"}
4544
client={THIRDWEB_CLIENT}
4645
description={nft?.metadata?.description}
4746
image={nft?.metadata?.image}

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,26 @@ export function TransactionPayment({
361361
fullWidth
362362
onClick={() => {
363363
if (transactionDataQuery.data?.tokenInfo) {
364+
if (
365+
userBalance &&
366+
Number(userBalance) <
367+
Number(transactionDataQuery.data.totalCost)
368+
) {
369+
// if user has funds, but not enough, we need to fund the wallet with the difference
370+
onContinue(
371+
(
372+
Number(transactionDataQuery.data.totalCost) -
373+
Number(userBalance)
374+
).toString(),
375+
transactionDataQuery.data.tokenInfo,
376+
getAddress(activeAccount.address),
377+
);
378+
return;
379+
}
380+
381+
// otherwise, use the full transaction cost
364382
onContinue(
365-
Math.max(
366-
0,
367-
Number(transactionDataQuery.data.totalCost) -
368-
Number(userBalance ?? "0"),
369-
).toString(),
383+
transactionDataQuery.data.totalCost,
370384
transactionDataQuery.data.tokenInfo,
371385
getAddress(activeAccount.address),
372386
);

0 commit comments

Comments
 (0)