-
Notifications
You must be signed in to change notification settings - Fork 574
[MNY-131] Add Pay Modal integration in useSendAndConfirmTransaction hook #7946
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
graphite-app
merged 1 commit into
main
from
08-29-_mny-131_add_pay_modal_integration_in_hook
Aug 29, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"thirdweb": patch | ||
--- | ||
|
||
Add Pay Modal integration in `useSendAndConfirmTransaction` hook similar to `useSendTransaction` hook | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
packages/thirdweb/src/react/web/hooks/transaction/useSendAndConfirmTransaction.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import { type UseMutationResult, useMutation } from "@tanstack/react-query"; | ||
import type { GaslessOptions } from "../../../../transaction/actions/gasless/types.js"; | ||
import type { SendTransactionOptions } from "../../../../transaction/actions/send-transaction.js"; | ||
import { waitForReceipt } from "../../../../transaction/actions/wait-for-tx-receipt.js"; | ||
import type { TransactionReceipt } from "../../../../transaction/types.js"; | ||
import type { SendTransactionPayModalConfig } from "../../../core/hooks/transaction/useSendTransaction.js"; | ||
import { useSendTransaction } from "./useSendTransaction.js"; | ||
|
||
MananTank marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/** | ||
* Configuration for the `useSendAndConfirmTransaction` hook. | ||
*/ | ||
type SendAndConfirmTransactionConfig = { | ||
/** | ||
* Refer to [`SendTransactionPayModalConfig`](https://portal.thirdweb.com/references/typescript/v5/SendTransactionPayModalConfig) for more details. | ||
*/ | ||
payModal?: SendTransactionPayModalConfig; | ||
|
||
/** | ||
* Configuration for gasless transactions. | ||
* Refer to [`GaslessOptions`](https://portal.thirdweb.com/references/typescript/v5/GaslessOptions) for more details. | ||
*/ | ||
gasless?: GaslessOptions; | ||
}; | ||
|
||
/** | ||
* A hook to send a transaction and confirm the transaction with users's connected wallet | ||
* @returns A mutation object to send a transaction. | ||
* @example | ||
* ```jsx | ||
* import { useSendAndConfirmTransaction } from "thirdweb/react"; | ||
* const { mutate: sendAndConfirmTx, data: transactionReceipt } = useSendAndConfirmTransaction(); | ||
* | ||
* // later | ||
* sendAndConfirmTx(tx); | ||
* ``` | ||
* | ||
* | ||
* ### Gasless usage with [thirdweb Engine](https://portal.thirdweb.com/engine) | ||
* ```tsx | ||
* import { useSendAndConfirmTransaction } from "thirdweb/react"; | ||
* const mutation = useSendAndConfirmTransaction({ | ||
* gasless: { | ||
* provider: "engine", | ||
* relayerUrl: "https://thirdweb.engine-***.thirdweb.com/relayer/***", | ||
* relayerForwarderAddress: "0x...", | ||
* } | ||
* }); | ||
* ``` | ||
* | ||
* ### Gasless usage with OpenZeppelin | ||
* ```tsx | ||
* import { useSendAndConfirmTransaction } from "thirdweb/react"; | ||
* const mutation = useSendAndConfirmTransaction({ | ||
* gasless: { | ||
* provider: "openzeppelin", | ||
* relayerUrl: "https://...", | ||
* relayerForwarderAddress: "0x...", | ||
* } | ||
* }); | ||
* ``` | ||
* | ||
* ### Configuring the Pay Modal | ||
* | ||
* When the wallet does not have enough funds to send the transaction, a modal is shown to the user to buy the required funds and then continue with the transaction. | ||
* | ||
* You can configure the pay modal by passing a [`SendTransactionPayModalConfig`](https://portal.thirdweb.com/references/typescript/v5/SendTransactionPayModalConfig) object to the `payModal` config. | ||
* | ||
* ```tsx | ||
* import { useSendAndConfirmTransaction } from "thirdweb/react"; | ||
* | ||
* const sendAndConfirmTx = useSendAndConfirmTransaction({ | ||
* payModal: { | ||
* theme: "light", | ||
* }, | ||
* }); | ||
* ``` | ||
* | ||
* By default, the pay modal is enabled. You can disable it by passing `payModal: false` to the config. | ||
* | ||
* ```tsx | ||
* import { useSendAndConfirmTransaction } from "thirdweb/react"; | ||
* | ||
* const sendAndConfirmTx = useSendAndConfirmTransaction({ | ||
* payModal: false, | ||
* }); | ||
* ``` | ||
* @transaction | ||
*/ | ||
export function useSendAndConfirmTransaction( | ||
config: SendAndConfirmTransactionConfig = {}, | ||
): UseMutationResult< | ||
TransactionReceipt, | ||
Error, | ||
SendTransactionOptions["transaction"] | ||
MananTank marked this conversation as resolved.
Show resolved
Hide resolved
|
||
> { | ||
const sendTx = useSendTransaction(config); | ||
return useMutation({ | ||
mutationFn: async (transaction) => { | ||
const receipt = await sendTx.mutateAsync(transaction); | ||
const confirmedReceipt = await waitForReceipt(receipt); | ||
return confirmedReceipt; | ||
}, | ||
Check warning on line 102 in packages/thirdweb/src/react/web/hooks/transaction/useSendAndConfirmTransaction.tsx
|
||
}); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.