Skip to content
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: event handling in get-starknet #413

Merged
merged 12 commits into from
Dec 13, 2024
Merged

Conversation

khanti42
Copy link
Collaborator

@khanti42 khanti42 commented Nov 5, 2024

Description

This PR introduces event handling in get-starknet by implementing a polling mechanism to detect and handle accountsChanged and networkChanged events.

Changes Introduced:

  1. Event Polling Added:

    • Implemented a polling mechanism to detect changes in the wallet account's address and network state.
    • The polling ensures the walletAccount object remains in sync with the snap state.
  2. Unified Polling Logic:

    • A single polling loop is reused for both accountsChanged and networkChanged event handling.
    • Avoids redundant checks and improves efficiency.
  3. Optimized Polling Mechanism:

    • Minimum Delay: Ensures a minimum delay between successive polls to avoid overloading resources.
    • Maximum Timeout: Added a timeout for polling operations to prevent hanging requests.
    • Sequential Execution: Ensures that a new poll does not begin until the previous one has completed.
  4. Performance Validation:

    • Tested with 20 browser tabs open concurrently to ensure the mechanism remains reliable and efficient under heavy usage.

Purpose:

This ensure that the walletAccount object address and network are in sync with the snap state. As both events are used in the walletAccount object to ensure this: https://github.com/starknet-io/starknet.js/blob/b15fe2d6aa9a5494c510fcac3d6d34fd7e41bf5c/src/wallet/account.ts#L56

@khanti42 khanti42 requested a review from a team as a code owner November 5, 2024 13:58
@khanti42 khanti42 requested review from Akaryatrh and stanleyyconsensys and removed request for a team November 5, 2024 13:58
@khanti42 khanti42 force-pushed the feat/event-handling-with-polling branch from 53d1b9f to 2071148 Compare November 5, 2024 14:04
@khanti42 khanti42 marked this pull request as draft November 5, 2024 14:19
@khanti42 khanti42 marked this pull request as ready for review December 6, 2024 11:01
Copy link
Collaborator

@stanleyyconsensys stanleyyconsensys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the overall coding look good,
some advice for clean up the code
and some bug/wrong behaviour discovered:

  • any handler error will break other handler
  • previous address never assign

packages/get-starknet/src/wallet.ts Outdated Show resolved Hide resolved
packages/get-starknet/src/wallet.ts Outdated Show resolved Hide resolved
packages/get-starknet/src/wallet.ts Outdated Show resolved Hide resolved
packages/get-starknet/src/wallet.ts Outdated Show resolved Hide resolved
packages/get-starknet/src/wallet.ts Outdated Show resolved Hide resolved
packages/get-starknet/src/wallet.ts Outdated Show resolved Hide resolved
packages/get-starknet/src/wallet.ts Outdated Show resolved Hide resolved
packages/get-starknet/src/wallet.ts Outdated Show resolved Hide resolved
packages/get-starknet/src/wallet.ts Outdated Show resolved Hide resolved
packages/get-starknet/src/wallet.ts Outdated Show resolved Hide resolved
@khanti42 khanti42 force-pushed the feat/event-handling-with-polling branch from 18941a2 to 2790ad8 Compare December 9, 2024 10:45
packages/get-starknet/src/wallet.ts Outdated Show resolved Hide resolved
packages/get-starknet/src/wallet.ts Outdated Show resolved Hide resolved
packages/get-starknet/src/wallet.ts Outdated Show resolved Hide resolved
packages/get-starknet/src/wallet.ts Outdated Show resolved Hide resolved
packages/get-starknet/src/wallet.ts Show resolved Hide resolved
@khanti42 khanti42 force-pushed the feat/event-handling-with-polling branch from 893e19b to f50bb63 Compare December 12, 2024 12:21
@khanti42 khanti42 force-pushed the feat/event-handling-with-polling branch from 4793645 to d35521f Compare December 13, 2024 09:43
Copy link

sonarcloud bot commented Dec 13, 2024

Quality Gate Passed Quality Gate passed for 'consensys_starknet-snap-starknet-snap'

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

Copy link

sonarcloud bot commented Dec 13, 2024

Quality Gate Passed Quality Gate passed for 'consensys_starknet-snap-wallet-ui'

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

Copy link
Collaborator

@stanleyyconsensys stanleyyconsensys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, we can have a unit test later on

@khanti42 khanti42 added this pull request to the merge queue Dec 13, 2024
Merged via the queue into main with commit 009e8d4 Dec 13, 2024
14 checks passed
@khanti42 khanti42 deleted the feat/event-handling-with-polling branch December 13, 2024 10:12
@github-actions github-actions bot mentioned this pull request Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants