Hooks
useSwapModal
Hook for opening the swap modal
Import
Usage
Return Type: UseSwapModalReturnType
The hook returns an object with the following properties:
Properties
openSwapModal
(settings: SwapModalSettings) => void
Function to open the Swap modal with the specified settings.
Parameters:
The settings
object can include the following properties:
Parameter | Type | Description |
---|---|---|
chainId | number | Blockchain network ID where the swap will occur |
currencyAddress | string | Address of the target token contract |
currencyAmount | string | Amount of the target token in smallest units |
postSwapTransactions | Array<{to: string, data: string}> | (Optional) Transactions to execute after the swap completes |
disableMainCurrency | boolean | (Optional) If true, disables swapping using the main currency of the chain |
title | string | (Optional) Custom title for the swap modal |
description | string | (Optional) Custom description for the swap modal |
onSuccess | () => void | (Optional) Callback when swap is successful |
onError | (error: Error) => void | (Optional) Callback when an error occurs |
onClose | () => void | (Optional) Callback when the modal is closed |
blockConfirmations | number | (Optional) Number of block confirmations to wait for the swap to complete |
closeSwapModal
() => void
Function to close the Swap modal.
swapModalSettings
SwapModalSettings | undefined
The current settings configuration for the Swap modal.
Notes
This hook provides methods to control the Swap modal that allows users to swap tokens in their wallet to a target currency. The Swap modal enables users to select tokens from their wallet to swap to a specified target token, with the option to execute additional transactions after the swap completes.
Was this page helpful?