Scaffold-Stark / scaffold-stark-2

Open source forkable Starknet dev stack
https://www.scaffoldstark.com
63 stars 83 forks source link

[CHORE] Set expiry time to `useAutoConnect()` #280

Closed metalboyrick closed 1 month ago

metalboyrick commented 1 month ago

Issue Overview

Currently useAutoConnect() will try to reconnect you indefinitely until you log out yourself. We would prefer to have some expiry time to ensure security in the web app.

Proposed Solutions or Ideas

Iwueseiter commented 1 month ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

Hi @metalboyrick can I work on this? I'm a frontend and smart contract developer. I've contributed to Projects here on onlydust and with that experience, I would handle this task as expected. This would also be my first time contributing to this project.

How I plan on tackling this issue

  1. Store the Last Intentional Connection Time When the user clicks the "Connect" button, save the timestamp of the connection in local storage or session storage. This timestamp will act as the last intentional connection time.
  2. Add TTL to scaffold.config.ts Define the TTL (Time to Live) in scaffold.config.ts as a duration in milliseconds.
  3. Modify useAutoConnect() In the useAutoConnect() function, i'll need to check the stored timestamp, calculate the difference between the current time and the last intentional connection time, and compare it to the TTL.
  4. Avoid Disconnecting Already Connected Wallets I will ensure that if the user manually connects their wallet (after TTL expiration), it doesn’t disconnect their wallet. This can be done by ensuring that useAutoConnect() only checks on page load or specific mount events and not during user-driven connection events.
onlydustapp[bot] commented 1 month ago

Hey @Iwueseiter! Thanks for showing interest. We've created an application for you to contribute to Speedrun & Scaffold Stark. Go check it out on OnlyDust!

ShantelPeters commented 1 month ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I am a frontend and blockchain developer ,i am interested in contributing to this issue with 2 years experience , kindly assign i am ready to work please

How I plan on tackling this issue

Here is how i intend to approach the problem below:

  1. Store Connection Time:
    • Record the last manual connection time when the user clicks the connect button.
  2. Extract TTL:
    • Add a TTL duration (in milliseconds) to scaffold.config.ts.
  3. Modify useAutoConnect():
    • Update the function to check if the TTL has expired before allowing reconnection, without disconnecting an already connected wallet.
onlydustapp[bot] commented 1 month ago

Hey @ShantelPeters! Thanks for showing interest. We've created an application for you to contribute to Speedrun & Scaffold Stark. Go check it out on OnlyDust!

Nadai2010 commented 1 month ago

Hello everyone, @Iwueseiter @ShantelPeters the Issues for the OD Hack will be assigned to each of you at the start, prepare your skills.

0xdevcollins commented 1 month ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

My name is Collins Ikechukwu. I'm a full stack blockchain developer developer.

How I plan on tackling this issue

To implement an ### Steps to Implement Expiry Time in useAutoConnect()

  1. Store Last Connection Time:

    • Modify the useAutoConnect() hook to store the last intentional connection time. This should be set whenever the user connects via the connect button.
  2. Extract TTL Duration:

    • Add a configuration entry in scaffold.config.ts for the desired TTL duration (in milliseconds).
  3. Implement Expiry Logic:

    • In the useAutoConnect() hook, check if the current time exceeds the last connection time plus the TTL duration before attempting to reconnect.
  4. User Experience Consideration:

    • Ensure that the auto-connect does not forcibly disconnect a wallet if the TTL has expired; instead, gracefully handle the expiration by allowing users to reconnect manually.
  5. Testing:

    • Test the functionality to ensure that the expiry logic works correctly, allowing reconnections within the TTL but not after.
  6. Documentation:

    • Update any relevant documentation to reflect the changes in the useAutoConnect() behavior and configuration settings.

Benefits

petersdt commented 1 month ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

kindly assign me this issue as am a frontend developer with experience using frontend technologies

How I plan on tackling this issue

I recognize that useAutoConnect() currently attempts to reconnect indefinitely until I manually log out, which raises security concerns. Implement a Connection Expiry:

I will find a way to store the timestamp of the last intentional connection. This means I’ll track when I click the connect button, differentiating it from auto-connection attempts. Extract TTL Duration:

I will extract the desired time-to-live (TTL) duration and store it in scaffold.config.ts in milliseconds. This will allow me to easily adjust the expiry time as needed. Modify useAutoConnect():

I will implement changes to useAutoConnect() so that it checks the current time against the stored last connection time. If the TTL has expired, I will ensure that it does not attempt to reconnect. I will make sure that my implementation does not disconnect a wallet that has reconnected before the TTL expires, as I understand that this would result in a poor user experience. Test the Implementation:

After making these changes, I will thoroughly test the functionality to ensure that it behaves as expected, allowing reconnections within the TTL and preventing reconnections once the expiry time has passed.

ScottyDavies commented 1 month ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I have experience in React development and state management, with experience in building secure and user-friendly web applications

How I plan on tackling this issue

To tackle the issue, I would:

Store Connection Time: Implement a mechanism to store the last intentional connection timestamp when the user clicks the connect button.

Configure TTL: Extract the desired TTL duration into scaffold.config.ts in milliseconds for easy configuration.

Modify Logic: Update the useAutoConnect() hook to check the current time against the stored connection time. If the TTL has expired, prevent reconnection attempts while ensuring that already connected wallets remain active.

Testing: Thoroughly test the implementation to confirm that users experience seamless reconnections within the TTL and proper handling after expiry.

metalboyrick commented 1 month ago

all yours @Iwueseiter

metalboyrick commented 1 month ago

Hi @Iwueseiter, any updates on this issue?

Iwueseiter commented 1 month ago

Hi @Iwueseiter, any updates on this issue?

Yes I’ve been working on it and I’d create a PR today.