Skip to main content
This library provides higher level React hooks to abstract some of the state management for you. You will still need to use the @echoxyz/sonar-core library for some parts of the integration, and to import types.

Hooks

useSonarAuth

A hook to handle the OAuth flow for the user. Returns
FieldTypeDescription
authenticatedbooleanWhether the user is authenticated.
login() => voidLogin the user.
tokenstring | undefinedThe OAuth token for the user.
login() => voidCall this to redirect the user to Sonar’s site to login and authorize your application to access their data.
completeOAuth(args: { code: string; state: string }) => Promise<void>Call this in your OAuth callback handler to complete the OAuth flow and exchange the code for an access token.
logout() => voidCall this to logout the user.

useSonarClient

A hook to get a reference to the underlying SonarClient from the @echoxyz/sonar-core library. Returns
FieldTypeDescription
clientSonarClientThe underlying SonarClient.

useSonarEntity

A hook to fetch the state of a user’s Sonar entity based on their connected wallet address. Arguments
NameTypeDescription
saleUUIDstringThe UUID of the sale to get entity details for.
walletAddressstring | undefinedThe wallet address of the entity to get details for. It will only start loading once this is defined.
Returns
FieldTypeDescription
authenticatedbooleanWhether the user is authenticated.
loadingbooleanWhether the hook is loading.
entityEntityDetails | undefinedThe state of the user’s Sonar entity. This can be undefined even if the user is not authenticated - see note about 404 errors in readentity docs.
errorError | undefinedPopulated if the entity failed to load.

useSonarPurchase

A hook to run pre-purchase checks and return functions required to complete the purchase flow. Arguments
NameTypeDescription
saleUUIDstringThe UUID of the sale to run pre-purchase checks against the entity for.
entityUUIDstringThe UUID of the entity to run pre-purchase checks for.
walletAddressstringThe wallet address of the entity to run pre-purchase checks for.
Returns
NameTypeDescription
loadingbooleanWhether the pre-purchase checks are loading.
readyToPurchasebooleanWhether the entity is ready to purchase.
errorError | undefinedPopulated if the pre-purchase checks failed to run.
failureReasonPrePurchaseFailureReason | undefinedPopulated if the entity is not ready to purchase.
livenessCheckURLstring | undefinedURL to link the user to so that they can complete a liveness check on the Sonar site. Populated if the failureReason is requires-liveness.
generatePurchasePermit() => Promise<GeneratePurchasePermitResponse> | undefinedFunction to generate a purchase permit to pass to the sale contract when purchasing tokens. Populated if the readyToPurchase is true.
I