Skip to content

Commit 5d71415

Browse files
[SDK] Fix: PayEmbed purchase callback and insufficient funds display (#5918)
1 parent bfc4778 commit 5d71415

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

.changeset/fluffy-rings-kick.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 PayEmbed purchase success callback and insufficient funds displayed when no metadata is passed in

packages/thirdweb/src/react/core/hooks/connection/ConnectButtonProps.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { SupportedFiatCurrency } from "../../../../pay/convert/type.js";
77
import type { FiatProvider } from "../../../../pay/utils/commonTypes.js";
88
import type { AssetTabs } from "../../../../react/web/ui/ConnectWallet/screens/ViewAssets.js";
99
import type { PreparedTransaction } from "../../../../transaction/prepare-transaction.js";
10+
import type { Hex } from "../../../../utils/encoding/hex.js";
1011
import type { Prettify } from "../../../../utils/type-utils.js";
1112
import type { Account, Wallet } from "../../../../wallets/interfaces/wallet.js";
1213
import type { SmartWalletOptions } from "../../../../wallets/smart/types.js";
@@ -114,6 +115,11 @@ export type PayUIOptions = Prettify<
114115
| {
115116
type: "fiat";
116117
status: BuyWithFiatStatus;
118+
}
119+
| {
120+
type: "transaction";
121+
chainId: number;
122+
transactionHash: Hex;
117123
},
118124
) => void;
119125
/**

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { sendTransaction } from "../../../../transaction/actions/send-transactio
88
import type { WaitForReceiptOptions } from "../../../../transaction/actions/wait-for-tx-receipt.js";
99
import type { PreparedTransaction } from "../../../../transaction/prepare-transaction.js";
1010
import { getTransactionGasCost } from "../../../../transaction/utils.js";
11+
import type { Hex } from "../../../../utils/encoding/hex.js";
1112
import { resolvePromisedValue } from "../../../../utils/promise/resolve-promised-value.js";
1213
import type { Wallet } from "../../../../wallets/interfaces/wallet.js";
1314
import { getTokenBalance } from "../../../../wallets/utils/getTokenBalance.js";
@@ -74,6 +75,11 @@ export type SendTransactionPayModalConfig =
7475
| {
7576
type: "fiat";
7677
status: BuyWithFiatStatus;
78+
}
79+
| {
80+
type: "transaction";
81+
chainId: number;
82+
transactionHash: Hex;
7783
},
7884
) => void;
7985
}

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ export function TransactionModeScreen(props: {
125125
return <LoadingScreen />;
126126
}
127127

128+
const insufficientFunds =
129+
balanceQuery.data &&
130+
balanceQuery.data.value < transactionCostAndData.transactionValueWei;
131+
128132
return (
129133
<Container p="lg">
130134
<ModalHeader title={metadata?.name || "Transaction"} />
@@ -144,9 +148,11 @@ export function TransactionModeScreen(props: {
144148
/>
145149
) : activeAccount ? (
146150
<Container flex="column" gap="sm">
147-
<Text size="sm" color="danger" style={{ textAlign: "center" }}>
148-
Insufficient funds
149-
</Text>
151+
{insufficientFunds && (
152+
<Text size="sm" color="danger" style={{ textAlign: "center" }}>
153+
Insufficient funds
154+
</Text>
155+
)}
150156
<Container
151157
flex="row"
152158
style={{

packages/thirdweb/src/react/web/ui/PayEmbed.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,13 @@ export function PayEmbed(props: PayEmbedProps) {
365365
onBack={() => {
366366
setScreen("buy");
367367
}}
368-
onTxSent={() => {}}
368+
onTxSent={(data) => {
369+
props.payOptions?.onPurchaseSuccess?.({
370+
type: "transaction",
371+
chainId: data.chain.id,
372+
transactionHash: data.transactionHash,
373+
});
374+
}}
369375
/>
370376
)}
371377
</>

0 commit comments

Comments
 (0)