Using the Hooks
The Torque UI library provides a set of React hooks that make it easy to integrate Torque functionality into your Solana application. To use the hooks below, make sure that you've already setup the TorqueProvider
inside of your app. The hooks can only be used if the Torque context exists.
useTorque
The main hook for interacting with the Torque SDK. The hook makes it easy to access and interact with the user's offers if you want to implement them directly in your application.
Returns
offers
Array of available offers
journeys
Array of user's progress through offers
publicKey
PublicKey
Connected wallet's public key
user
The user's data from the Torque API
userClient
The Torque user client instance
config
The Torque configuration
initialized
boolean
Whether the user is initialized
isLoading
boolean
Whether it is loading
initialize
Function to initialize the user
logout
() => Promise
Function to logout the user
claimOffer
(offerId: string) => Promise
Function to claim an offer
refreshOffers
() => Promise
Function to refresh the user's offers
useOfferStatus
The useOfferStatus hook provides information about the status of a specific offer for the current user.
Returns
isEligible
boolean
Whether the user is eligible to claim the offer
hasStarted
boolean
Whether the user has started the offer
hasCompleted
boolean
Whether the user has completed the offer
isLoading
boolean
Whether the user's status is being loaded
isEnded
boolean
Whether the offer has ended
isUpcoming
boolean
Whether the offer is upcoming
isPending
boolean
Whether the user is pending for the offer
updatedAt
Date
The date the offer was last updated
startTime
Date
The date the offer started
userSteps
{
id?: string;
bountyStepId: string;
userJourneyId: string;
status: ApiProgressStatus;
transaction?: string;
}[]
The user's progress through the offer
checkOfferStatus
() => Promise
Function to refresh the user's status for the offer
useAction
The useAction hook provides a utility for handling Torque Solana actions returned from the Torque API. The actions are Solana actions that allow the user to complete a requirement for an offer.
NOTE: The hook will automatically prompt the user's wallet for their signature.
Returns
isLoading
boolean
Whether the action is loading
handleBountyStepAction
Function to trigger the action for the user to complete the requirement
Types
TorqueOptions
TorqueOptions
is an interface that defines the configuration options for the Torque SDK:
apiUrl
string
The URL of the Torque API. Defaults to "https://api.torque.so".
appUrl
string
The URL of the Torque app/client. Defaults to "https://app.torque.so". This is used for sharing links and link generation.
functionsUrl
string
The URL of the Torque functions.
rpc
string
The RPC URL for the Solana network. Defaults to the default RPC endpoint for the Solana network.
publisherHandle
string
The publisher handle for the Torque. This is used to identify the publisher and their offers.
TorqueInitOptions
If you already have a SIWS or basic signature in your app, you can use the loginInput
property of the TorqueInitOptions
interface to initialize the user with Torque. This lets Torque validate the user's identity and retrieve their offers without requiring a secondary signature to authenticate with Torque.
loginInput
The login input for the user.
HandleActionProps
The HandleActionProps
interface is used by the handleBountyStepAction
in the useAction
hook to handle Torque actions.
campaignId
string
The ID of the offer/campaign to complete the action for.
index
number
The index of the action to complete.
data
Record<string, string>
The data to send with the action. This is specific to each action and can be used to pass additional information to the action.
onSuccess
OfferActionOnSuccess
The callback to call when the action is successful.
onError
OfferActionOnError
The callback to call when the action fails.
Last updated