Transactions
Actions
Transaction Management
addTransaction
: Adds a new transaction to the state. It requires the chain ID, transaction sender address (from
), transaction hash (hash
), additional transaction info (info
), and an optional summary of the transaction (summary
).clearAllTransactions
: Clears all transactions for a specified chain ID from the state.finalizeTransaction
: Marks a transaction as finalized (confirmed) in the state. It takes the chain ID, transaction hash, and a serializable receipt (receipt
) indicating the transaction has been included in a block and finalized.checkedTransaction
: Updates the state to indicate that a transaction's inclusion in a block has been checked up to a certain block number. It requires the chain ID, transaction hash, and the latest checked block number.updateTransaction
: Provides a comprehensive update to an existing transaction's details in the state. This action can be used to modify any aspect of a transaction after it has been added, based on new information or state changes. It requires an object combiningTransactionDetails
and the chain ID.
Hooks
useTransactionAdder
useTransactionAdder
Allows adding a transaction to the state with its hash, associated information, and an optional summary. This hook is crucial for tracking transactions initiated by the user.
Parameters:
hash
: The transaction hash.info
: Transaction information including type, spender, and token address.summary
: An optional summary of the transaction.
useAllTransactions
useAllTransactions
Retrieves all transactions associated with the current chain ID, providing a snapshot of user activity and transaction states.
useTransaction
useTransaction
Fetches details of a specific transaction identified by its hash. It returns undefined
if the hash is not provided or the transaction does not exist in the state.
Parameters:
transactionHash
: The hash of the transaction to retrieve.
isTransactionRecent
isTransactionRecent
Determines if a given transaction happened within the last day, helping to filter out older transactions from recent activity views.
Parameters:
tx
: The transaction to check for recency.
useIsTransactionPending
/ useIsTransactionConfirmed
useIsTransactionPending
/ useIsTransactionConfirmed
These hooks determine the pending or confirmed status of a transaction based on the presence of a receipt in the transaction details.
Parameters:
transactionHash
: The hash of the transaction to check.
useHasPendingApproval
useHasPendingApproval
Checks if there is a pending approval transaction for a specific token and spender. This hook is useful for UI elements that need to indicate pending approvals to the user.
Parameters:
token
: The token for which approval is being checked.spender
: The address of the spender.
useIsHavePendingTransaction
useIsHavePendingTransaction
Determines if there is any pending transaction of a specific type initiated by the user, providing insights into ongoing operations that haven't been finalized yet.
Parameters:
transactionType
: The type of transaction to check for pending status.
Types
SerializableTransactionReceipt
A simplified version of a transaction receipt that includes only the essential fields for serialization and storage in the application state.
to
: The address the transaction is directed to.from
: The address from which the transaction originates.contractAddress
: The contract address involved in the transaction.transactionIndex
,blockHash
,transactionHash
,blockNumber
: Blockchain-specific identifiers and indices.status
: The status of the transaction, which might be undefined before confirmation.
TransactionType
An enumeration of possible transaction types. This enum is critical for differentiating between various transaction actions (e.g., approvals, trades, collateral transfers) within the application. Each type is assigned a unique value to prevent conflicts and ensure consistency across the application state.
Note: Be careful adding to this enum, always assign a unique value as TypeScript will not prevent duplicate values. These values persist in state and if you change the value it will cause errors.
BaseTransactionInfo and Specific Transaction Info Interfaces
Defines a base interface for transaction information and extends it for specific transaction types (e.g., ApproveTransactionInfo
, TradeTransactionInfo
). These interfaces include fields relevant to the transaction type.
BaseTransactionInfo
ApproveTransactionInfo
tokenAddress
,spender
: Details for approval transactions.
TradeTransactionInfo
name
,state
,positionType
,slippage
: Details for trade transactions.amount
,price
,hedger
,id
: Common fields for trade transactions.
CancelQuoteTransactionInfo
positionType
,closeQuote
,hedger
: Additional details for cancelling quotes.
AddAccountTransactionInfo
name
: Name of the account being added.
SignMessageTransactionInfo
text
: Content for sign message transactions.
TransferCollateralTransactionInfo
transferType
,amount
,accountName
,accountAddress
: Details for collateral transfer transactions.
MintTransactionInfo
amount
: Amount of tokens to be minted.
TransactionInfo
A union type of all specific transaction info interfaces.
TransactionDetails
Encapsulates all details about a transaction, including its hash, an optional summary, a possible receipt, and timestamps indicating when the transaction was added and possibly confirmed.
hash
: The unique identifier of the transaction.summary
: A brief description of the transaction.receipt
: The transaction receipt, if available.lastCheckedBlockNumber
: The last block number at which the transaction was checked.addedTime
,confirmedTime
: Timestamps for when the transaction was added to the state and when it was confirmed, respectively.waitForReceipt
: Indicates if the application should wait for a receipt for this transaction.from
: The originating address of the transaction.info
: Detailed information about the transaction, aTransactionInfo
object.
Updater
Overview
The TransactionUpdater
component is a React component designed to integrate with the application's transaction management system.
Features
Transaction Monitoring: Listens for updates on pending transactions across supported blockchain networks.
Transaction Confirmation: Handles transaction receipts, finalizing transactions in the state once confirmed.
Notification Display: Shows pop-up notifications for transactions upon confirmation or failure, providing feedback to users.
Last updated