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

Role assignation fail #839

Merged
merged 13 commits into from
Sep 2, 2024
Merged

Role assignation fail #839

merged 13 commits into from
Sep 2, 2024

Conversation

marc-aurele-besner
Copy link
Collaborator

@marc-aurele-besner marc-aurele-besner commented Aug 28, 2024

User description

Role assignation fail


PR Type

Bug fix, Enhancement


Description

  • Simplified the logic in ChainProvider by removing the cookie-based network setting and directly using indexerSet.network.
  • Enhanced queryGraphqlServer to extract the network ID from the callback URL instead of relying on cookies, improving reliability and error handling.

Changes walkthrough 📝

Relevant files
Enhancement
ChainProvider.tsx
Simplify network selection logic in ChainProvider               

explorer/src/providers/ChainProvider.tsx

  • Removed cookie setting logic for network selection.
  • Simplified state management by directly using indexerSet.network.
  • Removed unnecessary network state variable.
  • +1/-5     
    Bug fix
    queryGraphqlServer.ts
    Use callback URL for network ID extraction in GraphQL queries

    explorer/src/utils/queryGraphqlServer.ts

  • Replaced cookie-based network selection with callback URL parsing.
  • Extracted network ID from callback URL for API selection.
  • Improved error handling for missing callback URL or network ID.
  • +9/-3     

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    Copy link

    netlify bot commented Aug 28, 2024

    Deploy Preview for dev-astral ready!

    Name Link
    🔨 Latest commit 117d138
    🔍 Latest deploy log https://app.netlify.com/sites/dev-astral/deploys/66d5cdf7c5b24a00089887ef
    😎 Deploy Preview https://deploy-preview-839--dev-astral.netlify.app
    📱 Preview on mobile
    Toggle QR Code...

    QR Code

    Use your smartphone camera to open QR code link.

    To edit notification comments on pull requests, go to your Netlify site configuration.

    Copy link

    PR Reviewer Guide 🔍

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Key issues to review

    Error Handling
    The error handling for 'No network ID found in callback URL' might not be sufficient. Consider adding more detailed error messages or handling specific cases more gracefully.

    Possible Bug
    The extraction of 'networkId' from the URL assumes a specific URL structure which might not always be valid. This could lead to incorrect or failed network ID extraction.

    Copy link

    github-actions bot commented Aug 28, 2024

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Possible bug
    Improve error handling for network ID extraction

    Add error handling for the case where url.pathname.split('/')[1] does not return a
    valid network ID, to prevent runtime errors.

    explorer/src/utils/queryGraphqlServer.ts [14-15]

    -const networkId = url.pathname.split('/')[1] // The network ID is the second part of the path
    -if (!networkId) throw new Error('No network ID found in callback URL')
    +const pathParts = url.pathname.split('/');
    +const networkId = pathParts.length > 1 ? pathParts[1] : null;
    +if (!networkId) throw new Error('No network ID found in callback URL');
     
    Suggestion importance[1-10]: 8

    Why: This suggestion addresses a potential runtime error by adding a check for the length of the path parts, which is a significant improvement in error handling.

    8
    Enhancement
    Provide more detailed error messages

    Use a more specific error message when api is not found, indicating the missing
    network ID.

    explorer/src/utils/queryGraphqlServer.ts [19]

    -if (!api) throw new Error('No selected chain api')
    +if (!api) throw new Error(`No selected chain api for network ID: ${networkId}`)
     
    Suggestion importance[1-10]: 7

    Why: The suggestion enhances the error message by including the missing network ID, which improves debugging but is not critical for functionality.

    7
    Best practice
    Use destructuring to access properties from indexerSet

    Replace the direct access of indexerSet.network with a destructured variable for
    consistency and clarity.

    explorer/src/providers/ChainProvider.tsx [78]

    -network: indexerSet.network,
    +const { network } = indexerSet;
    +network: network,
     
    Suggestion importance[1-10]: 5

    Why: The suggestion improves code readability by using destructuring, but it is not crucial as the current code is already clear and functional.

    5

    Copy link

    socket-security bot commented Aug 28, 2024

    🚨 Potential security issues detected. Learn more about Socket for GitHub ↗︎

    To accept the risk, merge this PR and you will not be notified again.

    Alert Package NoteSourceCI
    Protestware/Troll package npm/es5-ext@0.10.64
    • Note: This package prints a protestware console message on install regarding Ukraine for users with Russian language locale
    ⚠︎

    View full report↗︎

    Next steps

    What is protestware?

    This package is a joke, parody, or includes undocumented or hidden behavior unrelated to its primary function.

    Consider that consuming this package may come along with functionality unrelated to its primary purpose.

    Take a deeper look at the dependency

    Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev.

    Remove the package

    If you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency.

    Mark a package as acceptable risk

    To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of ecosystem/package-name@version specifiers. e.g. @SocketSecurity ignore npm/foo@1.0.0 or ignore all packages with @SocketSecurity ignore-all

    • @SocketSecurity ignore npm/es5-ext@0.10.64

    Copy link
    Contributor

    @EmilFattakhov EmilFattakhov left a comment

    Choose a reason for hiding this comment

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

    Can't confirm the fix on preview @marc-aurele-besner, but should be okay to test in prod.

    @marc-aurele-besner
    Copy link
    Collaborator Author

    marc-aurele-besner commented Aug 28, 2024

    Can't confirm the fix on preview @marc-aurele-besner, but should be okay to test in prod.

    Now it should work in the preview, but you will not be able to test the full flow in a preview since you will be redirected back to the production domain after connecting to Discord.

    clostao
    clostao previously approved these changes Sep 2, 2024
    Copy link

    Report too large to display inline

    View full report↗︎

    @marc-aurele-besner marc-aurele-besner merged commit 74ab199 into main Sep 2, 2024
    13 checks passed
    @marc-aurele-besner marc-aurele-besner deleted the bug/roleAssignationFail branch September 2, 2024 14:47
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    3 participants