Skip to content

[SDK] Fix TransactionWidget when wallet has enough currency #7656

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
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/lucky-ravens-hope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Fix TransactionWidget when wallet has enough currency for the transaction
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export function PayTransactionPreview() {

return (
<TransactionWidget
amount={"0.001"}
client={THIRDWEB_CLIENT}
description={nft?.metadata?.description}
image={nft?.metadata?.image}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,26 @@
fullWidth
onClick={() => {
if (transactionDataQuery.data?.tokenInfo) {
if (
userBalance &&
Number(userBalance) <
Number(transactionDataQuery.data.totalCost)
) {

Check warning on line 368 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#L364-L368

Added lines #L364 - L368 were not covered by tests
// if user has funds, but not enough, we need to fund the wallet with the difference
onContinue(

Check warning on line 370 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#L370

Added line #L370 was not covered by tests
(
Number(transactionDataQuery.data.totalCost) -
Number(userBalance)
).toString(),
transactionDataQuery.data.tokenInfo,
getAddress(activeAccount.address),
);
return;
}

Check warning on line 379 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#L372-L379

Added lines #L372 - L379 were not covered by tests

// otherwise, use the full transaction cost
onContinue(
Math.max(
0,
Number(transactionDataQuery.data.totalCost) -
Number(userBalance ?? "0"),
).toString(),
transactionDataQuery.data.totalCost,

Check warning on line 383 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#L383

Added line #L383 was not covered by tests
transactionDataQuery.data.tokenInfo,
getAddress(activeAccount.address),
);
Expand Down
Loading