This repository was archived by the owner on Apr 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
feat[DOCS] : add useAutoConnect documentations #91
Open
Oladayo-Ahmod
wants to merge
2
commits into
Scaffold-Stark:main
Choose a base branch
from
Oladayo-Ahmod:useAutoConnect-docs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 hidden or 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,60 @@ | ||
| --- | ||
| sidebar_position: 12 | ||
| --- | ||
|
|
||
| # useAutoConnect | ||
|
|
||
| Use this hook to automatically connect the user to a previously used wallet or connector based on configuration settings and prior connection data stored in local storage. This enhances the user experience by reconnecting seamlessly without manual intervention. | ||
|
|
||
| --- | ||
|
|
||
| ## **Features** | ||
| - **Auto-connect Configuration**: Uses the `scaffoldConfig.walletAutoConnect` flag to determine if auto-connect should occur. | ||
| - **TTL Check**: Ensures the connection is only re-established if the configured TTL (`autoConnectTTL`) has not expired. | ||
|
|
||
| --- | ||
|
|
||
| ### **Usage** | ||
|
|
||
| This hook is typically used globally in your application, such as in a provider or a high-level component, | ||
| to handle automatic wallet reconnections: | ||
|
|
||
| ```tsx | ||
| import { useAutoConnect } from "~~/hooks/scaffold-stark" | ||
|
|
||
| const ScaffoldStarkApp = () => { | ||
| useAutoConnect(); | ||
|
|
||
| return <YourAppComponents />; | ||
| }; | ||
| ``` | ||
|
|
||
| By calling `useAutoConnect`, the application will attempt to reconnect to the last used wallet if the `walletAutoConnect` feature is set to `true` in `scaffold.config.ts` and the time-to-live (TTL) has not expired. | ||
|
|
||
| --- | ||
|
|
||
| ### **How It Works** | ||
|
|
||
| 1. **Local Storage**: Reads the last used connector and connection timestamp from local storage: | ||
| - `lastUsedConnector`: Stores the ID of the last used wallet connector. | ||
| - `lastConnectedTime`: Stores the timestamp of the last successful connection. | ||
|
|
||
| 2. **Connector Matching**: Attempts to find the previously used connector from the available connectors. | ||
|
|
||
| 3. **Reconnection**: If the connector is found and the TTL hasn’t expired: | ||
| - For burner wallets, the correct account is restored based on the index. | ||
| - Initiates the connection using the `connect` function from `useConnect`. | ||
|
|
||
| --- | ||
|
|
||
| ### **Configuration** | ||
| Ensure the following keys are defined in your `scaffold.config`: | ||
| - `walletAutoConnect`: A boolean flag to enable or disable auto-connect by setting it to `true` or `false`. | ||
| - `autoConnectTTL`: Time-to-live (in milliseconds) for auto-connect. | ||
|
|
||
| --- | ||
|
|
||
| ### **Best Practices** | ||
| - Use this hook at the application root to manage wallet connections seamlessly. | ||
|
|
||
| --- | ||
|
Comment on lines
+57
to
+60
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dont really need this. |
||
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.
this should be on the top