-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat[DOCS] : add useScaffoldStarkProfile documentation #89
Merged
metalboyrick
merged 2 commits into
Scaffold-Stark:main
from
Oladayo-Ahmod:useScaffoldStarkProfile-docs
Jan 27, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
--- | ||
sidebar_position: 10 | ||
--- | ||
|
||
# useScaffoldStarkProfile | ||
|
||
Use this hook to fetch and manage the StarkNet profile of a specified address. The StarkNet profile includes the user's domain name and profile picture, leveraging the StarkNet ID API for supported networks. | ||
|
||
```ts | ||
const { data, isLoading } = useScaffoldStarkProfile( | ||
"0x061b6c0a78f9edf13cea17b50719f3344533fadd470b8cb29c2b4318014f52d3" | ||
); | ||
``` | ||
|
||
## Usage Example | ||
|
||
This example fetches the StarkNet profile for the provided address in the function. The returned object contains the profile `data` which includes the user's name and profile picture, along with `isLoading` showing the loading state. | ||
|
||
```tsx | ||
import { useScaffoldStarkProfile } from "~~/hooks/scaffold-stark/useScaffoldStarkProfile"; | ||
|
||
const ProfileDisplay = ({ userAddress }) => { | ||
const { data, isLoading } = useScaffoldStarkProfile(userAddress); | ||
|
||
if (isLoading) { | ||
return <p>Loading profile...</p>; | ||
} | ||
|
||
if (!data?.name) { | ||
return <p>No profile found for the provided address.</p>; | ||
} | ||
|
||
return ( | ||
<div> | ||
<img src={data.profilePicture} alt={`${data.name}'s profile`} width="100" /> | ||
<p>Name: {data.name}</p> | ||
</div> | ||
); | ||
}; | ||
``` | ||
|
||
This example demonstrates how to use the `useScaffoldStarkProfile` hook to display a user's StarkNet profile with their name and profile picture. | ||
|
||
--- | ||
|
||
## Configuration | ||
|
||
| Parameter | Description | | ||
| :---------- | :-------------------------------------------- | | ||
| **address** | The StarkNet address to fetch the profile for.| | ||
|
||
--- | ||
|
||
## Return Values | ||
|
||
| Parameter | Type | Description | | ||
| :------------- | :------------ | :----------------------------------------------------------------- | | ||
| **data** | `StarkProfile`| The user's StarkNet profile, including `name` and `profilePicture`.| | ||
| **isLoading** | `boolean` | Indicates whether the profile data is being fetched. | | ||
|
||
--- | ||
|
||
## StarkProfile Object | ||
|
||
| Field | Type | Description | | ||
| :---------------- | :------- | :------------------------------------------------------- | | ||
| **name** | `string` | The domain name associated with the user's StarkNet ID. | | ||
| **profilePicture**| `string` | URL of the user's profile picture. | | ||
|
||
--- | ||
|
||
## Best Practices | ||
|
||
- Use this hook in components where you need to display user-specific StarkNet information, such as their domain name or profile picture. | ||
- Ensure that the target network supports StarkNet profiles. | ||
- Handle loading and fallback states to provide a better user experience. | ||
--- | ||
|
||
## Error Handling | ||
|
||
This hook does not explicitly handle errors but logs them to the console. To manage errors in your component: | ||
|
||
```tsx | ||
const { data, isLoading } = useScaffoldStarkProfile(userAddress); | ||
|
||
if (isLoading) { | ||
return <div>Loading profile...</div>; | ||
} | ||
|
||
if (!data?.name) { | ||
return <div>No profile found or an error occurred.</div>; | ||
} | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can move this to below "Usage Example" before the code snippet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the comment. I have fixed this.