@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
Field | Type | Description |
---|---|---|
authenticated | boolean | Whether the user is authenticated. |
login | () => void | Login the user. |
token | string | undefined | The OAuth token for the user. |
login | () => void | Call 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 | () => void | Call this to logout the user. |
useSonarClient
A hook to get a reference to the underlying SonarClient
from the @echoxyz/sonar-core
library.
Returns
Field | Type | Description |
---|---|---|
client | SonarClient | The underlying SonarClient . |
useSonarEntity
A hook to fetch the state of a user’s Sonar entity based on their connected wallet address.
Arguments
Name | Type | Description |
---|---|---|
saleUUID | string | The UUID of the sale to get entity details for. |
walletAddress | string | undefined | The wallet address of the entity to get details for. It will only start loading once this is defined. |
Field | Type | Description |
---|---|---|
authenticated | boolean | Whether the user is authenticated. |
loading | boolean | Whether the hook is loading. |
entity | EntityDetails | undefined | The 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. |
error | Error | undefined | Populated if the entity failed to load. |
useSonarPurchase
A hook to run pre-purchase checks and return functions required to complete the purchase flow.
Arguments
Name | Type | Description |
---|---|---|
saleUUID | string | The UUID of the sale to run pre-purchase checks against the entity for. |
entityUUID | string | The UUID of the entity to run pre-purchase checks for. |
walletAddress | string | The wallet address of the entity to run pre-purchase checks for. |
Name | Type | Description |
---|---|---|
loading | boolean | Whether the pre-purchase checks are loading. |
readyToPurchase | boolean | Whether the entity is ready to purchase. |
error | Error | undefined | Populated if the pre-purchase checks failed to run. |
failureReason | PrePurchaseFailureReason | undefined | Populated if the entity is not ready to purchase. |
livenessCheckURL | string | undefined | URL 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> | undefined | Function to generate a purchase permit to pass to the sale contract when purchasing tokens. Populated if the readyToPurchase is true. |